| 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 import '../../io/source_information.dart'; | 9 import '../../io/source_information.dart'; |
| 10 | 10 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 351 |
| 352 /// Returns true if [exp] has no side effects and has a constant value within | 352 /// Returns true if [exp] has no side effects and has a constant value within |
| 353 /// any given activation of the enclosing method. | 353 /// any given activation of the enclosing method. |
| 354 bool isEffectivelyConstant(Expression exp) { | 354 bool isEffectivelyConstant(Expression exp) { |
| 355 // TODO(asgerf): Can be made more aggressive e.g. by checking conditional | 355 // TODO(asgerf): Can be made more aggressive e.g. by checking conditional |
| 356 // expressions recursively. Determine if that is a valuable optimization | 356 // expressions recursively. Determine if that is a valuable optimization |
| 357 // and/or if it is better handled at the CPS level. | 357 // and/or if it is better handled at the CPS level. |
| 358 return exp is Constant || | 358 return exp is Constant || |
| 359 exp is This || | 359 exp is This || |
| 360 exp is CreateInvocationMirror || | 360 exp is CreateInvocationMirror || |
| 361 exp is CreateInstance || |
| 362 exp is CreateBox || |
| 361 exp is GetStatic && exp.element.isFunction || | 363 exp is GetStatic && exp.element.isFunction || |
| 362 exp is Interceptor || | 364 exp is Interceptor || |
| 363 exp is ApplyBuiltinOperator || | 365 exp is ApplyBuiltinOperator || |
| 364 exp is VariableUse && constantEnvironment.containsKey(exp.variable); | 366 exp is VariableUse && constantEnvironment.containsKey(exp.variable); |
| 365 } | 367 } |
| 366 | 368 |
| 367 /// True if [node] is an assignment that can be propagated as a constant. | 369 /// True if [node] is an assignment that can be propagated as a constant. |
| 368 bool isEffectivelyConstantAssignment(Expression node) { | 370 bool isEffectivelyConstantAssignment(Expression node) { |
| 369 return node is Assign && | 371 return node is Assign && |
| 370 node.variable.writeCount == 1 && | 372 node.variable.writeCount == 1 && |
| (...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1225 VariableUseVisitor(this.callback); | 1227 VariableUseVisitor(this.callback); |
| 1226 | 1228 |
| 1227 visitVariableUse(VariableUse use) => callback(use); | 1229 visitVariableUse(VariableUse use) => callback(use); |
| 1228 | 1230 |
| 1229 visitInnerFunction(FunctionDefinition node) {} | 1231 visitInnerFunction(FunctionDefinition node) {} |
| 1230 | 1232 |
| 1231 static void visit(Expression node, VariableUseCallback callback) { | 1233 static void visit(Expression node, VariableUseCallback callback) { |
| 1232 new VariableUseVisitor(callback).visitExpression(node); | 1234 new VariableUseVisitor(callback).visitExpression(node); |
| 1233 } | 1235 } |
| 1234 } | 1236 } |
| OLD | NEW |