| OLD | NEW |
| 1 // Copyright (c) 2011, 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 class SsaOptimizerTask extends CompilerTask { | 5 class SsaOptimizerTask extends CompilerTask { |
| 6 SsaOptimizerTask(Compiler compiler) : super(compiler); | 6 SsaOptimizerTask(Compiler compiler) : super(compiler); |
| 7 String get name() => 'SSA optimizer'; | 7 String get name() => 'SSA optimizer'; |
| 8 | 8 |
| 9 void optimize(WorkItem work, HGraph graph) { | 9 void optimize(WorkItem work, HGraph graph) { |
| 10 measure(() { | 10 measure(() { |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 node.block.remove(node); | 239 node.block.remove(node); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 | 242 |
| 243 class SsaDeadCodeEliminator extends HGraphVisitor { | 243 class SsaDeadCodeEliminator extends HGraphVisitor { |
| 244 static bool isDeadCode(HInstruction instruction) { | 244 static bool isDeadCode(HInstruction instruction) { |
| 245 // TODO(ngeoffray): the way we handle side effects is not right | 245 // TODO(ngeoffray): the way we handle side effects is not right |
| 246 // (e.g. branching instructions have side effects). | 246 // (e.g. branching instructions have side effects). |
| 247 return !instruction.hasSideEffects() | 247 return !instruction.hasSideEffects() |
| 248 && instruction.usedBy.isEmpty() | 248 && instruction.usedBy.isEmpty() |
| 249 && instruction is !HCheck; | 249 && instruction is !HCheck |
| 250 && instruction is !HTypeGuard; |
| 250 } | 251 } |
| 251 | 252 |
| 252 void visitGraph(HGraph graph) { | 253 void visitGraph(HGraph graph) { |
| 253 visitPostDominatorTree(graph); | 254 visitPostDominatorTree(graph); |
| 254 } | 255 } |
| 255 | 256 |
| 256 void visitBasicBlock(HBasicBlock block) { | 257 void visitBasicBlock(HBasicBlock block) { |
| 257 HInstruction instruction = block.last; | 258 HInstruction instruction = block.last; |
| 258 while (instruction !== null) { | 259 while (instruction !== null) { |
| 259 var previous = instruction.previous; | 260 var previous = instruction.previous; |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 } | 612 } |
| 612 } | 613 } |
| 613 if (!canBeMoved) continue; | 614 if (!canBeMoved) continue; |
| 614 | 615 |
| 615 // This is safe because we are running after GVN. | 616 // This is safe because we are running after GVN. |
| 616 // TODO(ngeoffray): ensure GVN has been run. | 617 // TODO(ngeoffray): ensure GVN has been run. |
| 617 set_.add(current); | 618 set_.add(current); |
| 618 } | 619 } |
| 619 } | 620 } |
| 620 } | 621 } |
| OLD | NEW |