| 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 abstract class OptimizationPhase { | 5 abstract class OptimizationPhase { |
| 6 String get name; | 6 String get name; |
| 7 void visitGraph(HGraph graph); | 7 void visitGraph(HGraph graph); |
| 8 } | 8 } |
| 9 | 9 |
| 10 class SsaOptimizerTask extends CompilerTask { | 10 class SsaOptimizerTask extends CompilerTask { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 Constant folded = operation.fold(receiver.constant); | 196 Constant folded = operation.fold(receiver.constant); |
| 197 if (folded !== null) return graph.addConstant(folded); | 197 if (folded !== null) return graph.addConstant(folded); |
| 198 } | 198 } |
| 199 return node; | 199 return node; |
| 200 } | 200 } |
| 201 | 201 |
| 202 HInstruction visitInvokeInterceptor(HInvokeInterceptor node) { | 202 HInstruction visitInvokeInterceptor(HInvokeInterceptor node) { |
| 203 // Try to recognize the length interceptor with input [:new List(int):]. | 203 // Try to recognize the length interceptor with input [:new List(int):]. |
| 204 if (node.isLengthGetter() && node.inputs[1] is HInvokeStatic) { | 204 if (node.isLengthGetter() && node.inputs[1] is HInvokeStatic) { |
| 205 HInvokeStatic call = node.inputs[1]; | 205 HInvokeStatic call = node.inputs[1]; |
| 206 Element element = call.inputs[0].element; | 206 if (isFixedSizeListConstructor(call)) { |
| 207 if (element.isConstructor() && | 207 return call.inputs[1]; |
| 208 element.enclosingElement == compiler.listClass.defaultClass.element) { | |
| 209 if (call.inputs.length == 2 && call.inputs[1].isInteger(types)) { | |
| 210 return call.inputs[1]; | |
| 211 } | |
| 212 } | 208 } |
| 213 } | 209 } |
| 214 HInstruction input = node.inputs[1]; | 210 HInstruction input = node.inputs[1]; |
| 215 if (node.isLengthGetter()) { | 211 if (node.isLengthGetter()) { |
| 216 if (input.isConstantString()) { | 212 if (input.isConstantString()) { |
| 217 HConstant constantInput = input; | 213 HConstant constantInput = input; |
| 218 StringConstant constant = constantInput.constant; | 214 StringConstant constant = constantInput.constant; |
| 219 return graph.addConstantInt(constant.length, constantSystem); | 215 return graph.addConstantInt(constant.length, constantSystem); |
| 220 } else if (input.isConstantList()) { | 216 } else if (input.isConstantList()) { |
| 221 HConstant constantInput = input; | 217 HConstant constantInput = input; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 243 transformToDynamicInvocation = false; | 239 transformToDynamicInvocation = false; |
| 244 } | 240 } |
| 245 if (transformToDynamicInvocation) { | 241 if (transformToDynamicInvocation) { |
| 246 return fromInterceptorToDynamicInvocation(node, node.selector); | 242 return fromInterceptorToDynamicInvocation(node, node.selector); |
| 247 } | 243 } |
| 248 } | 244 } |
| 249 | 245 |
| 250 return node; | 246 return node; |
| 251 } | 247 } |
| 252 | 248 |
| 249 bool isFixedSizeListConstructor(HInvokeStatic node) { |
| 250 Element element = node.inputs[0].element; |
| 251 return element.isConstructor() |
| 252 && element.enclosingElement == compiler.listClass.defaultClass.element |
| 253 && node.inputs.length == 2 |
| 254 && node.inputs[1].isInteger(types); |
| 255 } |
| 256 |
| 257 HInstruction visitInvokeStatic(HInvokeStatic node) { |
| 258 if (isFixedSizeListConstructor(node)) { |
| 259 node.guaranteedType = HType.FIXED_ARRAY; |
| 260 } |
| 261 return node; |
| 262 } |
| 263 |
| 253 HInstruction visitInvokeDynamic(HInvokeDynamic node) { | 264 HInstruction visitInvokeDynamic(HInvokeDynamic node) { |
| 254 HType receiverType = types[node.receiver]; | 265 HType receiverType = types[node.receiver]; |
| 255 if (receiverType.isExact()) { | 266 if (receiverType.isExact()) { |
| 256 HBoundedType type = receiverType; | 267 HBoundedType type = receiverType; |
| 257 Element element = type.lookupMember(node.selector.name); | 268 Element element = type.lookupMember(node.selector.name); |
| 258 // TODO(ngeoffray): Also fold if it's a getter or variable. | 269 // TODO(ngeoffray): Also fold if it's a getter or variable. |
| 259 if (element != null && element.isFunction()) { | 270 if (element != null && element.isFunction()) { |
| 260 if (node.selector.applies(element, compiler)) { | 271 if (node.selector.applies(element, compiler)) { |
| 261 FunctionElement method = element; | 272 FunctionElement method = element; |
| 262 FunctionSignature parameters = method.computeSignature(compiler); | 273 FunctionSignature parameters = method.computeSignature(compiler); |
| (...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 } | 1336 } |
| 1326 | 1337 |
| 1327 // For other fields having setters in the generative constructor body, set | 1338 // For other fields having setters in the generative constructor body, set |
| 1328 // the type to UNKNOWN to avoid relying on the type set in the initializer | 1339 // the type to UNKNOWN to avoid relying on the type set in the initializer |
| 1329 // list. | 1340 // list. |
| 1330 allSetters.forEach((Element element) { | 1341 allSetters.forEach((Element element) { |
| 1331 backend.registerFieldConstructor(element, HType.UNKNOWN); | 1342 backend.registerFieldConstructor(element, HType.UNKNOWN); |
| 1332 }); | 1343 }); |
| 1333 } | 1344 } |
| 1334 } | 1345 } |
| OLD | NEW |