| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 tree_ir.optimization.variable_merger; | 5 library tree_ir.optimization.variable_merger; |
| 6 | 6 |
| 7 import 'optimization.dart' show Pass; | 7 import 'optimization.dart' show Pass; |
| 8 import '../tree_ir_nodes.dart'; | 8 import '../tree_ir_nodes.dart'; |
| 9 | 9 |
| 10 /// Merges variables based on liveness and source variable information. | 10 /// Merges variables based on liveness and source variable information. |
| 11 /// | 11 /// |
| 12 /// This phase cleans up artifacts introduced by the translation through CPS, | 12 /// This phase cleans up artifacts introduced by the translation through CPS, |
| 13 /// where each source variable is translated into several copies. The copies | 13 /// where each source variable is translated into several copies. The copies |
| 14 /// are merged again when they are not live simultaneously. | 14 /// are merged again when they are not live simultaneously. |
| 15 class VariableMerger extends RecursiveVisitor implements Pass { | 15 class VariableMerger implements Pass { |
| 16 String get passName => 'Variable merger'; | 16 String get passName => 'Variable merger'; |
| 17 | 17 |
| 18 void rewrite(FunctionDefinition node) { | 18 void rewrite(FunctionDefinition node) { |
| 19 rewriteFunction(node); | |
| 20 visitStatement(node.body); | |
| 21 } | |
| 22 | |
| 23 /// Rewrites the given function. | |
| 24 /// This is called for the outermost function and inner functions. | |
| 25 void rewriteFunction(FunctionDefinition node) { | |
| 26 BlockGraphBuilder builder = new BlockGraphBuilder(); | 19 BlockGraphBuilder builder = new BlockGraphBuilder(); |
| 27 builder.build(node); | 20 builder.build(node); |
| 28 _computeLiveness(builder.blocks); | 21 _computeLiveness(builder.blocks); |
| 29 Map<Variable, Variable> subst = | 22 Map<Variable, Variable> subst = |
| 30 _computeRegisterAllocation(builder.blocks, node.parameters); | 23 _computeRegisterAllocation(builder.blocks, node.parameters); |
| 31 new SubstituteVariables(subst).apply(node); | 24 new SubstituteVariables(subst).apply(node); |
| 32 } | 25 } |
| 33 } | 26 } |
| 34 | 27 |
| 35 /// A read or write access to a variable. | 28 /// A read or write access to a variable. |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 node.expression = visitExpression(node.expression); | 514 node.expression = visitExpression(node.expression); |
| 522 node.next = visitStatement(node.next); | 515 node.next = visitStatement(node.next); |
| 523 if (node.expression is VariableUse) { | 516 if (node.expression is VariableUse) { |
| 524 VariableUse use = node.expression; | 517 VariableUse use = node.expression; |
| 525 --use.variable.readCount; | 518 --use.variable.readCount; |
| 526 return node.next; | 519 return node.next; |
| 527 } | 520 } |
| 528 return node; | 521 return node; |
| 529 } | 522 } |
| 530 } | 523 } |
| OLD | NEW |