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 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 ->num_elements(); | 824 ->num_elements(); |
825 if (num_elements->BindsToConstant() && | 825 if (num_elements->BindsToConstant() && |
826 num_elements->BoundConstant().IsSmi()) { | 826 num_elements->BoundConstant().IsSmi()) { |
827 intptr_t length = Smi::Cast(num_elements->BoundConstant()).Value(); | 827 intptr_t length = Smi::Cast(num_elements->BoundConstant()).Value(); |
828 const Object& result = Smi::ZoneHandle(Z, Smi::New(length)); | 828 const Object& result = Smi::ZoneHandle(Z, Smi::New(length)); |
829 SetValue(instr, result); | 829 SetValue(instr, result); |
830 return; | 830 return; |
831 } | 831 } |
832 } | 832 } |
833 | 833 |
834 const Object& constant = instance->definition()->constant_value(); | 834 if (instr->IsImmutableLengthLoad()) { |
835 if (IsConstant(constant)) { | 835 ConstantInstr* constant = |
836 if (instr->IsImmutableLengthLoad()) { | 836 instance->definition()->OriginalDefinition()->AsConstant(); |
837 if (constant.IsString()) { | 837 if (constant != NULL) { |
| 838 if (constant->value().IsString()) { |
838 SetValue(instr, | 839 SetValue(instr, |
839 Smi::ZoneHandle(Z, Smi::New(String::Cast(constant).Length()))); | 840 Smi::ZoneHandle( |
| 841 Z, Smi::New(String::Cast(constant->value()).Length()))); |
840 return; | 842 return; |
841 } | 843 } |
842 if (constant.IsArray()) { | 844 if (constant->value().IsArray()) { |
843 SetValue(instr, | 845 SetValue(instr, |
844 Smi::ZoneHandle(Z, Smi::New(Array::Cast(constant).Length()))); | 846 Smi::ZoneHandle( |
| 847 Z, Smi::New(Array::Cast(constant->value()).Length()))); |
845 return; | 848 return; |
846 } | 849 } |
847 if (constant.IsTypedData()) { | 850 if (constant->value().IsTypedData()) { |
848 SetValue(instr, Smi::ZoneHandle( | 851 SetValue(instr, |
849 Z, Smi::New(TypedData::Cast(constant).Length()))); | 852 Smi::ZoneHandle( |
850 return; | 853 Z, Smi::New(TypedData::Cast(constant->value()).Length()))); |
851 } | |
852 } else { | |
853 Object& value = Object::Handle(); | |
854 if (instr->Evaluate(constant, &value)) { | |
855 SetValue(instr, Object::ZoneHandle(Z, value.raw())); | |
856 return; | 854 return; |
857 } | 855 } |
858 } | 856 } |
859 } | 857 } |
860 | |
861 SetValue(instr, non_constant_); | 858 SetValue(instr, non_constant_); |
862 } | 859 } |
863 | 860 |
864 | 861 |
865 void ConstantPropagator::VisitInstantiateType(InstantiateTypeInstr* instr) { | 862 void ConstantPropagator::VisitInstantiateType(InstantiateTypeInstr* instr) { |
866 const Object& object = | 863 const Object& object = |
867 instr->instantiator_type_arguments()->definition()->constant_value(); | 864 instr->instantiator_type_arguments()->definition()->constant_value(); |
868 if (IsNonConstant(object)) { | 865 if (IsNonConstant(object)) { |
869 SetValue(instr, non_constant_); | 866 SetValue(instr, non_constant_); |
870 return; | 867 return; |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1734 GrowableArray<BitVector*> dominance_frontier; | 1731 GrowableArray<BitVector*> dominance_frontier; |
1735 graph_->ComputeDominators(&dominance_frontier); | 1732 graph_->ComputeDominators(&dominance_frontier); |
1736 | 1733 |
1737 if (FLAG_trace_constant_propagation && | 1734 if (FLAG_trace_constant_propagation && |
1738 FlowGraphPrinter::ShouldPrint(graph_->function())) { | 1735 FlowGraphPrinter::ShouldPrint(graph_->function())) { |
1739 FlowGraphPrinter::PrintGraph("After CP", graph_); | 1736 FlowGraphPrinter::PrintGraph("After CP", graph_); |
1740 } | 1737 } |
1741 } | 1738 } |
1742 | 1739 |
1743 } // namespace dart | 1740 } // namespace dart |
OLD | NEW |