| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 interface OptimizationPhase { | 5 interface OptimizationPhase { |
| 6 String get name(); | 6 String get name(); |
| 7 void visitGraph(HGraph graph); | 7 void visitGraph(HGraph graph); |
| 8 } | 8 } |
| 9 | 9 |
| 10 class SsaOptimizerTask extends CompilerTask { | 10 class SsaOptimizerTask extends CompilerTask { |
| 11 final JavaScriptBackend backend; | 11 final JavaScriptBackend backend; |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 node.block.addBefore(node, newInstruction); | 704 node.block.addBefore(node, newInstruction); |
| 705 node.block.rewrite(node, newInstruction); | 705 node.block.rewrite(node, newInstruction); |
| 706 node.block.remove(node); | 706 node.block.remove(node); |
| 707 } | 707 } |
| 708 } | 708 } |
| 709 | 709 |
| 710 class SsaDeadCodeEliminator extends HGraphVisitor implements OptimizationPhase { | 710 class SsaDeadCodeEliminator extends HGraphVisitor implements OptimizationPhase { |
| 711 final String name = "SsaDeadCodeEliminator"; | 711 final String name = "SsaDeadCodeEliminator"; |
| 712 | 712 |
| 713 static bool isDeadCode(HInstruction instruction) { | 713 static bool isDeadCode(HInstruction instruction) { |
| 714 // TODO(ngeoffray): the way we handle side effects is not right |
| 715 // (e.g. branching instructions have side effects). |
| 714 return !instruction.hasSideEffects() | 716 return !instruction.hasSideEffects() |
| 715 && instruction.usedBy.isEmpty() | 717 && instruction.usedBy.isEmpty() |
| 716 && instruction is !HCheck | 718 && instruction is !HCheck |
| 717 && instruction is !HTypeGuard | 719 && instruction is !HTypeGuard; |
| 718 && !instruction.isControlFlow(); | |
| 719 } | 720 } |
| 720 | 721 |
| 721 void visitGraph(HGraph graph) { | 722 void visitGraph(HGraph graph) { |
| 722 visitPostDominatorTree(graph); | 723 visitPostDominatorTree(graph); |
| 723 } | 724 } |
| 724 | 725 |
| 725 void visitBasicBlock(HBasicBlock block) { | 726 void visitBasicBlock(HBasicBlock block) { |
| 726 HInstruction instruction = block.last; | 727 HInstruction instruction = block.last; |
| 727 while (instruction !== null) { | 728 while (instruction !== null) { |
| 728 var previous = instruction.previous; | 729 var previous = instruction.previous; |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 // the if block terminates. So any use of the instruction | 1162 // the if block terminates. So any use of the instruction |
| 1162 // after the join block should be changed to the new | 1163 // after the join block should be changed to the new |
| 1163 // instruction. | 1164 // instruction. |
| 1164 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); | 1165 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); |
| 1165 } | 1166 } |
| 1166 // TODO(ngeoffray): Also change uses for the then block on a HType | 1167 // TODO(ngeoffray): Also change uses for the then block on a HType |
| 1167 // that knows it is not of a specific Type. | 1168 // that knows it is not of a specific Type. |
| 1168 } | 1169 } |
| 1169 } | 1170 } |
| 1170 } | 1171 } |
| OLD | NEW |