| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart2js.cps_ir.redundant_phi_elimination; | 5 library dart2js.cps_ir.redundant_phi_elimination; |
| 6 | 6 |
| 7 import 'cps_ir_nodes.dart'; | 7 import 'cps_ir_nodes.dart'; |
| 8 import 'optimizers.dart'; | 8 import 'optimizers.dart'; |
| 9 | 9 |
| 10 /// Eliminate redundant phis from the given [FunctionDefinition]. | 10 /// Eliminate redundant phis from the given [FunctionDefinition]. |
| 11 /// | 11 /// |
| 12 /// Phis in this case are [Continuations] together with corresponding | 12 /// Phis in this case are [Continuations] together with corresponding |
| 13 /// [InvokeContinuation]s. A [Continuation] parameter at position i is redundant | 13 /// [InvokeContinuation]s. A [Continuation] parameter at position i is redundant |
| 14 /// if for all [InvokeContinuation]s, the parameter at position i is identical | 14 /// if for all [InvokeContinuation]s, the parameter at position i is identical |
| 15 /// (except for feedback). Redundant parameters are removed from the | 15 /// (except for feedback). Redundant parameters are removed from the |
| 16 /// continuation signature, all invocations, and replaced within the | 16 /// continuation signature, all invocations, and replaced within the |
| 17 /// continuation body. | 17 /// continuation body. |
| 18 class RedundantPhiEliminator extends RecursiveVisitor implements Pass { | 18 class RedundantPhiEliminator extends TrampolineRecursiveVisitor implements Pass
{ |
| 19 String get passName => 'Redundant phi elimination'; | 19 String get passName => 'Redundant phi elimination'; |
| 20 | 20 |
| 21 final Set<Continuation> workSet = new Set<Continuation>(); | 21 final Set<Continuation> workSet = new Set<Continuation>(); |
| 22 | 22 |
| 23 @override | 23 @override |
| 24 void rewrite(FunctionDefinition root) { | 24 void rewrite(FunctionDefinition root) { |
| 25 // Set all parent pointers. | |
| 26 new ParentVisitor().visit(root); | |
| 27 | |
| 28 // Traverse the tree once to build the work set. | 25 // Traverse the tree once to build the work set. |
| 29 visit(root); | 26 visit(root); |
| 30 | 27 |
| 31 // Process each continuation one-by-one. | 28 // Process each continuation one-by-one. |
| 32 while (workSet.isNotEmpty) { | 29 while (workSet.isNotEmpty) { |
| 33 Continuation cont = workSet.first; | 30 Continuation cont = workSet.first; |
| 34 workSet.remove(cont); | 31 workSet.remove(cont); |
| 35 | 32 |
| 36 if (cont.isReturnContinuation) { | 33 if (cont.isReturnContinuation) { |
| 37 continue; // Skip function return continuations. | 34 continue; // Skip function return continuations. |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 /// Returns the LetCont that now binds [continuation]. | 195 /// Returns the LetCont that now binds [continuation]. |
| 199 LetCont _makeUniqueBinding(Continuation continuation) { | 196 LetCont _makeUniqueBinding(Continuation continuation) { |
| 200 LetCont letCont = continuation.parent; | 197 LetCont letCont = continuation.parent; |
| 201 if (letCont.continuations.length == 1) return letCont; | 198 if (letCont.continuations.length == 1) return letCont; |
| 202 letCont.continuations.remove(continuation); | 199 letCont.continuations.remove(continuation); |
| 203 LetCont newBinding = new LetCont(continuation, null); | 200 LetCont newBinding = new LetCont(continuation, null); |
| 204 continuation.parent = newBinding; | 201 continuation.parent = newBinding; |
| 205 newBinding.insertBelow(letCont); | 202 newBinding.insertBelow(letCont); |
| 206 return newBinding; | 203 return newBinding; |
| 207 } | 204 } |
| OLD | NEW |