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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 /// Returns true if [exp] has no side effects and has a constant value within | 281 /// Returns true if [exp] has no side effects and has a constant value within |
282 /// any given activation of the enclosing method. | 282 /// any given activation of the enclosing method. |
283 bool isEffectivelyConstant(Expression exp) { | 283 bool isEffectivelyConstant(Expression exp) { |
284 // TODO(asgerf): Can be made more aggressive e.g. by checking conditional | 284 // TODO(asgerf): Can be made more aggressive e.g. by checking conditional |
285 // expressions recursively. Determine if that is a valuable optimization | 285 // expressions recursively. Determine if that is a valuable optimization |
286 // and/or if it is better handled at the CPS level. | 286 // and/or if it is better handled at the CPS level. |
287 return exp is Constant || | 287 return exp is Constant || |
288 exp is This || | 288 exp is This || |
289 exp is CreateInvocationMirror || | 289 exp is CreateInvocationMirror || |
290 exp is InvokeStatic && exp.isEffectivelyConstant || | 290 exp is InvokeStatic && exp.isEffectivelyConstant || |
| 291 exp is Interceptor || |
291 exp is ApplyBuiltinOperator || | 292 exp is ApplyBuiltinOperator || |
292 exp is VariableUse && constantEnvironment.containsKey(exp.variable); | 293 exp is VariableUse && constantEnvironment.containsKey(exp.variable); |
293 } | 294 } |
294 | 295 |
295 /// True if [node] is an assignment that can be propagated as a constant. | 296 /// True if [node] is an assignment that can be propagated as a constant. |
296 bool isEffectivelyConstantAssignment(Expression node) { | 297 bool isEffectivelyConstantAssignment(Expression node) { |
297 return node is Assign && | 298 return node is Assign && |
298 node.variable.writeCount == 1 && | 299 node.variable.writeCount == 1 && |
299 isEffectivelyConstant(node.value); | 300 isEffectivelyConstant(node.value); |
300 } | 301 } |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 Expression visitTypeExpression(TypeExpression node) { | 624 Expression visitTypeExpression(TypeExpression node) { |
624 _rewriteList(node.arguments); | 625 _rewriteList(node.arguments); |
625 return node; | 626 return node; |
626 } | 627 } |
627 | 628 |
628 Expression visitCreateInvocationMirror(CreateInvocationMirror node) { | 629 Expression visitCreateInvocationMirror(CreateInvocationMirror node) { |
629 _rewriteList(node.arguments); | 630 _rewriteList(node.arguments); |
630 return node; | 631 return node; |
631 } | 632 } |
632 | 633 |
| 634 Expression visitInterceptor(Interceptor node) { |
| 635 node.input = visitExpression(node.input); |
| 636 return node; |
| 637 } |
| 638 |
633 /// True if [operator] is a binary operator that always has the same value | 639 /// True if [operator] is a binary operator that always has the same value |
634 /// if its arguments are swapped. | 640 /// if its arguments are swapped. |
635 bool isSymmetricOperator(BuiltinOperator operator) { | 641 bool isSymmetricOperator(BuiltinOperator operator) { |
636 switch (operator) { | 642 switch (operator) { |
637 case BuiltinOperator.StrictEq: | 643 case BuiltinOperator.StrictEq: |
638 case BuiltinOperator.StrictNeq: | 644 case BuiltinOperator.StrictNeq: |
639 case BuiltinOperator.LooseEq: | 645 case BuiltinOperator.LooseEq: |
640 case BuiltinOperator.LooseNeq: | 646 case BuiltinOperator.LooseNeq: |
641 case BuiltinOperator.NumAnd: | 647 case BuiltinOperator.NumAnd: |
642 case BuiltinOperator.NumOr: | 648 case BuiltinOperator.NumOr: |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 IsVariableUsedVisitor(this.variable); | 1039 IsVariableUsedVisitor(this.variable); |
1034 | 1040 |
1035 visitVariableUse(VariableUse node) { | 1041 visitVariableUse(VariableUse node) { |
1036 if (node.variable == variable) { | 1042 if (node.variable == variable) { |
1037 wasFound = true; | 1043 wasFound = true; |
1038 } | 1044 } |
1039 } | 1045 } |
1040 | 1046 |
1041 visitInnerFunction(FunctionDefinition node) {} | 1047 visitInnerFunction(FunctionDefinition node) {} |
1042 } | 1048 } |
OLD | NEW |