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/constant_propagator.h" | 5 #include "vm/constant_propagator.h" |
6 | 6 |
7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
9 #include "vm/flow_graph_compiler.h" | 9 #include "vm/flow_graph_compiler.h" |
10 #include "vm/flow_graph_range_analysis.h" | 10 #include "vm/flow_graph_range_analysis.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 } | 311 } |
312 if (!SetValue(instr, value) && | 312 if (!SetValue(instr, value) && |
313 marked_phis_->Contains(instr->ssa_temp_index())) { | 313 marked_phis_->Contains(instr->ssa_temp_index())) { |
314 marked_phis_->Remove(instr->ssa_temp_index()); | 314 marked_phis_->Remove(instr->ssa_temp_index()); |
315 definition_worklist_.Add(instr); | 315 definition_worklist_.Add(instr); |
316 } | 316 } |
317 } | 317 } |
318 | 318 |
319 | 319 |
320 void ConstantPropagator::VisitRedefinition(RedefinitionInstr* instr) { | 320 void ConstantPropagator::VisitRedefinition(RedefinitionInstr* instr) { |
321 SetValue(instr, instr->value()->definition()->constant_value()); | 321 // Ensure that we never remove redefinition of a constant unless we are also |
322 // are guaranteed to fold away code paths that correspond to non-matching | |
323 // class ids. Otherwise LICM might potentially hoist incorrect code. | |
324 const Object& value = instr->value()->definition()->constant_value(); | |
325 if (IsConstant(value) && | |
326 CheckClassInstr::IsImmutableClassId(value.GetClassId())) { | |
Florian Schneider
2015/04/20 09:33:32
Works for now. Could we use the knowledge that the
| |
327 SetValue(instr, value); | |
328 } else { | |
329 SetValue(instr, non_constant_); | |
330 } | |
322 } | 331 } |
323 | 332 |
324 | 333 |
325 void ConstantPropagator::VisitParameter(ParameterInstr* instr) { | 334 void ConstantPropagator::VisitParameter(ParameterInstr* instr) { |
326 SetValue(instr, non_constant_); | 335 SetValue(instr, non_constant_); |
327 } | 336 } |
328 | 337 |
329 | 338 |
330 void ConstantPropagator::VisitPushArgument(PushArgumentInstr* instr) { | 339 void ConstantPropagator::VisitPushArgument(PushArgumentInstr* instr) { |
331 SetValue(instr, instr->value()->definition()->constant_value()); | 340 SetValue(instr, instr->value()->definition()->constant_value()); |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
781 SetValue(instr, non_constant_); | 790 SetValue(instr, non_constant_); |
782 } | 791 } |
783 | 792 |
784 | 793 |
785 void ConstantPropagator::VisitLoadClassId(LoadClassIdInstr* instr) { | 794 void ConstantPropagator::VisitLoadClassId(LoadClassIdInstr* instr) { |
786 intptr_t cid = instr->object()->Type()->ToCid(); | 795 intptr_t cid = instr->object()->Type()->ToCid(); |
787 if (cid != kDynamicCid) { | 796 if (cid != kDynamicCid) { |
788 SetValue(instr, Smi::ZoneHandle(Z, Smi::New(cid))); | 797 SetValue(instr, Smi::ZoneHandle(Z, Smi::New(cid))); |
789 return; | 798 return; |
790 } | 799 } |
800 | |
791 const Object& object = instr->object()->definition()->constant_value(); | 801 const Object& object = instr->object()->definition()->constant_value(); |
792 if (IsConstant(object)) { | 802 if (IsConstant(object)) { |
793 SetValue(instr, Smi::ZoneHandle(Z, Smi::New(object.GetClassId()))); | 803 cid = object.GetClassId(); |
794 return; | 804 if (CheckClassInstr::IsImmutableClassId(cid)) { |
805 SetValue(instr, Smi::ZoneHandle(Z, Smi::New(cid))); | |
806 return; | |
807 } | |
795 } | 808 } |
796 SetValue(instr, non_constant_); | 809 SetValue(instr, non_constant_); |
797 } | 810 } |
798 | 811 |
799 | 812 |
800 void ConstantPropagator::VisitLoadField(LoadFieldInstr* instr) { | 813 void ConstantPropagator::VisitLoadField(LoadFieldInstr* instr) { |
801 Value* instance = instr->instance(); | 814 Value* instance = instr->instance(); |
802 if ((instr->recognized_kind() == MethodRecognizer::kObjectArrayLength) && | 815 if ((instr->recognized_kind() == MethodRecognizer::kObjectArrayLength) && |
803 instance->definition()->OriginalDefinition()->IsCreateArray()) { | 816 instance->definition()->OriginalDefinition()->IsCreateArray()) { |
804 Value* num_elements = instance->definition()->OriginalDefinition() | 817 Value* num_elements = instance->definition()->OriginalDefinition() |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1663 graph_->MergeBlocks(); | 1676 graph_->MergeBlocks(); |
1664 GrowableArray<BitVector*> dominance_frontier; | 1677 GrowableArray<BitVector*> dominance_frontier; |
1665 graph_->ComputeDominators(&dominance_frontier); | 1678 graph_->ComputeDominators(&dominance_frontier); |
1666 | 1679 |
1667 if (FLAG_trace_constant_propagation) { | 1680 if (FLAG_trace_constant_propagation) { |
1668 FlowGraphPrinter::PrintGraph("After CP", graph_); | 1681 FlowGraphPrinter::PrintGraph("After CP", graph_); |
1669 } | 1682 } |
1670 } | 1683 } |
1671 | 1684 |
1672 } // namespace dart | 1685 } // namespace dart |
OLD | NEW |