| 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 HPhi phi = worklist.removeLast(); | 288 HPhi phi = worklist.removeLast(); |
| 289 for (final input in phi.inputs) { | 289 for (final input in phi.inputs) { |
| 290 if (input is HPhi && !livePhis.contains(input)) { | 290 if (input is HPhi && !livePhis.contains(input)) { |
| 291 worklist.add(input); | 291 worklist.add(input); |
| 292 livePhis.add(input); | 292 livePhis.add(input); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 | 296 |
| 297 // Remove phis that are not live. | 297 // Remove phis that are not live. |
| 298 for (final block in graph.blocks) { | 298 // Traverse in reverse order to remove phis with no uses before the |
| 299 // phis that they might use. |
| 300 // TODO(lrn): Handle cyclic usages. |
| 301 List<HBasicBlock> blocks = graph.blocks; |
| 302 for (int i = blocks.length - 1; i >= 0; i--) { |
| 303 HBasicBlock block = blocks[i]; |
| 299 HPhi current = block.phis.first; | 304 HPhi current = block.phis.first; |
| 300 HPhi next = null; | 305 HPhi next = null; |
| 301 while (current != null) { | 306 while (current != null) { |
| 302 next = current.next; | 307 next = current.next; |
| 303 if (!livePhis.contains(current)) block.removePhi(current); | 308 if (!livePhis.contains(current)) { |
| 309 current.block.removePhi(current); |
| 310 } |
| 304 current = next; | 311 current = next; |
| 305 } | 312 } |
| 306 } | 313 } |
| 307 } | 314 } |
| 308 } | 315 } |
| 309 | 316 |
| 310 class SsaRedundantPhiEliminator { | 317 class SsaRedundantPhiEliminator { |
| 311 void visitGraph(HGraph graph) { | 318 void visitGraph(HGraph graph) { |
| 312 final List<HPhi> worklist = <HPhi>[]; | 319 final List<HPhi> worklist = <HPhi>[]; |
| 313 | 320 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 } | 610 } |
| 604 } | 611 } |
| 605 if (!canBeMoved) continue; | 612 if (!canBeMoved) continue; |
| 606 | 613 |
| 607 // This is safe because we are running after GVN. | 614 // This is safe because we are running after GVN. |
| 608 // TODO(ngeoffray): ensure GVN has been run. | 615 // TODO(ngeoffray): ensure GVN has been run. |
| 609 set_.add(current); | 616 set_.add(current); |
| 610 } | 617 } |
| 611 } | 618 } |
| 612 } | 619 } |
| OLD | NEW |