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

Side by Side Diff: runtime/vm/flow_graph_optimizer.cc

Issue 25640004: Bug fix in load elimination, constant propagation for LoadClassId. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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
« no previous file with comments | « no previous file | runtime/vm/il_printer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 #include "vm/flow_graph_optimizer.h" 5 #include "vm/flow_graph_optimizer.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/cha.h" 8 #include "vm/cha.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
(...skipping 4130 matching lines...) Expand 10 before | Expand all | Expand 10 after
4141 id_(other.id_) { 4141 id_(other.id_) {
4142 } 4142 }
4143 4143
4144 // Construct a place from instruction if instruction accesses any place. 4144 // Construct a place from instruction if instruction accesses any place.
4145 // Otherwise constructs kNone place. 4145 // Otherwise constructs kNone place.
4146 Place(Instruction* instr, bool* is_load) 4146 Place(Instruction* instr, bool* is_load)
4147 : kind_(kNone), instance_(NULL), raw_selector_(0), id_(0) { 4147 : kind_(kNone), instance_(NULL), raw_selector_(0), id_(0) {
4148 switch (instr->tag()) { 4148 switch (instr->tag()) {
4149 case Instruction::kLoadField: { 4149 case Instruction::kLoadField: {
4150 LoadFieldInstr* load_field = instr->AsLoadField(); 4150 LoadFieldInstr* load_field = instr->AsLoadField();
4151 instance_ = load_field->instance()->definition(); 4151 instance_ = OriginalDefinition(load_field->instance()->definition());
4152 if (load_field->field() != NULL) { 4152 if (load_field->field() != NULL) {
4153 kind_ = kField; 4153 kind_ = kField;
4154 field_ = load_field->field(); 4154 field_ = load_field->field();
4155 } else { 4155 } else {
4156 kind_ = kVMField; 4156 kind_ = kVMField;
4157 offset_in_bytes_ = load_field->offset_in_bytes(); 4157 offset_in_bytes_ = load_field->offset_in_bytes();
4158 } 4158 }
4159 *is_load = true; 4159 *is_load = true;
4160 break; 4160 break;
4161 } 4161 }
4162 4162
4163 case Instruction::kStoreInstanceField: { 4163 case Instruction::kStoreInstanceField: {
4164 StoreInstanceFieldInstr* store_instance_field = 4164 StoreInstanceFieldInstr* store_instance_field =
4165 instr->AsStoreInstanceField(); 4165 instr->AsStoreInstanceField();
4166 kind_ = kField; 4166 kind_ = kField;
4167 instance_ = store_instance_field->instance()->definition(); 4167 instance_ =
4168 OriginalDefinition(store_instance_field->instance()->definition());
4168 field_ = &store_instance_field->field(); 4169 field_ = &store_instance_field->field();
4169 break; 4170 break;
4170 } 4171 }
4171 4172
4172 case Instruction::kStoreVMField: { 4173 case Instruction::kStoreVMField: {
4173 StoreVMFieldInstr* store_vm_field = instr->AsStoreVMField(); 4174 StoreVMFieldInstr* store_vm_field = instr->AsStoreVMField();
4174 kind_ = kVMField; 4175 kind_ = kVMField;
4175 instance_ = store_vm_field->dest()->definition(); 4176 instance_ = OriginalDefinition(store_vm_field->dest()->definition());
4176 offset_in_bytes_ = store_vm_field->offset_in_bytes(); 4177 offset_in_bytes_ = store_vm_field->offset_in_bytes();
4177 break; 4178 break;
4178 } 4179 }
4179 4180
4180 case Instruction::kLoadStaticField: 4181 case Instruction::kLoadStaticField:
4181 kind_ = kField; 4182 kind_ = kField;
4182 field_ = &instr->AsLoadStaticField()->StaticField(); 4183 field_ = &instr->AsLoadStaticField()->StaticField();
4183 *is_load = true; 4184 *is_load = true;
4184 break; 4185 break;
4185 4186
4186 case Instruction::kStoreStaticField: 4187 case Instruction::kStoreStaticField:
4187 kind_ = kField; 4188 kind_ = kField;
4188 field_ = &instr->AsStoreStaticField()->field(); 4189 field_ = &instr->AsStoreStaticField()->field();
4189 break; 4190 break;
4190 4191
4191 case Instruction::kLoadIndexed: { 4192 case Instruction::kLoadIndexed: {
4192 LoadIndexedInstr* load_indexed = instr->AsLoadIndexed(); 4193 LoadIndexedInstr* load_indexed = instr->AsLoadIndexed();
4193 kind_ = kIndexed; 4194 kind_ = kIndexed;
4194 instance_ = load_indexed->array()->definition(); 4195 instance_ = OriginalDefinition(load_indexed->array()->definition());
4195 index_ = load_indexed->index()->definition(); 4196 index_ = load_indexed->index()->definition();
4196 *is_load = true; 4197 *is_load = true;
4197 break; 4198 break;
4198 } 4199 }
4199 4200
4200 case Instruction::kStoreIndexed: { 4201 case Instruction::kStoreIndexed: {
4201 StoreIndexedInstr* store_indexed = instr->AsStoreIndexed(); 4202 StoreIndexedInstr* store_indexed = instr->AsStoreIndexed();
4202 kind_ = kIndexed; 4203 kind_ = kIndexed;
4203 instance_ = store_indexed->array()->definition(); 4204 instance_ = OriginalDefinition(store_indexed->array()->definition());
4204 index_ = store_indexed->index()->definition(); 4205 index_ = store_indexed->index()->definition();
4205 break; 4206 break;
4206 } 4207 }
4207 4208
4208 case Instruction::kCurrentContext: 4209 case Instruction::kCurrentContext:
4209 kind_ = kContext; 4210 kind_ = kContext;
4210 *is_load = true; 4211 *is_load = true;
4211 break; 4212 break;
4212 4213
4213 case Instruction::kStoreContext: 4214 case Instruction::kStoreContext:
(...skipping 10 matching lines...) Expand all
4224 4225
4225 Kind kind() const { return kind_; } 4226 Kind kind() const { return kind_; }
4226 4227
4227 Definition* instance() const { 4228 Definition* instance() const {
4228 ASSERT((kind_ == kField) || (kind_ == kVMField) || (kind_ == kIndexed)); 4229 ASSERT((kind_ == kField) || (kind_ == kVMField) || (kind_ == kIndexed));
4229 return instance_; 4230 return instance_;
4230 } 4231 }
4231 4232
4232 void set_instance(Definition* def) { 4233 void set_instance(Definition* def) {
4233 ASSERT((kind_ == kField) || (kind_ == kVMField) || (kind_ == kIndexed)); 4234 ASSERT((kind_ == kField) || (kind_ == kVMField) || (kind_ == kIndexed));
4234 instance_ = def; 4235 instance_ = OriginalDefinition(def);
4235 } 4236 }
4236 4237
4237 const Field& field() const { 4238 const Field& field() const {
4238 ASSERT(kind_ == kField); 4239 ASSERT(kind_ == kField);
4239 return *field_; 4240 return *field_;
4240 } 4241 }
4241 4242
4242 intptr_t offset_in_bytes() const { 4243 intptr_t offset_in_bytes() const {
4243 ASSERT(kind_ == kVMField); 4244 ASSERT(kind_ == kVMField);
4244 return offset_in_bytes_; 4245 return offset_in_bytes_;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
4295 bool Equals(Place* other) const { 4296 bool Equals(Place* other) const {
4296 return (kind_ == other->kind_) && 4297 return (kind_ == other->kind_) &&
4297 (instance_ == other->instance_) && 4298 (instance_ == other->instance_) &&
4298 SameField(other); 4299 SameField(other);
4299 } 4300 }
4300 4301
4301 // Create a zone allocated copy of this place. 4302 // Create a zone allocated copy of this place.
4302 static Place* Wrap(const Place& place); 4303 static Place* Wrap(const Place& place);
4303 4304
4304 private: 4305 private:
4306 static Definition* OriginalDefinition(Definition* defn) {
4307 while (defn->IsRedefinition()) {
4308 defn = defn->AsRedefinition()->value()->definition();
4309 }
4310 return defn;
4311 }
4312
4305 bool SameField(Place* other) const { 4313 bool SameField(Place* other) const {
4306 return (kind_ == kField) ? (field().raw() == other->field().raw()) 4314 return (kind_ == kField) ? (field().raw() == other->field().raw())
4307 : (offset_in_bytes_ == other->offset_in_bytes_); 4315 : (offset_in_bytes_ == other->offset_in_bytes_);
4308 } 4316 }
4309 4317
4310 intptr_t FieldHashcode() const { 4318 intptr_t FieldHashcode() const {
4311 return (kind_ == kField) ? reinterpret_cast<intptr_t>(field().raw()) 4319 return (kind_ == kField) ? reinterpret_cast<intptr_t>(field().raw())
4312 : offset_in_bytes_; 4320 : offset_in_bytes_;
4313 } 4321 }
4314 4322
(...skipping 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after
6273 SetValue(instr, non_constant_); 6281 SetValue(instr, non_constant_);
6274 } 6282 }
6275 6283
6276 6284
6277 void ConstantPropagator::VisitLoadUntagged(LoadUntaggedInstr* instr) { 6285 void ConstantPropagator::VisitLoadUntagged(LoadUntaggedInstr* instr) {
6278 SetValue(instr, non_constant_); 6286 SetValue(instr, non_constant_);
6279 } 6287 }
6280 6288
6281 6289
6282 void ConstantPropagator::VisitLoadClassId(LoadClassIdInstr* instr) { 6290 void ConstantPropagator::VisitLoadClassId(LoadClassIdInstr* instr) {
6291 intptr_t cid = instr->object()->Type()->ToCid();
6292 if (cid != kDynamicCid) {
6293 SetValue(instr, Smi::ZoneHandle(Smi::New(cid)));
6294 return;
6295 }
6296 const Object& object = instr->object()->definition()->constant_value();
6297 if (IsConstant(object)) {
6298 SetValue(instr, Smi::ZoneHandle(Smi::New(object.GetClassId())));
6299 return;
6300 }
6283 SetValue(instr, non_constant_); 6301 SetValue(instr, non_constant_);
6284 } 6302 }
6285 6303
6286 6304
6287 void ConstantPropagator::VisitLoadField(LoadFieldInstr* instr) { 6305 void ConstantPropagator::VisitLoadField(LoadFieldInstr* instr) {
6288 if ((instr->recognized_kind() == MethodRecognizer::kObjectArrayLength) && 6306 if ((instr->recognized_kind() == MethodRecognizer::kObjectArrayLength) &&
6289 (instr->instance()->definition()->IsCreateArray())) { 6307 (instr->instance()->definition()->IsCreateArray())) {
6290 const intptr_t length = 6308 const intptr_t length =
6291 instr->instance()->definition()->AsCreateArray()->num_elements(); 6309 instr->instance()->definition()->AsCreateArray()->num_elements();
6292 const Object& result = Smi::ZoneHandle(Smi::New(length)); 6310 const Object& result = Smi::ZoneHandle(Smi::New(length));
(...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after
7635 } 7653 }
7636 7654
7637 // Insert materializations at environment uses. 7655 // Insert materializations at environment uses.
7638 for (intptr_t i = 0; i < exits.length(); i++) { 7656 for (intptr_t i = 0; i < exits.length(); i++) {
7639 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); 7657 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields);
7640 } 7658 }
7641 } 7659 }
7642 7660
7643 7661
7644 } // namespace dart 7662 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/il_printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698