| 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 { | 15 class RedundantPhiEliminator extends RecursiveVisitor implements Pass { |
| 16 final Map<Continuation, List<InvokeContinuation>> cont2invokes = | 16 final Map<Continuation, List<InvokeContinuation>> cont2invokes = |
| 17 <Continuation, List<InvokeContinuation>>{}; | 17 <Continuation, List<InvokeContinuation>>{}; |
| 18 // For each reference r used in a continuation invocation i, stores the | 18 // For each reference r used in a continuation invocation i, stores the |
| 19 // corresponding continuation i.continuation. If required by other passes, | 19 // corresponding continuation i.continuation. If required by other passes, |
| 20 // we could consider adding parent pointers to references instead. | 20 // we could consider adding parent pointers to references instead. |
| 21 final Map<Reference, Continuation> ref2cont = <Reference, Continuation>{}; | 21 final Map<Reference, Continuation> ref2cont = <Reference, Continuation>{}; |
| 22 final Set<Continuation> workSet = new Set<Continuation>(); | 22 final Set<Continuation> workSet = new Set<Continuation>(); |
| 23 | 23 |
| 24 void rewrite(final FunctionDefinition root) { | 24 void rewrite(final FunctionDefinition root) { |
| 25 // Traverse the tree once to build the work set. | 25 // Traverse the tree once to build the work set. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 .add(node); | 125 .add(node); |
| 126 | 126 |
| 127 // And the reference map. | 127 // And the reference map. |
| 128 node.arguments.forEach((Reference ref) { | 128 node.arguments.forEach((Reference ref) { |
| 129 assert(!ref2cont.containsKey(ref)); | 129 assert(!ref2cont.containsKey(ref)); |
| 130 ref2cont[ref] = node.continuation.definition; | 130 ref2cont[ref] = node.continuation.definition; |
| 131 }); | 131 }); |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 | 134 |
| OLD | NEW |