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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 // Handle constant assignments specially. | 372 // Handle constant assignments specially. |
| 373 // They are always safe to propagate (though we should avoid duplication). | 373 // They are always safe to propagate (though we should avoid duplication). |
| 374 // Moreover, they should not prevent other expressions from propagating. | 374 // Moreover, they should not prevent other expressions from propagating. |
| 375 if (assign.variable.readCount == 1) { | 375 if (assign.variable.readCount == 1) { |
| 376 // A single-use constant should always be propagated to its use site. | 376 // A single-use constant should always be propagated to its use site. |
| 377 constantEnvironment[assign.variable] = assign.value; | 377 constantEnvironment[assign.variable] = assign.value; |
| 378 Statement next = visitStatement(stmt.next); | 378 Statement next = visitStatement(stmt.next); |
| 379 popDominatingAssignment(leftHand); | 379 popDominatingAssignment(leftHand); |
| 380 if (assign.variable.readCount > 0) { | 380 if (assign.variable.readCount > 0) { |
| 381 // The assignment could not be propagated. | 381 // The assignment could not be propagated. |
| 382 constantEnvironment.remove(assign.variable); | |
|
asgerf
2015/07/02 14:55:01
This matters for variables that have a single use
floitsch
2015/07/02 16:01:24
Can you put this as a comment?
asgerf
2015/07/02 16:09:45
Done.
| |
| 382 assign.value = visitExpression(assign.value); | 383 assign.value = visitExpression(assign.value); |
| 383 stmt.next = next; | 384 stmt.next = next; |
| 384 return stmt; | 385 return stmt; |
| 385 } else { | 386 } else { |
| 386 --assign.variable.writeCount; | 387 --assign.variable.writeCount; |
| 387 return next; | 388 return next; |
| 388 } | 389 } |
| 389 } else { | 390 } else { |
| 390 // With more than one use, we cannot propagate the constant. | 391 // With more than one use, we cannot propagate the constant. |
| 391 // Visit the following statement without polluting [environment] so | 392 // Visit the following statement without polluting [environment] so |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1140 VariableUseVisitor(this.callback); | 1141 VariableUseVisitor(this.callback); |
| 1141 | 1142 |
| 1142 visitVariableUse(VariableUse use) => callback(use); | 1143 visitVariableUse(VariableUse use) => callback(use); |
| 1143 | 1144 |
| 1144 visitInnerFunction(FunctionDefinition node) {} | 1145 visitInnerFunction(FunctionDefinition node) {} |
| 1145 | 1146 |
| 1146 static void visit(Expression node, VariableUseCallback callback) { | 1147 static void visit(Expression node, VariableUseCallback callback) { |
| 1147 new VariableUseVisitor(callback).visitExpression(node); | 1148 new VariableUseVisitor(callback).visitExpression(node); |
| 1148 } | 1149 } |
| 1149 } | 1150 } |
| OLD | NEW |