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