OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import '../common/codegen.dart' show CodegenWorkItem; | 5 import '../common/codegen.dart' show CodegenWorkItem; |
6 import '../common/tasks.dart' show CompilerTask; | 6 import '../common/tasks.dart' show CompilerTask; |
7 import '../compiler.dart' show Compiler; | 7 import '../compiler.dart' show Compiler; |
8 import '../constants/constant_system.dart'; | 8 import '../constants/constant_system.dart'; |
9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
10 import '../core_types.dart' show CoreClasses; | 10 import '../core_types.dart' show CoreClasses; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 ConstantValue value = getConstantFromType(node); | 240 ConstantValue value = getConstantFromType(node); |
241 if (value != null) { | 241 if (value != null) { |
242 HConstant constant = graph.addConstant(value, compiler); | 242 HConstant constant = graph.addConstant(value, compiler); |
243 for (HInstruction user in node.usedBy.toList()) { | 243 for (HInstruction user in node.usedBy.toList()) { |
244 user.changeUse(node, constant); | 244 user.changeUse(node, constant); |
245 } | 245 } |
246 } | 246 } |
247 } | 247 } |
248 | 248 |
249 HInstruction visitParameterValue(HParameterValue node) { | 249 HInstruction visitParameterValue(HParameterValue node) { |
250 // HParameterValue is either the parameter value, or the local variable | 250 // It is possible for the parameter value to be assigned to in the function |
251 // containing the parameter value. If the parameter is used as a mutable | 251 // body. If that happens then we should not forward the constant value to |
252 // variable we cannot replace the variable with a value. | 252 // its uses since since the uses reachable from the assignment may have |
253 bool userIsLocalAccess(HInstruction user) { | 253 // values in addition to the constant passed to the function. |
254 return user is HLocalGet || (user is HLocalSet && user.local == node); | 254 if (node.usedBy |
| 255 .any((user) => user is HLocalSet && identical(user.local, node))) { |
| 256 return node; |
255 } | 257 } |
256 if (node.usedBy.any(userIsLocalAccess)) return node; | |
257 propagateConstantValueToUses(node); | 258 propagateConstantValueToUses(node); |
258 return node; | 259 return node; |
259 } | 260 } |
260 | 261 |
261 HInstruction visitBoolify(HBoolify node) { | 262 HInstruction visitBoolify(HBoolify node) { |
262 List<HInstruction> inputs = node.inputs; | 263 List<HInstruction> inputs = node.inputs; |
263 assert(inputs.length == 1); | 264 assert(inputs.length == 1); |
264 HInstruction input = inputs[0]; | 265 HInstruction input = inputs[0]; |
265 if (input.isBoolean(compiler)) return input; | 266 if (input.isBoolean(compiler)) return input; |
266 | 267 |
(...skipping 2116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2383 | 2384 |
2384 keyedValues.forEach((receiver, values) { | 2385 keyedValues.forEach((receiver, values) { |
2385 result.keyedValues[receiver] = | 2386 result.keyedValues[receiver] = |
2386 new Map<HInstruction, HInstruction>.from(values); | 2387 new Map<HInstruction, HInstruction>.from(values); |
2387 }); | 2388 }); |
2388 | 2389 |
2389 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2390 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
2390 return result; | 2391 return result; |
2391 } | 2392 } |
2392 } | 2393 } |
OLD | NEW |