Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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_ = Unwrap(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_ = Unwrap(store_instance_field->instance()->definition()); |
| 4168 field_ = &store_instance_field->field(); | 4168 field_ = &store_instance_field->field(); |
| 4169 break; | 4169 break; |
| 4170 } | 4170 } |
| 4171 | 4171 |
| 4172 case Instruction::kStoreVMField: { | 4172 case Instruction::kStoreVMField: { |
| 4173 StoreVMFieldInstr* store_vm_field = instr->AsStoreVMField(); | 4173 StoreVMFieldInstr* store_vm_field = instr->AsStoreVMField(); |
| 4174 kind_ = kVMField; | 4174 kind_ = kVMField; |
| 4175 instance_ = store_vm_field->dest()->definition(); | 4175 instance_ = Unwrap(store_vm_field->dest()->definition()); |
| 4176 offset_in_bytes_ = store_vm_field->offset_in_bytes(); | 4176 offset_in_bytes_ = store_vm_field->offset_in_bytes(); |
| 4177 break; | 4177 break; |
| 4178 } | 4178 } |
| 4179 | 4179 |
| 4180 case Instruction::kLoadStaticField: | 4180 case Instruction::kLoadStaticField: |
| 4181 kind_ = kField; | 4181 kind_ = kField; |
| 4182 field_ = &instr->AsLoadStaticField()->StaticField(); | 4182 field_ = &instr->AsLoadStaticField()->StaticField(); |
| 4183 *is_load = true; | 4183 *is_load = true; |
| 4184 break; | 4184 break; |
| 4185 | 4185 |
| 4186 case Instruction::kStoreStaticField: | 4186 case Instruction::kStoreStaticField: |
| 4187 kind_ = kField; | 4187 kind_ = kField; |
| 4188 field_ = &instr->AsStoreStaticField()->field(); | 4188 field_ = &instr->AsStoreStaticField()->field(); |
| 4189 break; | 4189 break; |
| 4190 | 4190 |
| 4191 case Instruction::kLoadIndexed: { | 4191 case Instruction::kLoadIndexed: { |
| 4192 LoadIndexedInstr* load_indexed = instr->AsLoadIndexed(); | 4192 LoadIndexedInstr* load_indexed = instr->AsLoadIndexed(); |
| 4193 kind_ = kIndexed; | 4193 kind_ = kIndexed; |
| 4194 instance_ = load_indexed->array()->definition(); | 4194 instance_ = Unwrap(load_indexed->array()->definition()); |
| 4195 index_ = load_indexed->index()->definition(); | 4195 index_ = load_indexed->index()->definition(); |
| 4196 *is_load = true; | 4196 *is_load = true; |
| 4197 break; | 4197 break; |
| 4198 } | 4198 } |
| 4199 | 4199 |
| 4200 case Instruction::kStoreIndexed: { | 4200 case Instruction::kStoreIndexed: { |
| 4201 StoreIndexedInstr* store_indexed = instr->AsStoreIndexed(); | 4201 StoreIndexedInstr* store_indexed = instr->AsStoreIndexed(); |
| 4202 kind_ = kIndexed; | 4202 kind_ = kIndexed; |
| 4203 instance_ = store_indexed->array()->definition(); | 4203 instance_ = Unwrap(store_indexed->array()->definition()); |
| 4204 index_ = store_indexed->index()->definition(); | 4204 index_ = store_indexed->index()->definition(); |
| 4205 break; | 4205 break; |
| 4206 } | 4206 } |
| 4207 | 4207 |
| 4208 case Instruction::kCurrentContext: | 4208 case Instruction::kCurrentContext: |
| 4209 kind_ = kContext; | 4209 kind_ = kContext; |
| 4210 *is_load = true; | 4210 *is_load = true; |
| 4211 break; | 4211 break; |
| 4212 | 4212 |
| 4213 case Instruction::kStoreContext: | 4213 case Instruction::kStoreContext: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 4224 | 4224 |
| 4225 Kind kind() const { return kind_; } | 4225 Kind kind() const { return kind_; } |
| 4226 | 4226 |
| 4227 Definition* instance() const { | 4227 Definition* instance() const { |
| 4228 ASSERT((kind_ == kField) || (kind_ == kVMField) || (kind_ == kIndexed)); | 4228 ASSERT((kind_ == kField) || (kind_ == kVMField) || (kind_ == kIndexed)); |
| 4229 return instance_; | 4229 return instance_; |
| 4230 } | 4230 } |
| 4231 | 4231 |
| 4232 void set_instance(Definition* def) { | 4232 void set_instance(Definition* def) { |
| 4233 ASSERT((kind_ == kField) || (kind_ == kVMField) || (kind_ == kIndexed)); | 4233 ASSERT((kind_ == kField) || (kind_ == kVMField) || (kind_ == kIndexed)); |
| 4234 instance_ = def; | 4234 instance_ = Unwrap(def); |
| 4235 } | 4235 } |
| 4236 | 4236 |
| 4237 const Field& field() const { | 4237 const Field& field() const { |
| 4238 ASSERT(kind_ == kField); | 4238 ASSERT(kind_ == kField); |
| 4239 return *field_; | 4239 return *field_; |
| 4240 } | 4240 } |
| 4241 | 4241 |
| 4242 intptr_t offset_in_bytes() const { | 4242 intptr_t offset_in_bytes() const { |
| 4243 ASSERT(kind_ == kVMField); | 4243 ASSERT(kind_ == kVMField); |
| 4244 return offset_in_bytes_; | 4244 return offset_in_bytes_; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4295 bool Equals(Place* other) const { | 4295 bool Equals(Place* other) const { |
| 4296 return (kind_ == other->kind_) && | 4296 return (kind_ == other->kind_) && |
| 4297 (instance_ == other->instance_) && | 4297 (instance_ == other->instance_) && |
| 4298 SameField(other); | 4298 SameField(other); |
| 4299 } | 4299 } |
| 4300 | 4300 |
| 4301 // Create a zone allocated copy of this place. | 4301 // Create a zone allocated copy of this place. |
| 4302 static Place* Wrap(const Place& place); | 4302 static Place* Wrap(const Place& place); |
| 4303 | 4303 |
| 4304 private: | 4304 private: |
| 4305 static Definition* Unwrap(Definition* defn) { | |
|
Kevin Millikin (Google)
2013/10/02 12:36:19
Even though it's only used locally, this name is t
Florian Schneider
2013/10/02 12:58:41
Done.
| |
| 4306 while (defn->IsRedefinition()) { | |
| 4307 defn = defn->AsRedefinition()->value()->definition(); | |
| 4308 } | |
| 4309 return defn; | |
| 4310 } | |
| 4311 | |
| 4305 bool SameField(Place* other) const { | 4312 bool SameField(Place* other) const { |
| 4306 return (kind_ == kField) ? (field().raw() == other->field().raw()) | 4313 return (kind_ == kField) ? (field().raw() == other->field().raw()) |
| 4307 : (offset_in_bytes_ == other->offset_in_bytes_); | 4314 : (offset_in_bytes_ == other->offset_in_bytes_); |
| 4308 } | 4315 } |
| 4309 | 4316 |
| 4310 intptr_t FieldHashcode() const { | 4317 intptr_t FieldHashcode() const { |
| 4311 return (kind_ == kField) ? reinterpret_cast<intptr_t>(field().raw()) | 4318 return (kind_ == kField) ? reinterpret_cast<intptr_t>(field().raw()) |
| 4312 : offset_in_bytes_; | 4319 : offset_in_bytes_; |
| 4313 } | 4320 } |
| 4314 | 4321 |
| (...skipping 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6273 SetValue(instr, non_constant_); | 6280 SetValue(instr, non_constant_); |
| 6274 } | 6281 } |
| 6275 | 6282 |
| 6276 | 6283 |
| 6277 void ConstantPropagator::VisitLoadUntagged(LoadUntaggedInstr* instr) { | 6284 void ConstantPropagator::VisitLoadUntagged(LoadUntaggedInstr* instr) { |
| 6278 SetValue(instr, non_constant_); | 6285 SetValue(instr, non_constant_); |
| 6279 } | 6286 } |
| 6280 | 6287 |
| 6281 | 6288 |
| 6282 void ConstantPropagator::VisitLoadClassId(LoadClassIdInstr* instr) { | 6289 void ConstantPropagator::VisitLoadClassId(LoadClassIdInstr* instr) { |
| 6290 intptr_t cid = instr->object()->Type()->ToCid(); | |
| 6291 if (cid != kDynamicCid) { | |
| 6292 SetValue(instr, Smi::ZoneHandle(Smi::New(cid))); | |
| 6293 return; | |
| 6294 } | |
| 6283 SetValue(instr, non_constant_); | 6295 SetValue(instr, non_constant_); |
|
Kevin Millikin (Google)
2013/10/02 12:36:19
You could also try this: if instr->object() has a
Florian Schneider
2013/10/02 12:58:41
Done.
| |
| 6284 } | 6296 } |
| 6285 | 6297 |
| 6286 | 6298 |
| 6287 void ConstantPropagator::VisitLoadField(LoadFieldInstr* instr) { | 6299 void ConstantPropagator::VisitLoadField(LoadFieldInstr* instr) { |
| 6288 if ((instr->recognized_kind() == MethodRecognizer::kObjectArrayLength) && | 6300 if ((instr->recognized_kind() == MethodRecognizer::kObjectArrayLength) && |
| 6289 (instr->instance()->definition()->IsCreateArray())) { | 6301 (instr->instance()->definition()->IsCreateArray())) { |
| 6290 const intptr_t length = | 6302 const intptr_t length = |
| 6291 instr->instance()->definition()->AsCreateArray()->num_elements(); | 6303 instr->instance()->definition()->AsCreateArray()->num_elements(); |
| 6292 const Object& result = Smi::ZoneHandle(Smi::New(length)); | 6304 const Object& result = Smi::ZoneHandle(Smi::New(length)); |
| 6293 SetValue(instr, result); | 6305 SetValue(instr, result); |
| (...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7635 } | 7647 } |
| 7636 | 7648 |
| 7637 // Insert materializations at environment uses. | 7649 // Insert materializations at environment uses. |
| 7638 for (intptr_t i = 0; i < exits.length(); i++) { | 7650 for (intptr_t i = 0; i < exits.length(); i++) { |
| 7639 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); | 7651 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); |
| 7640 } | 7652 } |
| 7641 } | 7653 } |
| 7642 | 7654 |
| 7643 | 7655 |
| 7644 } // namespace dart | 7656 } // namespace dart |
| OLD | NEW |