| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 interface OptimizationPhase { | 5 interface 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 if (!input.canBePrimitive() && !node.getter && !node.setter) { | 196 if (!input.canBePrimitive() && !node.getter && !node.setter) { |
| 197 return fromInterceptorToDynamicInvocation(node, node.name); | 197 return fromInterceptorToDynamicInvocation(node, node.name); |
| 198 } | 198 } |
| 199 | 199 |
| 200 return node; | 200 return node; |
| 201 } | 201 } |
| 202 | 202 |
| 203 HInstruction visitInvokeDynamic(HInvokeDynamic node) { | 203 HInstruction visitInvokeDynamic(HInvokeDynamic node) { |
| 204 HType receiverType = node.receiver.propagatedType; | 204 HType receiverType = node.receiver.propagatedType; |
| 205 if (receiverType.isExact()) { | 205 if (receiverType.isExact()) { |
| 206 HExactType type = receiverType; | 206 HBoundedType type = receiverType; |
| 207 Element element = type.lookupMember(node.name); | 207 Element element = type.lookupMember(node.name); |
| 208 // TODO(ngeoffray): Also fold if it's a getter or variable. | 208 // TODO(ngeoffray): Also fold if it's a getter or variable. |
| 209 if (element != null && element.isFunction()) { | 209 if (element != null && element.isFunction()) { |
| 210 if (node.selector.applies(element, compiler)) { | 210 if (node.selector.applies(element, compiler)) { |
| 211 FunctionElement method = element; | 211 FunctionElement method = element; |
| 212 FunctionSignature parameters = method.computeSignature(compiler); | 212 FunctionSignature parameters = method.computeSignature(compiler); |
| 213 if (parameters.optionalParameterCount == 0) { | 213 if (parameters.optionalParameterCount == 0) { |
| 214 node.element = element; | 214 node.element = element; |
| 215 } | 215 } |
| 216 // TODO(ngeoffray): If the method has optional parameters, | 216 // TODO(ngeoffray): If the method has optional parameters, |
| 217 // we should pass the default values here. | 217 // we should pass the default values here. |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 return node; | 221 return node; |
| 222 } | 222 } |
| 223 | 223 |
| 224 HInstruction fromInterceptorToDynamicInvocation( | 224 HInstruction fromInterceptorToDynamicInvocation( |
| 225 HInvokeStatic node, SourceString methodName) { | 225 HInvokeStatic node, SourceString methodName) { |
| 226 HBoundedType type = node.inputs[1].propagatedType; | 226 HBoundedType type = node.inputs[1].propagatedType; |
| 227 HInvokeDynamicMethod result = new HInvokeDynamicMethod( | 227 HInvokeDynamicMethod result = new HInvokeDynamicMethod( |
| 228 node.selector, | 228 node.selector, |
| 229 methodName, | 229 methodName, |
| 230 node.inputs.getRange(1, node.inputs.length - 1)); | 230 node.inputs.getRange(1, node.inputs.length - 1)); |
| 231 if (type.isExact()) { | 231 if (type.isExact()) { |
| 232 HExactType concrete = type; | 232 HBoundedType concrete = type; |
| 233 result.element = concrete.lookupMember(methodName); | 233 result.element = concrete.lookupMember(methodName); |
| 234 } | 234 } |
| 235 return result; | 235 return result; |
| 236 } | 236 } |
| 237 | 237 |
| 238 HInstruction visitBoundsCheck(HBoundsCheck node) { | 238 HInstruction visitBoundsCheck(HBoundsCheck node) { |
| 239 int tryGetIntConstantValue(HInstruction instruction, String errorMessage) { | 239 int tryGetIntConstantValue(HInstruction instruction, String errorMessage) { |
| 240 // Tests whether an [HInstruction] is a constant. | 240 // Tests whether an [HInstruction] is a constant. |
| 241 // If it is a constant, and not an int constant, it fails. | 241 // If it is a constant, and not an int constant, it fails. |
| 242 // If it's an int constant it returns the value. | 242 // If it's an int constant it returns the value. |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 | 422 |
| 423 if (node.builtin) { | 423 if (node.builtin) { |
| 424 return foldBuiltinEqualsCheck(node); | 424 return foldBuiltinEqualsCheck(node); |
| 425 } | 425 } |
| 426 | 426 |
| 427 if (left.isConstant() && right.isConstant()) { | 427 if (left.isConstant() && right.isConstant()) { |
| 428 return super.visitEquals(node); | 428 return super.visitEquals(node); |
| 429 } | 429 } |
| 430 | 430 |
| 431 if (left.propagatedType.isExact()) { | 431 if (left.propagatedType.isExact()) { |
| 432 HExactType type = left.propagatedType; | 432 HBoundedType type = left.propagatedType; |
| 433 Element element = type.lookupMember(Namer.OPERATOR_EQUALS); | 433 Element element = type.lookupMember(Namer.OPERATOR_EQUALS); |
| 434 if (element !== null) { | 434 if (element !== null) { |
| 435 // If the left-hand side is guaranteed to be a non-primitive | 435 // If the left-hand side is guaranteed to be a non-primitive |
| 436 // type and and it defines operator==, we emit a call to that | 436 // type and and it defines operator==, we emit a call to that |
| 437 // operator. | 437 // operator. |
| 438 return super.visitEquals(node); | 438 return super.visitEquals(node); |
| 439 } else if (right.isConstantNull()) { | 439 } else if (right.isConstantNull()) { |
| 440 return graph.addConstantBool(false); | 440 return graph.addConstantBool(false); |
| 441 } else { | 441 } else { |
| 442 // We can just emit an identity check because the type does | 442 // We can just emit an identity check because the type does |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 // the if block terminates. So any use of the instruction | 1117 // the if block terminates. So any use of the instruction |
| 1118 // after the join block should be changed to the new | 1118 // after the join block should be changed to the new |
| 1119 // instruction. | 1119 // instruction. |
| 1120 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); | 1120 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); |
| 1121 } | 1121 } |
| 1122 // TODO(ngeoffray): Also change uses for the then block on a HType | 1122 // TODO(ngeoffray): Also change uses for the then block on a HType |
| 1123 // that knows it is not of a specific Type. | 1123 // that knows it is not of a specific Type. |
| 1124 } | 1124 } |
| 1125 } | 1125 } |
| 1126 } | 1126 } |
| OLD | NEW |