Chromium Code Reviews| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 isEffectivelyConstant(node.value); | 300 isEffectivelyConstant(node.value); |
| 301 } | 301 } |
| 302 | 302 |
| 303 Statement visitExpressionStatement(ExpressionStatement stmt) { | 303 Statement visitExpressionStatement(ExpressionStatement stmt) { |
| 304 if (isEffectivelyConstantAssignment(stmt.expression) && | 304 if (isEffectivelyConstantAssignment(stmt.expression) && |
| 305 !usesRecentlyAssignedVariable(stmt.expression)) { | 305 !usesRecentlyAssignedVariable(stmt.expression)) { |
| 306 Assign assign = stmt.expression; | 306 Assign assign = stmt.expression; |
| 307 // Handle constant assignments specially. | 307 // Handle constant assignments specially. |
| 308 // They are always safe to propagate (though we should avoid duplication). | 308 // They are always safe to propagate (though we should avoid duplication). |
| 309 // Moreover, they should not prevent other expressions from propagating. | 309 // Moreover, they should not prevent other expressions from propagating. |
| 310 if (assign.variable.readCount <= 1) { | 310 if (assign.variable.readCount == 1) { |
|
asgerf
2015/06/29 14:09:12
This matters when there is a dead variable due to
| |
| 311 // A single-use constant should always be propagted to its use site. | 311 // A single-use constant should always be propagted to its use site. |
| 312 constantEnvironment[assign.variable] = assign.value; | 312 constantEnvironment[assign.variable] = assign.value; |
| 313 --assign.variable.writeCount; | 313 --assign.variable.writeCount; |
| 314 return visitStatement(stmt.next); | 314 return visitStatement(stmt.next); |
| 315 } else { | 315 } else { |
| 316 // With more than one use, we cannot propagate the constant. | 316 // With more than one use, we cannot propagate the constant. |
| 317 // Visit the following statement without polluting [environment] so | 317 // Visit the following statement without polluting [environment] so |
| 318 // that any preceding non-constant assignments might still propagate. | 318 // that any preceding non-constant assignments might still propagate. |
| 319 stmt.next = visitStatement(stmt.next); | 319 stmt.next = visitStatement(stmt.next); |
| 320 assign.value = visitExpression(assign.value); | 320 assign.value = visitExpression(assign.value); |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1039 IsVariableUsedVisitor(this.variable); | 1039 IsVariableUsedVisitor(this.variable); |
| 1040 | 1040 |
| 1041 visitVariableUse(VariableUse node) { | 1041 visitVariableUse(VariableUse node) { |
| 1042 if (node.variable == variable) { | 1042 if (node.variable == variable) { |
| 1043 wasFound = true; | 1043 wasFound = true; |
| 1044 } | 1044 } |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 visitInnerFunction(FunctionDefinition node) {} | 1047 visitInnerFunction(FunctionDefinition node) {} |
| 1048 } | 1048 } |
| OLD | NEW |