| 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 abstract class OptimizationPhase { | 7 abstract class OptimizationPhase { |
| 8 String get name; | 8 String get name; |
| 9 void visitGraph(HGraph graph); | 9 void visitGraph(HGraph graph); |
| 10 } | 10 } |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 moveLoopInvariantCode(graph); | 883 moveLoopInvariantCode(graph); |
| 884 visitBasicBlock(graph.entry, new ValueSet()); | 884 visitBasicBlock(graph.entry, new ValueSet()); |
| 885 } | 885 } |
| 886 | 886 |
| 887 void moveLoopInvariantCode(HGraph graph) { | 887 void moveLoopInvariantCode(HGraph graph) { |
| 888 for (int i = graph.blocks.length - 1; i >= 0; i--) { | 888 for (int i = graph.blocks.length - 1; i >= 0; i--) { |
| 889 HBasicBlock block = graph.blocks[i]; | 889 HBasicBlock block = graph.blocks[i]; |
| 890 if (block.isLoopHeader()) { | 890 if (block.isLoopHeader()) { |
| 891 int changesFlags = loopChangesFlags[block.id]; | 891 int changesFlags = loopChangesFlags[block.id]; |
| 892 HLoopInformation info = block.loopInformation; | 892 HLoopInformation info = block.loopInformation; |
| 893 HBasicBlock last = info.getLastBackEdge(); | 893 // Iterate over all blocks of this loop. Note that blocks in |
| 894 for (int j = block.id; j <= last.id; j++) { | 894 // inner loops are not visited here, but we know they |
| 895 moveLoopInvariantCodeFromBlock(graph.blocks[j], block, changesFlags); | 895 // were visited before because we are iterating in post-order. |
| 896 // So instructions that are GVN'ed in an inner loop are in their |
| 897 // loop entry, and [info.blocks] contains this loop entry. |
| 898 for (HBasicBlock other in info.blocks) { |
| 899 moveLoopInvariantCodeFromBlock(other, block, changesFlags); |
| 896 } | 900 } |
| 897 } | 901 } |
| 898 } | 902 } |
| 899 } | 903 } |
| 900 | 904 |
| 901 void moveLoopInvariantCodeFromBlock(HBasicBlock block, | 905 void moveLoopInvariantCodeFromBlock(HBasicBlock block, |
| 902 HBasicBlock loopHeader, | 906 HBasicBlock loopHeader, |
| 903 int changesFlags) { | 907 int changesFlags) { |
| 908 assert(block.parentLoopHeader == loopHeader); |
| 904 HBasicBlock preheader = loopHeader.predecessors[0]; | 909 HBasicBlock preheader = loopHeader.predecessors[0]; |
| 905 int dependsFlags = HInstruction.computeDependsOnFlags(changesFlags); | 910 int dependsFlags = HInstruction.computeDependsOnFlags(changesFlags); |
| 906 HInstruction instruction = block.first; | 911 HInstruction instruction = block.first; |
| 907 while (instruction != null) { | 912 while (instruction != null) { |
| 908 HInstruction next = instruction.next; | 913 HInstruction next = instruction.next; |
| 909 if (instruction.useGvn() | 914 if (instruction.useGvn() |
| 910 && (instruction is !HCheck) | 915 && (instruction is !HCheck) |
| 911 && (instruction.flags & dependsFlags) == 0) { | 916 && (instruction.flags & dependsFlags) == 0) { |
| 912 bool loopInvariantInputs = true; | 917 bool loopInvariantInputs = true; |
| 913 List<HInstruction> inputs = instruction.inputs; | 918 List<HInstruction> inputs = instruction.inputs; |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 } | 1345 } |
| 1341 | 1346 |
| 1342 // For other fields having setters in the generative constructor body, set | 1347 // For other fields having setters in the generative constructor body, set |
| 1343 // the type to UNKNOWN to avoid relying on the type set in the initializer | 1348 // the type to UNKNOWN to avoid relying on the type set in the initializer |
| 1344 // list. | 1349 // list. |
| 1345 allSetters.forEach((Element element) { | 1350 allSetters.forEach((Element element) { |
| 1346 backend.registerFieldConstructor(element, HType.UNKNOWN); | 1351 backend.registerFieldConstructor(element, HType.UNKNOWN); |
| 1347 }); | 1352 }); |
| 1348 } | 1353 } |
| 1349 } | 1354 } |
| OLD | NEW |