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 import '../../io/source_information.dart'; | 9 import '../../io/source_information.dart'; |
| 10 import '../../elements/elements.dart'; | 10 import '../../elements/elements.dart'; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 Constant getRightHandConstant(Expression e) { | 246 Constant getRightHandConstant(Expression e) { |
| 247 Expression value = getValueSubexpression(e); | 247 Expression value = getValueSubexpression(e); |
| 248 return value is Constant ? value : null; | 248 return value is Constant ? value : null; |
| 249 } | 249 } |
| 250 | 250 |
| 251 /// True if the given expression (taken from [constantEnvironment]) uses a | 251 /// True if the given expression (taken from [constantEnvironment]) uses a |
| 252 /// variable that might have been reassigned since [node] was evaluated. | 252 /// variable that might have been reassigned since [node] was evaluated. |
| 253 bool hasUnsafeVariableUse(Expression node) { | 253 bool hasUnsafeVariableUse(Expression node) { |
| 254 bool wasFound = false; | 254 bool wasFound = false; |
| 255 VariableUseVisitor.visit(node, (VariableUse use) { | 255 VariableUseVisitor.visit(node, (VariableUse use) { |
| 256 if (dominatingAssignments[use.variable] == null) { | |
| 257 print('${use} ${use.variable} ${dominatingAssignments}'); | |
| 258 } | |
|
asgerf
2016/01/26 10:30:00
Debug code.
I'm guessing the this was related to
sra1
2016/01/26 22:21:08
Removed. Yes, you guessed right.
| |
| 256 if (dominatingAssignments[use.variable] > 1) { | 259 if (dominatingAssignments[use.variable] > 1) { |
| 257 wasFound = true; | 260 wasFound = true; |
| 258 } | 261 } |
| 259 }); | 262 }); |
| 260 return wasFound; | 263 return wasFound; |
| 261 } | 264 } |
| 262 | 265 |
| 263 void pushDominatingAssignment(Variable variable) { | 266 void pushDominatingAssignment(Variable variable) { |
| 264 if (variable != null) { | 267 if (variable != null) { |
| 265 dominatingAssignments.putIfAbsent(variable, () => 0); | 268 dominatingAssignments.putIfAbsent(variable, () => 0); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 /// any given activation of the enclosing method. | 368 /// any given activation of the enclosing method. |
| 366 bool isEffectivelyConstant(Expression exp) { | 369 bool isEffectivelyConstant(Expression exp) { |
| 367 // TODO(asgerf): Can be made more aggressive e.g. by checking conditional | 370 // TODO(asgerf): Can be made more aggressive e.g. by checking conditional |
| 368 // expressions recursively. Determine if that is a valuable optimization | 371 // expressions recursively. Determine if that is a valuable optimization |
| 369 // and/or if it is better handled at the CPS level. | 372 // and/or if it is better handled at the CPS level. |
| 370 return exp is Constant || | 373 return exp is Constant || |
| 371 exp is This || | 374 exp is This || |
| 372 exp is CreateInvocationMirror || | 375 exp is CreateInvocationMirror || |
| 373 exp is CreateInstance || | 376 exp is CreateInstance || |
| 374 exp is CreateBox || | 377 exp is CreateBox || |
| 378 exp is TypeExpression || | |
| 375 exp is GetStatic && exp.element.isFunction || | 379 exp is GetStatic && exp.element.isFunction || |
| 376 exp is Interceptor || | 380 exp is Interceptor || |
| 377 exp is ApplyBuiltinOperator || | 381 exp is ApplyBuiltinOperator || |
| 378 exp is VariableUse && constantEnvironment.containsKey(exp.variable); | 382 exp is VariableUse && constantEnvironment.containsKey(exp.variable); |
| 379 } | 383 } |
| 380 | 384 |
| 381 /// True if [node] is an assignment that can be propagated as a constant. | 385 /// True if [node] is an assignment that can be propagated as a constant. |
| 382 bool isEffectivelyConstantAssignment(Expression node) { | 386 bool isEffectivelyConstantAssignment(Expression node) { |
| 383 return node is Assign && | 387 return node is Assign && |
| 384 node.variable.writeCount == 1 && | 388 node.variable.writeCount == 1 && |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 816 node.object = visitExpression(node.object); | 820 node.object = visitExpression(node.object); |
| 817 return node; | 821 return node; |
| 818 } | 822 } |
| 819 | 823 |
| 820 Expression visitCreateBox(CreateBox node) { | 824 Expression visitCreateBox(CreateBox node) { |
| 821 return node; | 825 return node; |
| 822 } | 826 } |
| 823 | 827 |
| 824 Expression visitCreateInstance(CreateInstance node) { | 828 Expression visitCreateInstance(CreateInstance node) { |
| 825 _rewriteList(node.arguments); | 829 _rewriteList(node.arguments); |
| 830 if (node.typeInformation != null) { | |
| 831 node.typeInformation = visitExpression(node.typeInformation); | |
| 832 } | |
|
asgerf
2016/01/26 10:30:01
In this pass traversal of expressions is right-to-
sra1
2016/01/26 22:21:08
Done.
Interestingly, it makes no difference, perh
| |
| 826 return node; | 833 return node; |
| 827 } | 834 } |
| 828 | 835 |
| 829 Expression visitReifyRuntimeType(ReifyRuntimeType node) { | 836 Expression visitReifyRuntimeType(ReifyRuntimeType node) { |
| 830 node.value = visitExpression(node.value); | 837 node.value = visitExpression(node.value); |
| 831 return node; | 838 return node; |
| 832 } | 839 } |
| 833 | 840 |
| 834 Expression visitReadTypeVariable(ReadTypeVariable node) { | 841 Expression visitReadTypeVariable(ReadTypeVariable node) { |
| 835 node.target = visitExpression(node.target); | 842 node.target = visitExpression(node.target); |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1377 } | 1384 } |
| 1378 | 1385 |
| 1379 /// Decrement the reference count for [e] if it is a variable use. | 1386 /// Decrement the reference count for [e] if it is a variable use. |
| 1380 void destroyPrimaryExpression(Expression e) { | 1387 void destroyPrimaryExpression(Expression e) { |
| 1381 if (e is VariableUse) { | 1388 if (e is VariableUse) { |
| 1382 --e.variable.readCount; | 1389 --e.variable.readCount; |
| 1383 } else { | 1390 } else { |
| 1384 assert(e is This); | 1391 assert(e is This); |
| 1385 } | 1392 } |
| 1386 } | 1393 } |
| OLD | NEW |