| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ | 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ |
| 6 #define VM_INTERMEDIATE_LANGUAGE_H_ | 6 #define VM_INTERMEDIATE_LANGUAGE_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
| 10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
| (...skipping 3199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3210 | 3210 |
| 3211 private: | 3211 private: |
| 3212 intptr_t array_type_; | 3212 intptr_t array_type_; |
| 3213 | 3213 |
| 3214 DISALLOW_COPY_AND_ASSIGN(CheckArrayBoundInstr); | 3214 DISALLOW_COPY_AND_ASSIGN(CheckArrayBoundInstr); |
| 3215 }; | 3215 }; |
| 3216 | 3216 |
| 3217 | 3217 |
| 3218 #undef DECLARE_INSTRUCTION | 3218 #undef DECLARE_INSTRUCTION |
| 3219 | 3219 |
| 3220 | |
| 3221 class Environment : public ZoneAllocated { | 3220 class Environment : public ZoneAllocated { |
| 3222 public: | 3221 public: |
| 3223 // Construct an environment by constructing uses from an array of definitions. | 3222 // Construct an environment by constructing uses from an array of definitions. |
| 3224 Environment(const GrowableArray<Definition*>& definitions, | 3223 static Environment* From(const GrowableArray<Definition*>& definitions, |
| 3225 intptr_t fixed_parameter_count); | 3224 intptr_t fixed_parameter_count, |
| 3225 const Environment* outer); |
| 3226 | 3226 |
| 3227 void set_locations(Location* locations) { | 3227 void set_locations(Location* locations) { |
| 3228 ASSERT(locations_ == NULL); | 3228 ASSERT(locations_ == NULL); |
| 3229 locations_ = locations; | 3229 locations_ = locations; |
| 3230 } | 3230 } |
| 3231 | 3231 |
| 3232 const GrowableArray<Value*>& values() const { | 3232 void set_deopt_id(intptr_t deopt_id) { deopt_id_ = deopt_id; } |
| 3233 return values_; | 3233 intptr_t deopt_id() const { return deopt_id_; } |
| 3234 |
| 3235 Environment* outer() const { return outer_; } |
| 3236 |
| 3237 Value* ValueAt(intptr_t ix) const { |
| 3238 return values_[ix]; |
| 3234 } | 3239 } |
| 3235 | 3240 |
| 3236 GrowableArray<Value*>* values_ptr() { | 3241 intptr_t Length() const { |
| 3237 return &values_; | 3242 return values_.length(); |
| 3238 } | 3243 } |
| 3239 | 3244 |
| 3240 Location LocationAt(intptr_t ix) const { | 3245 Location LocationAt(intptr_t ix) const { |
| 3241 ASSERT((ix >= 0) && (ix < values_.length())); | 3246 ASSERT((ix >= 0) && (ix < values_.length())); |
| 3242 return locations_[ix]; | 3247 return locations_[ix]; |
| 3243 } | 3248 } |
| 3244 | 3249 |
| 3245 Location* LocationSlotAt(intptr_t ix) const { | 3250 Location* LocationSlotAt(intptr_t ix) const { |
| 3246 ASSERT((ix >= 0) && (ix < values_.length())); | 3251 ASSERT((ix >= 0) && (ix < values_.length())); |
| 3247 return &locations_[ix]; | 3252 return &locations_[ix]; |
| 3248 } | 3253 } |
| 3249 | 3254 |
| 3255 // The use index is the index in the flattened environment. |
| 3256 Value* ValueAtUseIndex(intptr_t ix) const { |
| 3257 const Environment* env = this; |
| 3258 while (ix >= env->Length()) { |
| 3259 ASSERT(env->outer_ != NULL); |
| 3260 ix -= env->Length(); |
| 3261 env = env->outer_; |
| 3262 } |
| 3263 return env->ValueAt(ix); |
| 3264 } |
| 3265 |
| 3250 intptr_t fixed_parameter_count() const { | 3266 intptr_t fixed_parameter_count() const { |
| 3251 return fixed_parameter_count_; | 3267 return fixed_parameter_count_; |
| 3252 } | 3268 } |
| 3253 | 3269 |
| 3254 void CopyTo(Instruction* instr) const; | 3270 void CopyTo(Instruction* instr) const; |
| 3255 | 3271 |
| 3256 void PrintTo(BufferFormatter* f) const; | 3272 void PrintTo(BufferFormatter* f) const; |
| 3257 | 3273 |
| 3258 private: | 3274 private: |
| 3259 Environment(intptr_t length, intptr_t fixed_parameter_count) | 3275 Environment(intptr_t length, |
| 3276 intptr_t fixed_parameter_count, |
| 3277 intptr_t deopt_id, |
| 3278 Environment* outer) |
| 3260 : values_(length), | 3279 : values_(length), |
| 3261 locations_(NULL), | 3280 locations_(NULL), |
| 3262 fixed_parameter_count_(fixed_parameter_count) { } | 3281 fixed_parameter_count_(fixed_parameter_count), |
| 3282 deopt_id_(deopt_id), |
| 3283 outer_(outer) { } |
| 3284 |
| 3285 Environment* Copy() const; |
| 3263 | 3286 |
| 3264 GrowableArray<Value*> values_; | 3287 GrowableArray<Value*> values_; |
| 3265 Location* locations_; | 3288 Location* locations_; |
| 3266 const intptr_t fixed_parameter_count_; | 3289 const intptr_t fixed_parameter_count_; |
| 3290 intptr_t deopt_id_; |
| 3291 Environment* outer_; |
| 3267 | 3292 |
| 3293 friend class EnvironmentIterator; |
| 3268 DISALLOW_COPY_AND_ASSIGN(Environment); | 3294 DISALLOW_COPY_AND_ASSIGN(Environment); |
| 3269 }; | 3295 }; |
| 3270 | 3296 |
| 3271 | 3297 |
| 3298 // Iterator over the full deoptimization environment. |
| 3299 // Iterates the environment from the inner most to the outer most. |
| 3300 class EnvironmentIterator : public ValueObject { |
| 3301 public: |
| 3302 explicit EnvironmentIterator(Environment* env) : env_(env), ix_(0) { } |
| 3303 |
| 3304 void Advance() { |
| 3305 ASSERT(!Done()); |
| 3306 if (++ix_ == env_->values_.length()) { |
| 3307 ix_ = 0; |
| 3308 env_ = env_->outer(); |
| 3309 } |
| 3310 } |
| 3311 |
| 3312 bool Done() const { |
| 3313 return env_ == NULL || ix_ == env_->values_.length(); |
| 3314 } |
| 3315 |
| 3316 Value* CurrentValue() const { |
| 3317 return env_->values_[ix_]; |
| 3318 } |
| 3319 |
| 3320 Location CurrentLocation() const { |
| 3321 return env_->locations_[ix_]; |
| 3322 } |
| 3323 |
| 3324 Location* CurrentLocationSlot() const { |
| 3325 return &env_->locations_[ix_]; |
| 3326 } |
| 3327 |
| 3328 Environment* CurrentEnvironment() const { |
| 3329 return env_; |
| 3330 } |
| 3331 |
| 3332 void ReplaceCurrentValue(Value* value) { |
| 3333 env_->values_[ix_] = value; |
| 3334 } |
| 3335 |
| 3336 void ReplaceCurrentLocation(Location loc) { |
| 3337 env_->locations_[ix_] = loc; |
| 3338 } |
| 3339 |
| 3340 private: |
| 3341 Environment* env_; |
| 3342 intptr_t ix_; |
| 3343 }; |
| 3344 |
| 3345 |
| 3346 |
| 3272 // Visitor base class to visit each instruction and computation in a flow | 3347 // Visitor base class to visit each instruction and computation in a flow |
| 3273 // graph as defined by a reversed list of basic blocks. | 3348 // graph as defined by a reversed list of basic blocks. |
| 3274 class FlowGraphVisitor : public ValueObject { | 3349 class FlowGraphVisitor : public ValueObject { |
| 3275 public: | 3350 public: |
| 3276 explicit FlowGraphVisitor(const GrowableArray<BlockEntryInstr*>& block_order) | 3351 explicit FlowGraphVisitor(const GrowableArray<BlockEntryInstr*>& block_order) |
| 3277 : block_order_(block_order), current_iterator_(NULL) { } | 3352 : block_order_(block_order), current_iterator_(NULL) { } |
| 3278 virtual ~FlowGraphVisitor() { } | 3353 virtual ~FlowGraphVisitor() { } |
| 3279 | 3354 |
| 3280 ForwardInstructionIterator* current_iterator() const { | 3355 ForwardInstructionIterator* current_iterator() const { |
| 3281 return current_iterator_; | 3356 return current_iterator_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3299 ForwardInstructionIterator* current_iterator_; | 3374 ForwardInstructionIterator* current_iterator_; |
| 3300 | 3375 |
| 3301 private: | 3376 private: |
| 3302 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 3377 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 3303 }; | 3378 }; |
| 3304 | 3379 |
| 3305 | 3380 |
| 3306 } // namespace dart | 3381 } // namespace dart |
| 3307 | 3382 |
| 3308 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 3383 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |