| 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 /** | 7 /** |
| 8 * Performs the following transformations on the tree: | 8 * Performs the following transformations on the tree: |
| 9 * - Assignment inlining | 9 * - Assignment inlining |
| 10 * - Assignment expression propagation | 10 * - Assignment expression propagation |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 /// Returns true if [exp] has no side effects and has a constant value within | 264 /// Returns true if [exp] has no side effects and has a constant value within |
| 265 /// any given activation of the enclosing method. | 265 /// any given activation of the enclosing method. |
| 266 bool isEffectivelyConstant(Expression exp) { | 266 bool isEffectivelyConstant(Expression exp) { |
| 267 // TODO(asgerf): Can be made more aggressive e.g. by checking conditional | 267 // TODO(asgerf): Can be made more aggressive e.g. by checking conditional |
| 268 // expressions recursively. Determine if that is a valuable optimization | 268 // expressions recursively. Determine if that is a valuable optimization |
| 269 // and/or if it is better handled at the CPS level. | 269 // and/or if it is better handled at the CPS level. |
| 270 return exp is Constant || | 270 return exp is Constant || |
| 271 exp is This || | 271 exp is This || |
| 272 exp is ReifyTypeVar || | 272 exp is ReifyTypeVar || |
| 273 exp is CreateInvocationMirror || |
| 273 exp is InvokeStatic && exp.isEffectivelyConstant || | 274 exp is InvokeStatic && exp.isEffectivelyConstant || |
| 274 exp is VariableUse && constantEnvironment.containsKey(exp.variable); | 275 exp is VariableUse && constantEnvironment.containsKey(exp.variable); |
| 275 } | 276 } |
| 276 | 277 |
| 277 /// True if [node] is an assignment that can be propagated as a constant. | 278 /// True if [node] is an assignment that can be propagated as a constant. |
| 278 bool isEffectivelyConstantAssignment(Expression node) { | 279 bool isEffectivelyConstantAssignment(Expression node) { |
| 279 return node is Assign && | 280 return node is Assign && |
| 280 node.variable.writeCount == 1 && | 281 node.variable.writeCount == 1 && |
| 281 isEffectivelyConstant(node.value); | 282 isEffectivelyConstant(node.value); |
| 282 } | 283 } |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 Expression visitReifyRuntimeType(ReifyRuntimeType node) { | 607 Expression visitReifyRuntimeType(ReifyRuntimeType node) { |
| 607 node.value = visitExpression(node.value); | 608 node.value = visitExpression(node.value); |
| 608 return node; | 609 return node; |
| 609 } | 610 } |
| 610 | 611 |
| 611 Expression visitReadTypeVariable(ReadTypeVariable node) { | 612 Expression visitReadTypeVariable(ReadTypeVariable node) { |
| 612 node.target = visitExpression(node.target); | 613 node.target = visitExpression(node.target); |
| 613 return node; | 614 return node; |
| 614 } | 615 } |
| 615 | 616 |
| 616 @override | |
| 617 Expression visitTypeExpression(TypeExpression node) { | 617 Expression visitTypeExpression(TypeExpression node) { |
| 618 for (int i = node.arguments.length - 1; i >= 0; --i) { | 618 for (int i = node.arguments.length - 1; i >= 0; --i) { |
| 619 node.arguments[i] = visitExpression(node.arguments[i]); | 619 node.arguments[i] = visitExpression(node.arguments[i]); |
| 620 } | 620 } |
| 621 return node; | 621 return node; |
| 622 } | 622 } |
| 623 | 623 |
| 624 Expression visitCreateInvocationMirror(CreateInvocationMirror node) { |
| 625 for (int i = node.arguments.length - 1; i >= 0; --i) { |
| 626 node.arguments[i] = visitExpression(node.arguments[i]); |
| 627 } |
| 628 return node; |
| 629 } |
| 630 |
| 624 /// If [s] and [t] are similar statements we extract their subexpressions | 631 /// If [s] and [t] are similar statements we extract their subexpressions |
| 625 /// and returns a new statement of the same type using expressions combined | 632 /// and returns a new statement of the same type using expressions combined |
| 626 /// with the [combine] callback. For example: | 633 /// with the [combine] callback. For example: |
| 627 /// | 634 /// |
| 628 /// combineStatements(Return E1, Return E2) = Return combine(E1, E2) | 635 /// combineStatements(Return E1, Return E2) = Return combine(E1, E2) |
| 629 /// | 636 /// |
| 630 /// If [combine] returns E1 then the unified statement is equivalent to [s], | 637 /// If [combine] returns E1 then the unified statement is equivalent to [s], |
| 631 /// and if [combine] returns E2 the unified statement is equivalence to [t]. | 638 /// and if [combine] returns E2 the unified statement is equivalence to [t]. |
| 632 /// | 639 /// |
| 633 /// It is guaranteed that no side effects occur between the beginning of the | 640 /// It is guaranteed that no side effects occur between the beginning of the |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 } | 925 } |
| 919 | 926 |
| 920 /// Result of combining two expressions that do not affect reference counting. | 927 /// Result of combining two expressions that do not affect reference counting. |
| 921 class GenericCombinedExpressions implements CombinedExpressions { | 928 class GenericCombinedExpressions implements CombinedExpressions { |
| 922 Expression combined; | 929 Expression combined; |
| 923 | 930 |
| 924 GenericCombinedExpressions(this.combined); | 931 GenericCombinedExpressions(this.combined); |
| 925 | 932 |
| 926 void uncombine() {} | 933 void uncombine() {} |
| 927 } | 934 } |
| OLD | NEW |