| 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 tree_ir.optimization; | 5 part of tree_ir.optimization; |
| 6 | 6 |
| 7 /// 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 |
| 8 /// at the definition of v. | 8 /// at the definition of v. |
| 9 /// | 9 /// |
| 10 /// This compensates for suboptimal register allocation, and merges closure | 10 /// This compensates for suboptimal register allocation, and merges closure |
| 11 /// variables with local temporaries that were left behind when translating | 11 /// variables with local temporaries that were left behind when translating |
| 12 /// out of CPS (where closure variables live in a separate space). | 12 /// out of CPS (where closure variables live in a separate space). |
| 13 class CopyPropagator extends RecursiveVisitor with PassMixin { | 13 class CopyPropagator extends RecursiveVisitor with PassMixin { |
| 14 String get passName => 'Copy propagation'; |
| 14 | 15 |
| 15 /// After visitStatement returns, [move] maps a variable v to an | 16 /// After visitStatement returns, [move] maps a variable v to an |
| 16 /// assignment A of form w := v, under the following conditions: | 17 /// assignment A of form w := v, under the following conditions: |
| 17 /// - there are no reads or writes of w before A | 18 /// - there are no reads or writes of w before A |
| 18 /// - A is the only use of v | 19 /// - A is the only use of v |
| 19 Map<Variable, Assign> move = <Variable, Assign>{}; | 20 Map<Variable, Assign> move = <Variable, Assign>{}; |
| 20 | 21 |
| 21 /// Like [move], except w is the key instead of v. | 22 /// Like [move], except w is the key instead of v. |
| 22 Map<Variable, Assign> inverseMove = <Variable, Assign>{}; | 23 Map<Variable, Assign> inverseMove = <Variable, Assign>{}; |
| 23 | 24 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 246 |
| 246 void visitFunctionExpression(FunctionExpression node) { | 247 void visitFunctionExpression(FunctionExpression node) { |
| 247 new CopyPropagator().rewrite(node.definition); | 248 new CopyPropagator().rewrite(node.definition); |
| 248 } | 249 } |
| 249 | 250 |
| 250 void visitFieldInitializer(FieldInitializer node) { | 251 void visitFieldInitializer(FieldInitializer node) { |
| 251 visitStatement(node.body); | 252 visitStatement(node.body); |
| 252 } | 253 } |
| 253 | 254 |
| 254 } | 255 } |
| OLD | NEW |