Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: runtime/vm/intermediate_language.h

Issue 10909168: Introduce nested deoptimization environments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 3201 matching lines...) Expand 10 before | Expand all | Expand 10 after
3212 3212
3213 private: 3213 private:
3214 intptr_t array_type_; 3214 intptr_t array_type_;
3215 3215
3216 DISALLOW_COPY_AND_ASSIGN(CheckArrayBoundInstr); 3216 DISALLOW_COPY_AND_ASSIGN(CheckArrayBoundInstr);
3217 }; 3217 };
3218 3218
3219 3219
3220 #undef DECLARE_INSTRUCTION 3220 #undef DECLARE_INSTRUCTION
3221 3221
3222
3223 class Environment : public ZoneAllocated { 3222 class Environment : public ZoneAllocated {
3224 public: 3223 public:
3224 // Iterate the non-NULL values in the innermost level of an environment.
3225 class ShallowIterator : public ValueObject {
3226 public:
3227 explicit ShallowIterator(Environment* environment)
3228 : environment_(environment), index_(0) {
3229 SkipNull();
3230 }
3231
3232 Environment* environment() const { return environment_; }
3233
3234 void Advance() {
3235 ASSERT(!Done());
3236 ++index_;
3237 SkipNull();
Florian Schneider 2012/09/11 12:07:38 Maybe we can assert that all definitions in the en
Kevin Millikin (Google) 2012/09/11 12:38:15 Done.
3238 }
3239
3240 bool Done() const {
3241 return (environment_ == NULL) || (index_ >= environment_->Length());
3242 }
3243
3244 Value* CurrentValue() const {
3245 ASSERT(!Done());
3246 return environment_->values_[index_];
3247 }
3248
3249 void SetCurrentValue(Value* value) {
3250 ASSERT(!Done());
3251 environment_->values_[index_] = value;
3252 }
3253
3254 private:
3255 void SkipNull() {
3256 while (!Done() && (CurrentValue() == NULL)) {
3257 ++index_;
3258 }
3259 }
3260
3261 Environment* environment_;
3262 intptr_t index_;
3263 };
3264
3265 // Iterate all non-NULL values in an environment, including outer
3266 // environments. Note that the iterator skips empty environments.
3267 class DeepIterator : public ValueObject {
3268 public:
3269 explicit DeepIterator(Environment* environment) : iterator_(environment) {
3270 SkipDone();
3271 }
3272
3273 void Advance() {
3274 ASSERT(!Done());
3275 iterator_.Advance();
3276 SkipDone();
3277 }
3278
3279 bool Done() const { return iterator_.environment() == NULL; }
3280
3281 Value* CurrentValue() const {
3282 ASSERT(!Done());
3283 return iterator_.CurrentValue();
3284 }
3285
3286 void SetCurrentValue(Value* value) {
3287 ASSERT(!Done());
3288 iterator_.SetCurrentValue(value);
3289 }
3290
3291 private:
3292 void SkipDone() {
3293 while (!Done() && iterator_.Done()) {
3294 iterator_ = ShallowIterator(iterator_.environment()->outer());
3295 }
3296 }
3297
3298 ShallowIterator iterator_;
3299 };
3300
3225 // Construct an environment by constructing uses from an array of definitions. 3301 // Construct an environment by constructing uses from an array of definitions.
3226 Environment(const GrowableArray<Definition*>& definitions, 3302 static Environment* From(const GrowableArray<Definition*>& definitions,
3227 intptr_t fixed_parameter_count); 3303 intptr_t fixed_parameter_count,
3304 const Environment* outer);
3228 3305
3229 void set_locations(Location* locations) { 3306 void set_locations(Location* locations) {
3230 ASSERT(locations_ == NULL); 3307 ASSERT(locations_ == NULL);
3231 locations_ = locations; 3308 locations_ = locations;
3232 } 3309 }
3233 3310
3234 const GrowableArray<Value*>& values() const { 3311 void set_deopt_id(intptr_t deopt_id) { deopt_id_ = deopt_id; }
3235 return values_; 3312 intptr_t deopt_id() const { return deopt_id_; }
3313
3314 Environment* outer() const { return outer_; }
3315
3316 Value* ValueAt(intptr_t ix) const {
3317 return values_[ix];
3236 } 3318 }
3237 3319
3238 GrowableArray<Value*>* values_ptr() { 3320 intptr_t Length() const {
3239 return &values_; 3321 return values_.length();
3240 } 3322 }
3241 3323
3242 Location LocationAt(intptr_t ix) const { 3324 Location LocationAt(intptr_t index) const {
3243 ASSERT((ix >= 0) && (ix < values_.length())); 3325 ASSERT((index >= 0) && (index < values_.length()));
3244 return locations_[ix]; 3326 return locations_[index];
3245 } 3327 }
3246 3328
3247 Location* LocationSlotAt(intptr_t ix) const { 3329 Location* LocationSlotAt(intptr_t index) const {
3248 ASSERT((ix >= 0) && (ix < values_.length())); 3330 ASSERT((index >= 0) && (index < values_.length()));
3249 return &locations_[ix]; 3331 return &locations_[index];
3332 }
3333
3334 // The use index is the index in the flattened environment.
3335 Value* ValueAtUseIndex(intptr_t index) const {
3336 const Environment* env = this;
3337 while (index >= env->Length()) {
3338 ASSERT(env->outer_ != NULL);
3339 index -= env->Length();
3340 env = env->outer_;
3341 }
3342 return env->ValueAt(index);
3250 } 3343 }
3251 3344
3252 intptr_t fixed_parameter_count() const { 3345 intptr_t fixed_parameter_count() const {
3253 return fixed_parameter_count_; 3346 return fixed_parameter_count_;
3254 } 3347 }
3255 3348
3256 void CopyTo(Instruction* instr) const; 3349 void CopyTo(Instruction* instr) const;
3257 3350
3258 void PrintTo(BufferFormatter* f) const; 3351 void PrintTo(BufferFormatter* f) const;
3259 3352
3260 private: 3353 private:
3261 Environment(intptr_t length, intptr_t fixed_parameter_count) 3354 friend class ShallowIterator;
3355
3356 Environment(intptr_t length,
3357 intptr_t fixed_parameter_count,
3358 intptr_t deopt_id,
3359 Environment* outer)
3262 : values_(length), 3360 : values_(length),
3263 locations_(NULL), 3361 locations_(NULL),
3264 fixed_parameter_count_(fixed_parameter_count) { } 3362 fixed_parameter_count_(fixed_parameter_count),
3363 deopt_id_(deopt_id),
3364 outer_(outer) { }
3365
3366 Environment* Copy() const;
3265 3367
3266 GrowableArray<Value*> values_; 3368 GrowableArray<Value*> values_;
3267 Location* locations_; 3369 Location* locations_;
3268 const intptr_t fixed_parameter_count_; 3370 const intptr_t fixed_parameter_count_;
3371 intptr_t deopt_id_;
3372 Environment* outer_;
3269 3373
3270 DISALLOW_COPY_AND_ASSIGN(Environment); 3374 DISALLOW_COPY_AND_ASSIGN(Environment);
3271 }; 3375 };
3272 3376
3273 3377
3274 // Visitor base class to visit each instruction and computation in a flow 3378 // Visitor base class to visit each instruction and computation in a flow
3275 // graph as defined by a reversed list of basic blocks. 3379 // graph as defined by a reversed list of basic blocks.
3276 class FlowGraphVisitor : public ValueObject { 3380 class FlowGraphVisitor : public ValueObject {
3277 public: 3381 public:
3278 explicit FlowGraphVisitor(const GrowableArray<BlockEntryInstr*>& block_order) 3382 explicit FlowGraphVisitor(const GrowableArray<BlockEntryInstr*>& block_order)
(...skipping 22 matching lines...) Expand all
3301 ForwardInstructionIterator* current_iterator_; 3405 ForwardInstructionIterator* current_iterator_;
3302 3406
3303 private: 3407 private:
3304 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 3408 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
3305 }; 3409 };
3306 3410
3307 3411
3308 } // namespace dart 3412 } // namespace dart
3309 3413
3310 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 3414 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698