| 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/flow_graph_builder.h" | 9 #include "vm/flow_graph_builder.h" |
| 10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
| (...skipping 3652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3663 return Alias::VMField(load_field->offset_in_bytes()); | 3663 return Alias::VMField(load_field->offset_in_bytes()); |
| 3664 } | 3664 } |
| 3665 } | 3665 } |
| 3666 | 3666 |
| 3667 if (defn->IsCurrentContext()) { | 3667 if (defn->IsCurrentContext()) { |
| 3668 return Alias::CurrentContext(); | 3668 return Alias::CurrentContext(); |
| 3669 } | 3669 } |
| 3670 | 3670 |
| 3671 LoadStaticFieldInstr* load_static_field = defn->AsLoadStaticField(); | 3671 LoadStaticFieldInstr* load_static_field = defn->AsLoadStaticField(); |
| 3672 if (load_static_field != NULL) { | 3672 if (load_static_field != NULL) { |
| 3673 return Alias::Field(GetFieldId(kAnyInstance, load_static_field->field())); | 3673 return Alias::Field(GetFieldId(kAnyInstance, |
| 3674 load_static_field->StaticField())); |
| 3674 } | 3675 } |
| 3675 | 3676 |
| 3676 UNREACHABLE(); | 3677 UNREACHABLE(); |
| 3677 return Alias::None(); | 3678 return Alias::None(); |
| 3678 } | 3679 } |
| 3679 | 3680 |
| 3680 Alias ComputeAliasForStore(Instruction* instr) { | 3681 Alias ComputeAliasForStore(Instruction* instr) { |
| 3681 if (instr->IsStoreIndexed()) { | 3682 if (instr->IsStoreIndexed()) { |
| 3682 return Alias::Indexes(); | 3683 return Alias::Indexes(); |
| 3683 } | 3684 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3839 return true; | 3840 return true; |
| 3840 } | 3841 } |
| 3841 | 3842 |
| 3842 AllocateObjectInstr* alloc = | 3843 AllocateObjectInstr* alloc = |
| 3843 load_field->instance()->definition()->AsAllocateObject(); | 3844 load_field->instance()->definition()->AsAllocateObject(); |
| 3844 return (alloc != NULL) && !CanBeAliased(alloc); | 3845 return (alloc != NULL) && !CanBeAliased(alloc); |
| 3845 } | 3846 } |
| 3846 | 3847 |
| 3847 LoadStaticFieldInstr* load_static_field = defn->AsLoadStaticField(); | 3848 LoadStaticFieldInstr* load_static_field = defn->AsLoadStaticField(); |
| 3848 if (load_static_field != NULL) { | 3849 if (load_static_field != NULL) { |
| 3849 return load_static_field->field().is_final(); | 3850 return load_static_field->StaticField().is_final(); |
| 3850 } | 3851 } |
| 3851 | 3852 |
| 3852 return false; | 3853 return false; |
| 3853 } | 3854 } |
| 3854 | 3855 |
| 3855 class FieldIdPair { | 3856 class FieldIdPair { |
| 3856 public: | 3857 public: |
| 3857 struct Key { | 3858 struct Key { |
| 3858 Key(intptr_t instance_id, const Field* field) | 3859 Key(intptr_t instance_id, const Field* field) |
| 3859 : instance_id_(instance_id), field_(field) { } | 3860 : instance_id_(instance_id), field_(field) { } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3967 } else if (key->IsStoreInstanceField()) { | 3968 } else if (key->IsStoreInstanceField()) { |
| 3968 StoreInstanceFieldInstr* store_field = key->AsStoreInstanceField(); | 3969 StoreInstanceFieldInstr* store_field = key->AsStoreInstanceField(); |
| 3969 object = store_field->instance()->definition()->ssa_temp_index(); | 3970 object = store_field->instance()->definition()->ssa_temp_index(); |
| 3970 location = store_field->field().Offset(); | 3971 location = store_field->field().Offset(); |
| 3971 } else if (key->IsStoreVMField()) { | 3972 } else if (key->IsStoreVMField()) { |
| 3972 StoreVMFieldInstr* store_field = key->AsStoreVMField(); | 3973 StoreVMFieldInstr* store_field = key->AsStoreVMField(); |
| 3973 object = store_field->dest()->definition()->ssa_temp_index(); | 3974 object = store_field->dest()->definition()->ssa_temp_index(); |
| 3974 location = store_field->offset_in_bytes(); | 3975 location = store_field->offset_in_bytes(); |
| 3975 } else if (key->IsLoadStaticField()) { | 3976 } else if (key->IsLoadStaticField()) { |
| 3976 LoadStaticFieldInstr* load_static_field = key->AsLoadStaticField(); | 3977 LoadStaticFieldInstr* load_static_field = key->AsLoadStaticField(); |
| 3977 object = String::Handle(load_static_field->field().name()).Hash(); | 3978 object = String::Handle(load_static_field->StaticField().name()).Hash(); |
| 3978 } else if (key->IsStoreStaticField()) { | 3979 } else if (key->IsStoreStaticField()) { |
| 3979 StoreStaticFieldInstr* store_static_field = key->AsStoreStaticField(); | 3980 StoreStaticFieldInstr* store_static_field = key->AsStoreStaticField(); |
| 3980 object = String::Handle(store_static_field->field().name()).Hash(); | 3981 object = String::Handle(store_static_field->field().name()).Hash(); |
| 3981 } else { | 3982 } else { |
| 3982 ASSERT(key->IsStoreContext() || | 3983 ASSERT(key->IsStoreContext() || |
| 3983 key->IsCurrentContext() || | 3984 key->IsCurrentContext() || |
| 3984 key->IsChainContext()); | 3985 key->IsChainContext()); |
| 3985 } | 3986 } |
| 3986 | 3987 |
| 3987 return object * 31 + location; | 3988 return object * 31 + location; |
| 3988 } | 3989 } |
| 3989 | 3990 |
| 3990 static inline bool IsKeyEqual(Pair kv, Key key) { | 3991 static inline bool IsKeyEqual(Pair kv, Key key) { |
| 3991 if (kv->Equals(key)) return true; | 3992 if (kv->Equals(key)) return true; |
| 3992 | 3993 |
| 3993 if (kv->IsLoadIndexed()) { | 3994 if (kv->IsLoadIndexed()) { |
| 3994 if (key->IsStoreIndexed()) { | 3995 if (key->IsStoreIndexed()) { |
| 3995 LoadIndexedInstr* load_indexed = kv->AsLoadIndexed(); | 3996 LoadIndexedInstr* load_indexed = kv->AsLoadIndexed(); |
| 3996 StoreIndexedInstr* store_indexed = key->AsStoreIndexed(); | 3997 StoreIndexedInstr* store_indexed = key->AsStoreIndexed(); |
| 3997 return load_indexed->array()->Equals(store_indexed->array()) && | 3998 return load_indexed->array()->Equals(store_indexed->array()) && |
| 3998 load_indexed->index()->Equals(store_indexed->index()); | 3999 load_indexed->index()->Equals(store_indexed->index()); |
| 3999 } | 4000 } |
| 4000 return false; | 4001 return false; |
| 4001 } | 4002 } |
| 4002 | 4003 |
| 4003 if (kv->IsLoadStaticField()) { | 4004 if (kv->IsLoadStaticField()) { |
| 4004 if (key->IsStoreStaticField()) { | 4005 if (key->IsStoreStaticField()) { |
| 4005 LoadStaticFieldInstr* load_static_field = kv->AsLoadStaticField(); | 4006 LoadStaticFieldInstr* load_static_field = kv->AsLoadStaticField(); |
| 4006 StoreStaticFieldInstr* store_static_field = key->AsStoreStaticField(); | 4007 StoreStaticFieldInstr* store_static_field = key->AsStoreStaticField(); |
| 4007 return load_static_field->field().raw() == | 4008 return load_static_field->StaticField().raw() == |
| 4008 store_static_field->field().raw(); | 4009 store_static_field->field().raw(); |
| 4009 } | 4010 } |
| 4010 return false; | 4011 return false; |
| 4011 } | 4012 } |
| 4012 | 4013 |
| 4013 if (kv->IsCurrentContext()) { | 4014 if (kv->IsCurrentContext()) { |
| 4014 return key->IsStoreContext() || key->IsChainContext(); | 4015 return key->IsStoreContext() || key->IsChainContext(); |
| 4015 } | 4016 } |
| 4016 | 4017 |
| 4017 ASSERT(kv->IsLoadField()); | 4018 ASSERT(kv->IsLoadField()); |
| (...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5229 } | 5230 } |
| 5230 | 5231 |
| 5231 | 5232 |
| 5232 void ConstantPropagator::VisitStoreInstanceField( | 5233 void ConstantPropagator::VisitStoreInstanceField( |
| 5233 StoreInstanceFieldInstr* instr) { | 5234 StoreInstanceFieldInstr* instr) { |
| 5234 SetValue(instr, instr->value()->definition()->constant_value()); | 5235 SetValue(instr, instr->value()->definition()->constant_value()); |
| 5235 } | 5236 } |
| 5236 | 5237 |
| 5237 | 5238 |
| 5238 void ConstantPropagator::VisitLoadStaticField(LoadStaticFieldInstr* instr) { | 5239 void ConstantPropagator::VisitLoadStaticField(LoadStaticFieldInstr* instr) { |
| 5239 const Field& field = instr->field(); | 5240 const Field& field = instr->StaticField(); |
| 5240 ASSERT(field.is_static()); | 5241 ASSERT(field.is_static()); |
| 5241 if (field.is_final()) { | 5242 if (field.is_final()) { |
| 5242 Instance& obj = Instance::Handle(field.value()); | 5243 Instance& obj = Instance::Handle(field.value()); |
| 5243 if (obj.IsSmi() || obj.IsOld()) { | 5244 if (obj.IsSmi() || obj.IsOld()) { |
| 5244 SetValue(instr, obj); | 5245 SetValue(instr, obj); |
| 5245 return; | 5246 return; |
| 5246 } | 5247 } |
| 5247 } | 5248 } |
| 5248 SetValue(instr, non_constant_); | 5249 SetValue(instr, non_constant_); |
| 5249 } | 5250 } |
| (...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6570 | 6571 |
| 6571 // Insert materializations at environment uses. | 6572 // Insert materializations at environment uses. |
| 6572 const Class& cls = Class::Handle(alloc->constructor().Owner()); | 6573 const Class& cls = Class::Handle(alloc->constructor().Owner()); |
| 6573 for (intptr_t i = 0; i < exits.length(); i++) { | 6574 for (intptr_t i = 0; i < exits.length(); i++) { |
| 6574 CreateMaterializationAt(exits[i], alloc, cls, *fields); | 6575 CreateMaterializationAt(exits[i], alloc, cls, *fields); |
| 6575 } | 6576 } |
| 6576 } | 6577 } |
| 6577 | 6578 |
| 6578 | 6579 |
| 6579 } // namespace dart | 6580 } // namespace dart |
| OLD | NEW |