| 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 tree_ir.optimization.statement_rewriter; | 5 library tree_ir.optimization.statement_rewriter; |
| 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 /** | 10 /** |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 343 |
| 344 /// Returns true if [exp] has no side effects and has a constant value within | 344 /// Returns true if [exp] has no side effects and has a constant value within |
| 345 /// any given activation of the enclosing method. | 345 /// any given activation of the enclosing method. |
| 346 bool isEffectivelyConstant(Expression exp) { | 346 bool isEffectivelyConstant(Expression exp) { |
| 347 // TODO(asgerf): Can be made more aggressive e.g. by checking conditional | 347 // TODO(asgerf): Can be made more aggressive e.g. by checking conditional |
| 348 // expressions recursively. Determine if that is a valuable optimization | 348 // expressions recursively. Determine if that is a valuable optimization |
| 349 // and/or if it is better handled at the CPS level. | 349 // and/or if it is better handled at the CPS level. |
| 350 return exp is Constant || | 350 return exp is Constant || |
| 351 exp is This || | 351 exp is This || |
| 352 exp is CreateInvocationMirror || | 352 exp is CreateInvocationMirror || |
| 353 exp is GetStatic && exp.element.isFunction || |
| 353 exp is Interceptor || | 354 exp is Interceptor || |
| 354 exp is ApplyBuiltinOperator || | 355 exp is ApplyBuiltinOperator || |
| 355 exp is VariableUse && constantEnvironment.containsKey(exp.variable); | 356 exp is VariableUse && constantEnvironment.containsKey(exp.variable); |
| 356 } | 357 } |
| 357 | 358 |
| 358 /// True if [node] is an assignment that can be propagated as a constant. | 359 /// True if [node] is an assignment that can be propagated as a constant. |
| 359 bool isEffectivelyConstantAssignment(Expression node) { | 360 bool isEffectivelyConstantAssignment(Expression node) { |
| 360 return node is Assign && | 361 return node is Assign && |
| 361 node.variable.writeCount == 1 && | 362 node.variable.writeCount == 1 && |
| 362 isEffectivelyConstant(node.value); | 363 isEffectivelyConstant(node.value); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 Expression visitCreateInvocationMirror(CreateInvocationMirror node) { | 711 Expression visitCreateInvocationMirror(CreateInvocationMirror node) { |
| 711 _rewriteList(node.arguments); | 712 _rewriteList(node.arguments); |
| 712 return node; | 713 return node; |
| 713 } | 714 } |
| 714 | 715 |
| 715 Expression visitInterceptor(Interceptor node) { | 716 Expression visitInterceptor(Interceptor node) { |
| 716 node.input = visitExpression(node.input); | 717 node.input = visitExpression(node.input); |
| 717 return node; | 718 return node; |
| 718 } | 719 } |
| 719 | 720 |
| 721 Expression visitGetLength(GetLength node) { |
| 722 node.object = visitExpression(node.object); |
| 723 return node; |
| 724 } |
| 725 |
| 726 Expression visitGetIndex(GetIndex node) { |
| 727 node.index = visitExpression(node.index); |
| 728 node.object = visitExpression(node.object); |
| 729 return node; |
| 730 } |
| 731 |
| 732 Expression visitSetIndex(SetIndex node) { |
| 733 node.value = visitExpression(node.value); |
| 734 node.index = visitExpression(node.index); |
| 735 node.object = visitExpression(node.object); |
| 736 return node; |
| 737 } |
| 738 |
| 720 /// True if [operator] is a binary operator that always has the same value | 739 /// True if [operator] is a binary operator that always has the same value |
| 721 /// if its arguments are swapped. | 740 /// if its arguments are swapped. |
| 722 bool isSymmetricOperator(BuiltinOperator operator) { | 741 bool isSymmetricOperator(BuiltinOperator operator) { |
| 723 switch (operator) { | 742 switch (operator) { |
| 724 case BuiltinOperator.StrictEq: | 743 case BuiltinOperator.StrictEq: |
| 725 case BuiltinOperator.StrictNeq: | 744 case BuiltinOperator.StrictNeq: |
| 726 case BuiltinOperator.LooseEq: | 745 case BuiltinOperator.LooseEq: |
| 727 case BuiltinOperator.LooseNeq: | 746 case BuiltinOperator.LooseNeq: |
| 728 case BuiltinOperator.NumAnd: | 747 case BuiltinOperator.NumAnd: |
| 729 case BuiltinOperator.NumOr: | 748 case BuiltinOperator.NumOr: |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 VariableUseVisitor(this.callback); | 1162 VariableUseVisitor(this.callback); |
| 1144 | 1163 |
| 1145 visitVariableUse(VariableUse use) => callback(use); | 1164 visitVariableUse(VariableUse use) => callback(use); |
| 1146 | 1165 |
| 1147 visitInnerFunction(FunctionDefinition node) {} | 1166 visitInnerFunction(FunctionDefinition node) {} |
| 1148 | 1167 |
| 1149 static void visit(Expression node, VariableUseCallback callback) { | 1168 static void visit(Expression node, VariableUseCallback callback) { |
| 1150 new VariableUseVisitor(callback).visitExpression(node); | 1169 new VariableUseVisitor(callback).visitExpression(node); |
| 1151 } | 1170 } |
| 1152 } | 1171 } |
| OLD | NEW |