| 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 part of dart2js.cps_ir.optimizers; | 5 library dart2js.cps_ir.redundant_phi_elimination; |
| 6 |
| 7 import 'cps_ir_nodes.dart'; |
| 8 import 'optimizers.dart'; |
| 6 | 9 |
| 7 /// Eliminate redundant phis from the given [FunctionDefinition]. | 10 /// Eliminate redundant phis from the given [FunctionDefinition]. |
| 8 /// | 11 /// |
| 9 /// Phis in this case are [Continuations] together with corresponding | 12 /// Phis in this case are [Continuations] together with corresponding |
| 10 /// [InvokeContinuation]s. A [Continuation] parameter at position i is redundant | 13 /// [InvokeContinuation]s. A [Continuation] parameter at position i is redundant |
| 11 /// 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 |
| 12 /// (except for feedback). Redundant parameters are removed from the | 15 /// (except for feedback). Redundant parameters are removed from the |
| 13 /// continuation signature, all invocations, and replaced within the | 16 /// continuation signature, all invocations, and replaced within the |
| 14 /// continuation body. | 17 /// continuation body. |
| 15 class RedundantPhiEliminator extends RecursiveVisitor implements Pass { | 18 class RedundantPhiEliminator extends RecursiveVisitor implements Pass { |
| 16 String get passName => 'Redundant phi elimination'; | 19 String get passName => 'Redundant phi elimination'; |
| 17 | 20 |
| 18 final Set<Continuation> workSet = new Set<Continuation>(); | 21 final Set<Continuation> workSet = new Set<Continuation>(); |
| 19 | 22 |
| 20 @override | 23 @override |
| 21 void rewrite(RootNode root) { | 24 void rewrite(FunctionDefinition root) { |
| 22 if (root.isEmpty) return; | |
| 23 | |
| 24 // Set all parent pointers. | 25 // Set all parent pointers. |
| 25 new ParentVisitor().visit(root); | 26 new ParentVisitor().visit(root); |
| 26 | 27 |
| 27 // Traverse the tree once to build the work set. | 28 // Traverse the tree once to build the work set. |
| 28 visit(root); | 29 visit(root); |
| 29 | 30 |
| 30 // Process each continuation one-by-one. | 31 // Process each continuation one-by-one. |
| 31 while (workSet.isNotEmpty) { | 32 while (workSet.isNotEmpty) { |
| 32 Continuation cont = workSet.first; | 33 Continuation cont = workSet.first; |
| 33 workSet.remove(cont); | 34 workSet.remove(cont); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 194 |
| 194 // Insert it just below the binding of definition. | 195 // Insert it just below the binding of definition. |
| 195 InteriorNode binding = definition.parent; | 196 InteriorNode binding = definition.parent; |
| 196 | 197 |
| 197 letCont.body = binding.body; | 198 letCont.body = binding.body; |
| 198 binding.body.parent = letCont; | 199 binding.body.parent = letCont; |
| 199 | 200 |
| 200 binding.body = letCont; | 201 binding.body = letCont; |
| 201 letCont.parent = binding; | 202 letCont.parent = binding; |
| 202 } | 203 } |
| OLD | NEW |