| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 1764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1775 // rename all uses that are dominated by it. | 1775 // rename all uses that are dominated by it. |
| 1776 ConstraintInstr* InsertConstraintFor(Definition* defn, | 1776 ConstraintInstr* InsertConstraintFor(Definition* defn, |
| 1777 Range* constraint, | 1777 Range* constraint, |
| 1778 Instruction* after); | 1778 Instruction* after); |
| 1779 | 1779 |
| 1780 void ConstrainValueAfterBranch(Definition* defn, Value* use); | 1780 void ConstrainValueAfterBranch(Definition* defn, Value* use); |
| 1781 void ConstrainValueAfterCheckArrayBound(Definition* defn, | 1781 void ConstrainValueAfterCheckArrayBound(Definition* defn, |
| 1782 CheckArrayBoundInstr* check); | 1782 CheckArrayBoundInstr* check); |
| 1783 Definition* LoadArrayLength(CheckArrayBoundInstr* check); | 1783 Definition* LoadArrayLength(CheckArrayBoundInstr* check); |
| 1784 | 1784 |
| 1785 | |
| 1786 | |
| 1787 // Replace uses of the definition def that are dominated by instruction dom | 1785 // Replace uses of the definition def that are dominated by instruction dom |
| 1788 // with uses of other definition. | 1786 // with uses of other definition. |
| 1789 void RenameDominatedUses(Definition* def, | 1787 void RenameDominatedUses(Definition* def, |
| 1790 Instruction* dom, | 1788 Instruction* dom, |
| 1791 Definition* other); | 1789 Definition* other); |
| 1792 | 1790 |
| 1793 | 1791 |
| 1794 // Walk the dominator tree and infer ranges for smi values. | 1792 // Walk the dominator tree and infer ranges for smi values. |
| 1795 void InferRanges(); | 1793 void InferRanges(); |
| 1796 void InferRangesRecursive(BlockEntryInstr* block); | 1794 void InferRangesRecursive(BlockEntryInstr* block); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2133 (allocation->ResultCid() == kArrayCid)) { | 2131 (allocation->ResultCid() == kArrayCid)) { |
| 2134 // For fixed length arrays check if array is the result of a constructor | 2132 // For fixed length arrays check if array is the result of a constructor |
| 2135 // call. In this case we can use the length passed to the constructor | 2133 // call. In this case we can use the length passed to the constructor |
| 2136 // instead of loading it from array itself. | 2134 // instead of loading it from array itself. |
| 2137 length = allocation->ArgumentAt(1)->value()->definition(); | 2135 length = allocation->ArgumentAt(1)->value()->definition(); |
| 2138 } else { | 2136 } else { |
| 2139 // Load length from the array. Do not insert instruction into the graph. | 2137 // Load length from the array. Do not insert instruction into the graph. |
| 2140 // It will only be used in range boundaries. | 2138 // It will only be used in range boundaries. |
| 2141 LoadFieldInstr* length_load = new LoadFieldInstr( | 2139 LoadFieldInstr* length_load = new LoadFieldInstr( |
| 2142 check->array()->Copy(), | 2140 check->array()->Copy(), |
| 2143 Array::length_offset(), | 2141 CheckArrayBoundInstr::LengthOffsetFor(check->array_type()), |
| 2144 Type::ZoneHandle(Type::SmiType()), | 2142 Type::ZoneHandle(Type::SmiType()), |
| 2145 true); // Immutable. | 2143 true); // Immutable. |
| 2146 length_load->set_recognized_kind(MethodRecognizer::kObjectArrayLength); | 2144 length_load->set_recognized_kind(MethodRecognizer::kObjectArrayLength); |
| 2147 length_load->set_result_cid(kSmiCid); | 2145 length_load->set_result_cid(kSmiCid); |
| 2148 length_load->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index()); | 2146 length_load->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index()); |
| 2149 length = length_load; | 2147 length = length_load; |
| 2150 } | 2148 } |
| 2151 | 2149 |
| 2152 ASSERT(length != NULL); | 2150 ASSERT(length != NULL); |
| 2153 array_lengths_.Insert(ArrayLengthData(array, length)); | 2151 array_lengths_.Insert(ArrayLengthData(array, length)); |
| 2154 return length; | 2152 return length; |
| 2155 } | 2153 } |
| 2156 | 2154 |
| 2157 | 2155 |
| 2158 void RangeAnalysis::ConstrainValueAfterCheckArrayBound( | 2156 void RangeAnalysis::ConstrainValueAfterCheckArrayBound( |
| 2159 Definition* defn, CheckArrayBoundInstr* check) { | 2157 Definition* defn, CheckArrayBoundInstr* check) { |
| 2160 if ((check->array_type() != kArrayCid) && | 2158 if (!CheckArrayBoundInstr::IsFixedLengthArrayType(check->array_type())) { |
| 2161 (check->array_type() != kImmutableArrayCid)) { | |
| 2162 return; | 2159 return; |
| 2163 } | 2160 } |
| 2164 | 2161 |
| 2165 Definition* length = LoadArrayLength(check); | 2162 Definition* length = LoadArrayLength(check); |
| 2166 | 2163 |
| 2167 Range* constraint_range = new Range( | 2164 Range* constraint_range = new Range( |
| 2168 RangeBoundary::FromConstant(0), | 2165 RangeBoundary::FromConstant(0), |
| 2169 RangeBoundary::FromDefinition(length, -1)); | 2166 RangeBoundary::FromDefinition(length, -1)); |
| 2170 InsertConstraintFor(defn, constraint_range, check); | 2167 InsertConstraintFor(defn, constraint_range, check); |
| 2171 } | 2168 } |
| (...skipping 2125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4297 | 4294 |
| 4298 if (FLAG_trace_constant_propagation) { | 4295 if (FLAG_trace_constant_propagation) { |
| 4299 OS::Print("\n==== After constant propagation ====\n"); | 4296 OS::Print("\n==== After constant propagation ====\n"); |
| 4300 FlowGraphPrinter printer(*graph_); | 4297 FlowGraphPrinter printer(*graph_); |
| 4301 printer.PrintBlocks(); | 4298 printer.PrintBlocks(); |
| 4302 } | 4299 } |
| 4303 } | 4300 } |
| 4304 | 4301 |
| 4305 | 4302 |
| 4306 } // namespace dart | 4303 } // namespace dart |
| OLD | NEW |