| Index: pkg/compiler/lib/src/tree_ir/optimization/copy_propagator.dart
|
| diff --git a/pkg/compiler/lib/src/tree_ir/optimization/copy_propagator.dart b/pkg/compiler/lib/src/tree_ir/optimization/copy_propagator.dart
|
| index e85e16a3be7a9cfe227ee4f37e598b45b2212d31..0e3c61aa4bb0eb5b61aa9aa434e155572ac4c9b6 100644
|
| --- a/pkg/compiler/lib/src/tree_ir/optimization/copy_propagator.dart
|
| +++ b/pkg/compiler/lib/src/tree_ir/optimization/copy_propagator.dart
|
| @@ -28,9 +28,9 @@ class CopyPropagator extends RecursiveVisitor with PassMixin {
|
| root.body = visitStatement(root.body);
|
| }
|
|
|
| - rewriteFunctionDefinition(FunctionDefinition function) {
|
| - if (function.isAbstract) return;
|
| - rewriteExecutableDefinition(function);
|
| + rewriteFunctionDefinition(FunctionDefinition node) {
|
| + if (node.isAbstract) return;
|
| + rewriteExecutableDefinition(node);
|
|
|
| // Try to propagate moving assignments into function parameters.
|
| // For example:
|
| @@ -51,17 +51,55 @@ class CopyPropagator extends RecursiveVisitor with PassMixin {
|
| // BODY
|
| // }
|
| // Cannot declare function as foo(x,x)!
|
| - function.parameters.forEach(visitVariable);
|
| + node.parameters.forEach(visitVariable);
|
|
|
| // Now do the propagation.
|
| - for (int i = 0; i < function.parameters.length; i++) {
|
| - Variable param = function.parameters[i];
|
| + for (int i = 0; i < node.parameters.length; i++) {
|
| + Variable param = node.parameters[i];
|
| Variable replacement = copyPropagateVariable(param);
|
| replacement.element = param.element; // Preserve parameter name.
|
| - function.parameters[i] = replacement;
|
| + node.parameters[i] = replacement;
|
| }
|
| }
|
|
|
| + rewriteConstructorDefinition(ConstructorDefinition node) {
|
| + if (node.isAbstract) return;
|
| + node.initializers.forEach(visitExpression);
|
| + rewriteExecutableDefinition(node);
|
| +
|
| +
|
| + // Try to propagate moving assignments into function parameters.
|
| + // For example:
|
| + // foo(x) {
|
| + // var v1 = x;
|
| + // BODY
|
| + // }
|
| + // ==>
|
| + // foo(v1) {
|
| + // BODY
|
| + // }
|
| +
|
| + // Variables must not occur more than once in the parameter list, so
|
| + // invalidate all moving assignments that would propagate a parameter
|
| + // into another parameter. For example:
|
| + // foo(x,y) {
|
| + // y = x;
|
| + // BODY
|
| + // }
|
| + // Cannot declare function as foo(x,x)!
|
| + node.parameters.forEach(visitVariable);
|
| +
|
| + // Now do the propagation.
|
| + for (int i = 0; i < node.parameters.length; i++) {
|
| + Variable param = node.parameters[i];
|
| + Variable replacement = copyPropagateVariable(param);
|
| + replacement.element = param.element; // Preserve parameter name.
|
| + node.parameters[i] = replacement;
|
| + }
|
| +
|
| + }
|
| +
|
| +
|
| Statement visitBasicBlock(Statement node) {
|
| node = visitStatement(node);
|
| move.clear();
|
| @@ -190,4 +228,8 @@ class CopyPropagator extends RecursiveVisitor with PassMixin {
|
| new CopyPropagator().rewrite(node.definition);
|
| }
|
|
|
| + void visitFieldInitializer(FieldInitializer node) {
|
| + visitStatement(node.body);
|
| + }
|
| +
|
| }
|
|
|