| 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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 Assign assign = stmt.expression; | 370 Assign assign = stmt.expression; |
| 371 // Handle constant assignments specially. | 371 // Handle constant assignments specially. |
| 372 // They are always safe to propagate (though we should avoid duplication). | 372 // They are always safe to propagate (though we should avoid duplication). |
| 373 // Moreover, they should not prevent other expressions from propagating. | 373 // Moreover, they should not prevent other expressions from propagating. |
| 374 if (assign.variable.readCount == 1) { | 374 if (assign.variable.readCount == 1) { |
| 375 // A single-use constant should always be propagated to its use site. | 375 // A single-use constant should always be propagated to its use site. |
| 376 constantEnvironment[assign.variable] = assign.value; | 376 constantEnvironment[assign.variable] = assign.value; |
| 377 Statement next = visitStatement(stmt.next); | 377 Statement next = visitStatement(stmt.next); |
| 378 popDominatingAssignment(leftHand); | 378 popDominatingAssignment(leftHand); |
| 379 if (assign.variable.readCount > 0) { | 379 if (assign.variable.readCount > 0) { |
| 380 // The assignment could not be propagated. | 380 // The assignment could not be propagated into the successor, either |
| 381 // because it has an unsafe variable use (see [hasUnsafeVariableUse]) |
| 382 // or because the use is outside the current try block, and we do |
| 383 // not currently support constant propagation out of a try block. |
| 384 constantEnvironment.remove(assign.variable); |
| 381 assign.value = visitExpression(assign.value); | 385 assign.value = visitExpression(assign.value); |
| 382 stmt.next = next; | 386 stmt.next = next; |
| 383 return stmt; | 387 return stmt; |
| 384 } else { | 388 } else { |
| 385 --assign.variable.writeCount; | 389 --assign.variable.writeCount; |
| 386 return next; | 390 return next; |
| 387 } | 391 } |
| 388 } else { | 392 } else { |
| 389 // With more than one use, we cannot propagate the constant. | 393 // With more than one use, we cannot propagate the constant. |
| 390 // Visit the following statement without polluting [environment] so | 394 // Visit the following statement without polluting [environment] so |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 VariableUseVisitor(this.callback); | 1143 VariableUseVisitor(this.callback); |
| 1140 | 1144 |
| 1141 visitVariableUse(VariableUse use) => callback(use); | 1145 visitVariableUse(VariableUse use) => callback(use); |
| 1142 | 1146 |
| 1143 visitInnerFunction(FunctionDefinition node) {} | 1147 visitInnerFunction(FunctionDefinition node) {} |
| 1144 | 1148 |
| 1145 static void visit(Expression node, VariableUseCallback callback) { | 1149 static void visit(Expression node, VariableUseCallback callback) { |
| 1146 new VariableUseVisitor(callback).visitExpression(node); | 1150 new VariableUseVisitor(callback).visitExpression(node); |
| 1147 } | 1151 } |
| 1148 } | 1152 } |
| OLD | NEW |