Chromium Code Reviews| 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 while (!worklist.isEmpty()) { | 288 while (!worklist.isEmpty()) { |
| 289 HPhi phi = worklist.removeLast(); | 289 HPhi phi = worklist.removeLast(); |
| 290 for (final input in phi.inputs) { | 290 for (final input in phi.inputs) { |
| 291 if (input is HPhi && !livePhis.contains(input)) { | 291 if (input is HPhi && !livePhis.contains(input)) { |
| 292 worklist.add(input); | 292 worklist.add(input); |
| 293 livePhis.add(input); | 293 livePhis.add(input); |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 } | 296 } |
| 297 | 297 |
| 298 recursiveRemove(HPhi phi) { | |
| 299 while (!phi.usedBy.isEmpty()) { | |
| 300 recursiveRemove(phi.usedBy[0]); | |
|
floitsch
2012/02/20 19:01:54
are you sure this can't yield an infinite loop?
Lasse Reichstein Nielsen
2012/02/21 13:53:56
Not absolutely. I guess we could have recursive de
| |
| 301 } | |
| 302 phi.block.removePhi(phi); | |
| 303 } | |
| 304 | |
| 298 // Remove phis that are not live. | 305 // Remove phis that are not live. |
| 299 for (final block in graph.blocks) { | 306 for (final block in graph.blocks) { |
| 300 HPhi current = block.phis.first; | 307 HPhi current = block.phis.first; |
| 301 HPhi next = null; | 308 HPhi next = null; |
| 302 while (current != null) { | 309 while (current != null) { |
| 303 next = current.next; | 310 next = current.next; |
| 304 if (!livePhis.contains(current)) block.removePhi(current); | 311 if (!livePhis.contains(current)) { |
| 312 // Remove any (dead phi) uses of current before removing current. | |
| 313 recursiveRemove(current); | |
| 314 } | |
| 305 current = next; | 315 current = next; |
| 306 } | 316 } |
| 307 } | 317 } |
| 308 } | 318 } |
| 309 } | 319 } |
| 310 | 320 |
| 311 class SsaRedundantPhiEliminator { | 321 class SsaRedundantPhiEliminator { |
| 312 void visitGraph(HGraph graph) { | 322 void visitGraph(HGraph graph) { |
| 313 final List<HPhi> worklist = <HPhi>[]; | 323 final List<HPhi> worklist = <HPhi>[]; |
| 314 | 324 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 } | 614 } |
| 605 } | 615 } |
| 606 if (!canBeMoved) continue; | 616 if (!canBeMoved) continue; |
| 607 | 617 |
| 608 // This is safe because we are running after GVN. | 618 // This is safe because we are running after GVN. |
| 609 // TODO(ngeoffray): ensure GVN has been run. | 619 // TODO(ngeoffray): ensure GVN has been run. |
| 610 set_.add(current); | 620 set_.add(current); |
| 611 } | 621 } |
| 612 } | 622 } |
| 613 } | 623 } |
| OLD | NEW |