| 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 1850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1861 // rename all uses that are dominated by it. | 1861 // rename all uses that are dominated by it. |
| 1862 ConstraintInstr* InsertConstraintFor(Definition* defn, | 1862 ConstraintInstr* InsertConstraintFor(Definition* defn, |
| 1863 Range* constraint, | 1863 Range* constraint, |
| 1864 Instruction* after); | 1864 Instruction* after); |
| 1865 | 1865 |
| 1866 void ConstrainValueAfterBranch(Definition* defn, Value* use); | 1866 void ConstrainValueAfterBranch(Definition* defn, Value* use); |
| 1867 void ConstrainValueAfterCheckArrayBound(Definition* defn, | 1867 void ConstrainValueAfterCheckArrayBound(Definition* defn, |
| 1868 CheckArrayBoundInstr* check); | 1868 CheckArrayBoundInstr* check); |
| 1869 Definition* LoadArrayLength(CheckArrayBoundInstr* check); | 1869 Definition* LoadArrayLength(CheckArrayBoundInstr* check); |
| 1870 | 1870 |
| 1871 | |
| 1872 | |
| 1873 // Replace uses of the definition def that are dominated by instruction dom | 1871 // Replace uses of the definition def that are dominated by instruction dom |
| 1874 // with uses of other definition. | 1872 // with uses of other definition. |
| 1875 void RenameDominatedUses(Definition* def, | 1873 void RenameDominatedUses(Definition* def, |
| 1876 Instruction* dom, | 1874 Instruction* dom, |
| 1877 Definition* other); | 1875 Definition* other); |
| 1878 | 1876 |
| 1879 | 1877 |
| 1880 // Walk the dominator tree and infer ranges for smi values. | 1878 // Walk the dominator tree and infer ranges for smi values. |
| 1881 void InferRanges(); | 1879 void InferRanges(); |
| 1882 void InferRangesRecursive(BlockEntryInstr* block); | 1880 void InferRangesRecursive(BlockEntryInstr* block); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2219 (allocation->ResultCid() == kArrayCid)) { | 2217 (allocation->ResultCid() == kArrayCid)) { |
| 2220 // For fixed length arrays check if array is the result of a constructor | 2218 // For fixed length arrays check if array is the result of a constructor |
| 2221 // call. In this case we can use the length passed to the constructor | 2219 // call. In this case we can use the length passed to the constructor |
| 2222 // instead of loading it from array itself. | 2220 // instead of loading it from array itself. |
| 2223 length = allocation->ArgumentAt(1)->value()->definition(); | 2221 length = allocation->ArgumentAt(1)->value()->definition(); |
| 2224 } else { | 2222 } else { |
| 2225 // Load length from the array. Do not insert instruction into the graph. | 2223 // Load length from the array. Do not insert instruction into the graph. |
| 2226 // It will only be used in range boundaries. | 2224 // It will only be used in range boundaries. |
| 2227 LoadFieldInstr* length_load = new LoadFieldInstr( | 2225 LoadFieldInstr* length_load = new LoadFieldInstr( |
| 2228 check->array()->Copy(), | 2226 check->array()->Copy(), |
| 2229 Array::length_offset(), | 2227 CheckArrayBoundInstr::LengthOffsetFor(check->array_type()), |
| 2230 Type::ZoneHandle(Type::SmiType()), | 2228 Type::ZoneHandle(Type::SmiType()), |
| 2231 true); // Immutable. | 2229 true); // Immutable. |
| 2232 length_load->set_recognized_kind(MethodRecognizer::kObjectArrayLength); | 2230 length_load->set_recognized_kind(MethodRecognizer::kObjectArrayLength); |
| 2233 length_load->set_result_cid(kSmiCid); | 2231 length_load->set_result_cid(kSmiCid); |
| 2234 length_load->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index()); | 2232 length_load->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index()); |
| 2235 length = length_load; | 2233 length = length_load; |
| 2236 } | 2234 } |
| 2237 | 2235 |
| 2238 ASSERT(length != NULL); | 2236 ASSERT(length != NULL); |
| 2239 array_lengths_.Insert(ArrayLengthData(array, length)); | 2237 array_lengths_.Insert(ArrayLengthData(array, length)); |
| 2240 return length; | 2238 return length; |
| 2241 } | 2239 } |
| 2242 | 2240 |
| 2243 | 2241 |
| 2244 void RangeAnalysis::ConstrainValueAfterCheckArrayBound( | 2242 void RangeAnalysis::ConstrainValueAfterCheckArrayBound( |
| 2245 Definition* defn, CheckArrayBoundInstr* check) { | 2243 Definition* defn, CheckArrayBoundInstr* check) { |
| 2246 if ((check->array_type() != kArrayCid) && | 2244 if (!CheckArrayBoundInstr::IsFixedLengthArrayType(check->array_type())) { |
| 2247 (check->array_type() != kImmutableArrayCid)) { | |
| 2248 return; | 2245 return; |
| 2249 } | 2246 } |
| 2250 | 2247 |
| 2251 Definition* length = LoadArrayLength(check); | 2248 Definition* length = LoadArrayLength(check); |
| 2252 | 2249 |
| 2253 Range* constraint_range = new Range( | 2250 Range* constraint_range = new Range( |
| 2254 RangeBoundary::FromConstant(0), | 2251 RangeBoundary::FromConstant(0), |
| 2255 RangeBoundary::FromDefinition(length, -1)); | 2252 RangeBoundary::FromDefinition(length, -1)); |
| 2256 InsertConstraintFor(defn, constraint_range, check); | 2253 InsertConstraintFor(defn, constraint_range, check); |
| 2257 } | 2254 } |
| (...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4423 | 4420 |
| 4424 if (FLAG_trace_constant_propagation) { | 4421 if (FLAG_trace_constant_propagation) { |
| 4425 OS::Print("\n==== After constant propagation ====\n"); | 4422 OS::Print("\n==== After constant propagation ====\n"); |
| 4426 FlowGraphPrinter printer(*graph_); | 4423 FlowGraphPrinter printer(*graph_); |
| 4427 printer.PrintBlocks(); | 4424 printer.PrintBlocks(); |
| 4428 } | 4425 } |
| 4429 } | 4426 } |
| 4430 | 4427 |
| 4431 | 4428 |
| 4432 } // namespace dart | 4429 } // namespace dart |
| OLD | NEW |