| 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 copy_propagator; | 5 part of tree_ir.optimization; |
| 6 | |
| 7 import '../elements/elements.dart'; | |
| 8 import '../tree_ir/tree_ir_nodes.dart'; | |
| 9 | 6 |
| 10 /// Eliminates moving assignments, such as w := v, by assigning directly to w | 7 /// Eliminates moving assignments, such as w := v, by assigning directly to w |
| 11 /// at the definition of v. | 8 /// at the definition of v. |
| 12 /// | 9 /// |
| 13 /// This compensates for suboptimal register allocation, and merges closure | 10 /// This compensates for suboptimal register allocation, and merges closure |
| 14 /// variables with local temporaries that were left behind when translating | 11 /// variables with local temporaries that were left behind when translating |
| 15 /// out of CPS (where closure variables live in a separate space). | 12 /// out of CPS (where closure variables live in a separate space). |
| 16 class CopyPropagator extends RecursiveVisitor { | 13 class CopyPropagator extends RecursiveVisitor implements Pass { |
| 17 | 14 |
| 18 /// After visitStatement returns, [move] maps a variable v to an | 15 /// After visitStatement returns, [move] maps a variable v to an |
| 19 /// assignment A of form w := v, under the following conditions: | 16 /// assignment A of form w := v, under the following conditions: |
| 20 /// - there are no uses of w before A | 17 /// - there are no uses of w before A |
| 21 /// - A is the only use of v | 18 /// - A is the only use of v |
| 22 Map<Variable, Assign> move = <Variable, Assign>{}; | 19 Map<Variable, Assign> move = <Variable, Assign>{}; |
| 23 | 20 |
| 24 /// Like [move], except w is the key instead of v. | 21 /// Like [move], except w is the key instead of v. |
| 25 Map<Variable, Assign> inverseMove = <Variable, Assign>{}; | 22 Map<Variable, Assign> inverseMove = <Variable, Assign>{}; |
| 26 | 23 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 node.next = visitStatement(node.next); | 187 node.next = visitStatement(node.next); |
| 191 visitExpression(node.expression); | 188 visitExpression(node.expression); |
| 192 return node; | 189 return node; |
| 193 } | 190 } |
| 194 | 191 |
| 195 void visitFunctionExpression(FunctionExpression node) { | 192 void visitFunctionExpression(FunctionExpression node) { |
| 196 new CopyPropagator().rewrite(node.definition); | 193 new CopyPropagator().rewrite(node.definition); |
| 197 } | 194 } |
| 198 | 195 |
| 199 } | 196 } |
| OLD | NEW |