| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Traverse in reverse order to remove phis with no uses before the | 298 // Traverse in reverse order to remove phis with no uses before the |
| 299 // phis that they might use. | 299 // phis that they might use. |
| 300 // TODO(lrn): Handle cyclic usages. | 300 // NOTICE: Doesn't handle circular references, but we don't currently |
| 301 // create any. |
| 301 List<HBasicBlock> blocks = graph.blocks; | 302 List<HBasicBlock> blocks = graph.blocks; |
| 302 for (int i = blocks.length - 1; i >= 0; i--) { | 303 for (int i = blocks.length - 1; i >= 0; i--) { |
| 303 HBasicBlock block = blocks[i]; | 304 HBasicBlock block = blocks[i]; |
| 304 HPhi current = block.phis.first; | 305 HPhi current = block.phis.first; |
| 305 HPhi next = null; | 306 HPhi next = null; |
| 306 while (current != null) { | 307 while (current != null) { |
| 307 next = current.next; | 308 next = current.next; |
| 308 if (!livePhis.contains(current)) { | 309 if (!livePhis.contains(current)) { |
| 309 current.block.removePhi(current); | 310 block.removePhi(current); |
| 310 } | 311 } |
| 311 current = next; | 312 current = next; |
| 312 } | 313 } |
| 313 } | 314 } |
| 314 } | 315 } |
| 315 } | 316 } |
| 316 | 317 |
| 317 class SsaRedundantPhiEliminator { | 318 class SsaRedundantPhiEliminator { |
| 318 void visitGraph(HGraph graph) { | 319 void visitGraph(HGraph graph) { |
| 319 final List<HPhi> worklist = <HPhi>[]; | 320 final List<HPhi> worklist = <HPhi>[]; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 } | 611 } |
| 611 } | 612 } |
| 612 if (!canBeMoved) continue; | 613 if (!canBeMoved) continue; |
| 613 | 614 |
| 614 // This is safe because we are running after GVN. | 615 // This is safe because we are running after GVN. |
| 615 // TODO(ngeoffray): ensure GVN has been run. | 616 // TODO(ngeoffray): ensure GVN has been run. |
| 616 set_.add(current); | 617 set_.add(current); |
| 617 } | 618 } |
| 618 } | 619 } |
| 619 } | 620 } |
| OLD | NEW |