| 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.optimizers; | 5 part of dart2js.optimizers; |
| 6 | 6 |
| 7 /// Eliminate redundant phis from the given [FunctionDefinition]. | 7 /// Eliminate redundant phis from the given [FunctionDefinition]. |
| 8 /// | 8 /// |
| 9 /// Phis in this case are [Continuations] together with corresponding | 9 /// Phis in this case are [Continuations] together with corresponding |
| 10 /// [InvokeContinuation]s. A [Continuation] parameter at position i is redundant | 10 /// [InvokeContinuation]s. A [Continuation] parameter at position i is redundant |
| 11 /// if for all [InvokeContinuation]s, the parameter at position i is identical | 11 /// if for all [InvokeContinuation]s, the parameter at position i is identical |
| 12 /// (except for feedback). Redundant parameters are removed from the | 12 /// (except for feedback). Redundant parameters are removed from the |
| 13 /// continuation signature, all invocations, and replaced within the | 13 /// continuation signature, all invocations, and replaced within the |
| 14 /// continuation body. | 14 /// continuation body. |
| 15 class RedundantPhiEliminator extends RecursiveVisitor implements Pass { | 15 class RedundantPhiEliminator extends RecursiveVisitor implements Pass { |
| 16 final Set<Continuation> workSet = new Set<Continuation>(); | 16 final Set<Continuation> workSet = new Set<Continuation>(); |
| 17 | 17 |
| 18 void rewrite(final ExecutableDefinition root) => root.applyPass(this); | 18 void rewrite(final ExecutableDefinition root) => root.applyPass(this); |
| 19 | 19 |
| 20 void rewriteFunctionDefinition(final FunctionDefinition root) { | 20 void rewriteFunctionDefinition(final FunctionDefinition root) { |
| 21 if (root.isAbstract) return; | 21 if (root.isAbstract) return; |
| 22 rewriteExecutableDefinition(root); | 22 rewriteExecutableDefinition(root); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void rewriteFieldDefinition(final FieldDefinition root) { | 25 void rewriteFieldDefinition(final FieldDefinition root) { |
| 26 if (!root.hasInitializer) return; |
| 26 rewriteExecutableDefinition(root); | 27 rewriteExecutableDefinition(root); |
| 27 } | 28 } |
| 28 | 29 |
| 29 void rewriteExecutableDefinition(final ExecutableDefinition root) { | 30 void rewriteExecutableDefinition(final ExecutableDefinition root) { |
| 30 | 31 |
| 31 // Set all parent pointers. | 32 // Set all parent pointers. |
| 32 new ParentVisitor().visit(root); | 33 new ParentVisitor().visit(root); |
| 33 | 34 |
| 34 // Traverse the tree once to build the work set. | 35 // Traverse the tree once to build the work set. |
| 35 visit(root); | 36 visit(root); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 182 |
| 182 // Insert it just below the binding of definition. | 183 // Insert it just below the binding of definition. |
| 183 InteriorNode binding = definition.parent; | 184 InteriorNode binding = definition.parent; |
| 184 | 185 |
| 185 letCont.body = binding.body; | 186 letCont.body = binding.body; |
| 186 binding.body.parent = letCont; | 187 binding.body.parent = letCont; |
| 187 | 188 |
| 188 binding.body = letCont; | 189 binding.body = letCont; |
| 189 letCont.parent = binding; | 190 letCont.parent = binding; |
| 190 } | 191 } |
| OLD | NEW |