| OLD | NEW |
| 1 // Copyright (c) 2011, 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 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). | |
| 716 return !instruction.hasSideEffects() | 714 return !instruction.hasSideEffects() |
| 717 && instruction.usedBy.isEmpty() | 715 && instruction.usedBy.isEmpty() |
| 718 && instruction is !HCheck | 716 && instruction is !HCheck |
| 719 && instruction is !HTypeGuard; | 717 && instruction is !HTypeGuard |
| 718 && !instruction.isControlFlow(); |
| 720 } | 719 } |
| 721 | 720 |
| 722 void visitGraph(HGraph graph) { | 721 void visitGraph(HGraph graph) { |
| 723 visitPostDominatorTree(graph); | 722 visitPostDominatorTree(graph); |
| 724 } | 723 } |
| 725 | 724 |
| 726 void visitBasicBlock(HBasicBlock block) { | 725 void visitBasicBlock(HBasicBlock block) { |
| 727 HInstruction instruction = block.last; | 726 HInstruction instruction = block.last; |
| 728 while (instruction !== null) { | 727 while (instruction !== null) { |
| 729 var previous = instruction.previous; | 728 var previous = instruction.previous; |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1162 // the if block terminates. So any use of the instruction | 1161 // the if block terminates. So any use of the instruction |
| 1163 // after the join block should be changed to the new | 1162 // after the join block should be changed to the new |
| 1164 // instruction. | 1163 // instruction. |
| 1165 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); | 1164 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); |
| 1166 } | 1165 } |
| 1167 // TODO(ngeoffray): Also change uses for the then block on a HType | 1166 // TODO(ngeoffray): Also change uses for the then block on a HType |
| 1168 // that knows it is not of a specific Type. | 1167 // that knows it is not of a specific Type. |
| 1169 } | 1168 } |
| 1170 } | 1169 } |
| 1171 } | 1170 } |
| OLD | NEW |