| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * [InvokeDynamicSpecializer] and its subclasses are helpers to | 8 * [InvokeDynamicSpecializer] and its subclasses are helpers to |
| 9 * optimize intercepted dynamic calls. It knows what input types | 9 * optimize intercepted dynamic calls. It knows what input types |
| 10 * would be beneficial for performance, and how to change a invoke | 10 * would be beneficial for performance, and how to change a invoke |
| 11 * dynamic to a builtin instruction (e.g. HIndex, HBitNot). | 11 * dynamic to a builtin instruction (e.g. HIndex, HBitNot). |
| 12 */ | 12 */ |
| 13 class InvokeDynamicSpecializer { | 13 class InvokeDynamicSpecializer { |
| 14 const InvokeDynamicSpecializer(); | 14 const InvokeDynamicSpecializer(); |
| 15 | 15 |
| 16 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, | 16 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, |
| 17 Compiler compiler) { | 17 Compiler compiler) { |
| 18 return TypeMaskFactory.inferredTypeForSelector( | 18 Selector selector = instruction.selector; |
| 19 instruction.selector, instruction.mask, compiler); | 19 return TypeMaskFactory.inferredTypeForSelector(selector, compiler); |
| 20 } | 20 } |
| 21 | 21 |
| 22 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, | 22 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, |
| 23 Compiler compiler) { | 23 Compiler compiler) { |
| 24 return null; | 24 return null; |
| 25 } | 25 } |
| 26 | 26 |
| 27 Operation operation(ConstantSystem constantSystem) => null; | 27 Operation operation(ConstantSystem constantSystem) => null; |
| 28 | 28 |
| 29 static InvokeDynamicSpecializer lookupSpecializer(Selector selector) { | 29 static InvokeDynamicSpecializer lookupSpecializer(Selector selector) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, | 106 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, |
| 107 Compiler compiler) { | 107 Compiler compiler) { |
| 108 if (!instruction.inputs[1].isIndexablePrimitive(compiler)) return null; | 108 if (!instruction.inputs[1].isIndexablePrimitive(compiler)) return null; |
| 109 if (!instruction.inputs[2].isInteger(compiler) | 109 if (!instruction.inputs[2].isInteger(compiler) |
| 110 && compiler.enableTypeAssertions) { | 110 && compiler.enableTypeAssertions) { |
| 111 // We want the right checked mode error. | 111 // We want the right checked mode error. |
| 112 return null; | 112 return null; |
| 113 } | 113 } |
| 114 TypeMask receiverType = | 114 TypeMask receiverType = |
| 115 instruction.getDartReceiver(compiler).instructionType; | 115 instruction.getDartReceiver(compiler).instructionType; |
| 116 TypeMask type = TypeMaskFactory.inferredTypeForSelector( | 116 Selector refined = new TypedSelector(receiverType, instruction.selector, |
| 117 instruction.selector, receiverType, compiler); | 117 compiler.world); |
| 118 TypeMask type = TypeMaskFactory.inferredTypeForSelector(refined, compiler); |
| 118 return new HIndex( | 119 return new HIndex( |
| 119 instruction.inputs[1], instruction.inputs[2], | 120 instruction.inputs[1], instruction.inputs[2], |
| 120 instruction.selector, type); | 121 instruction.selector, type); |
| 121 } | 122 } |
| 122 } | 123 } |
| 123 | 124 |
| 124 class BitNotSpecializer extends InvokeDynamicSpecializer { | 125 class BitNotSpecializer extends InvokeDynamicSpecializer { |
| 125 const BitNotSpecializer(); | 126 const BitNotSpecializer(); |
| 126 | 127 |
| 127 UnaryOperation operation(ConstantSystem constantSystem) { | 128 UnaryOperation operation(ConstantSystem constantSystem) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 return left.isUInt31(compiler) && right.isUInt31(compiler); | 232 return left.isUInt31(compiler) && right.isUInt31(compiler); |
| 232 } | 233 } |
| 233 | 234 |
| 234 HInstruction newBuiltinVariant(HInvokeDynamic instruction, Compiler compiler); | 235 HInstruction newBuiltinVariant(HInvokeDynamic instruction, Compiler compiler); |
| 235 | 236 |
| 236 Selector renameToOptimizedSelector(String name, | 237 Selector renameToOptimizedSelector(String name, |
| 237 Selector selector, | 238 Selector selector, |
| 238 Compiler compiler) { | 239 Compiler compiler) { |
| 239 if (selector.name == name) return selector; | 240 if (selector.name == name) return selector; |
| 240 JavaScriptBackend backend = compiler.backend; | 241 JavaScriptBackend backend = compiler.backend; |
| 241 return new Selector( | 242 Selector newSelector = new Selector( |
| 242 SelectorKind.CALL, new Name(name, backend.interceptorsLibrary), | 243 SelectorKind.CALL, new Name(name, backend.interceptorsLibrary), |
| 243 new CallStructure(selector.argumentCount)); | 244 new CallStructure(selector.argumentCount)); |
| 245 return selector.mask == null |
| 246 ? newSelector |
| 247 : new TypedSelector(selector.mask, newSelector, compiler.world); |
| 244 } | 248 } |
| 245 } | 249 } |
| 246 | 250 |
| 247 class AddSpecializer extends BinaryArithmeticSpecializer { | 251 class AddSpecializer extends BinaryArithmeticSpecializer { |
| 248 const AddSpecializer(); | 252 const AddSpecializer(); |
| 249 | 253 |
| 250 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, | 254 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, |
| 251 Compiler compiler) { | 255 Compiler compiler) { |
| 252 if (inputsAreUInt31(instruction, compiler)) { | 256 if (inputsAreUInt31(instruction, compiler)) { |
| 253 JavaScriptBackend backend = compiler.backend; | 257 JavaScriptBackend backend = compiler.backend; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 | 662 |
| 659 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, | 663 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, |
| 660 Compiler compiler) { | 664 Compiler compiler) { |
| 661 HInstruction left = instruction.inputs[1]; | 665 HInstruction left = instruction.inputs[1]; |
| 662 HInstruction right = instruction.inputs[2]; | 666 HInstruction right = instruction.inputs[2]; |
| 663 TypeMask instructionType = left.instructionType; | 667 TypeMask instructionType = left.instructionType; |
| 664 if (right.isConstantNull() || left.isPrimitiveOrNull(compiler)) { | 668 if (right.isConstantNull() || left.isPrimitiveOrNull(compiler)) { |
| 665 return newBuiltinVariant(instruction, compiler); | 669 return newBuiltinVariant(instruction, compiler); |
| 666 } | 670 } |
| 667 World world = compiler.world; | 671 World world = compiler.world; |
| 672 Selector selector = |
| 673 new TypedSelector(instructionType, instruction.selector, world); |
| 668 JavaScriptBackend backend = compiler.backend; | 674 JavaScriptBackend backend = compiler.backend; |
| 669 Iterable<Element> matches = world.allFunctions.filter( | 675 Iterable<Element> matches = world.allFunctions.filter(selector); |
| 670 instruction.selector, instructionType); | |
| 671 // This test relies the on `Object.==` and `Interceptor.==` always being | 676 // This test relies the on `Object.==` and `Interceptor.==` always being |
| 672 // implemented because if the selector matches by subtype, it still will be | 677 // implemented because if the selector matches by subtype, it still will be |
| 673 // a regular object or an interceptor. | 678 // a regular object or an interceptor. |
| 674 if (matches.every(backend.isDefaultEqualityImplementation)) { | 679 if (matches.every(backend.isDefaultEqualityImplementation)) { |
| 675 return newBuiltinVariant(instruction, compiler); | 680 return newBuiltinVariant(instruction, compiler); |
| 676 } | 681 } |
| 677 return null; | 682 return null; |
| 678 } | 683 } |
| 679 | 684 |
| 680 BinaryOperation operation(ConstantSystem constantSystem) { | 685 BinaryOperation operation(ConstantSystem constantSystem) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 return constantSystem.codeUnitAt; | 766 return constantSystem.codeUnitAt; |
| 762 } | 767 } |
| 763 | 768 |
| 764 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, | 769 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, |
| 765 Compiler compiler) { | 770 Compiler compiler) { |
| 766 // TODO(sra): Implement a builtin HCodeUnitAt instruction and the same index | 771 // TODO(sra): Implement a builtin HCodeUnitAt instruction and the same index |
| 767 // bounds checking optimizations as for HIndex. | 772 // bounds checking optimizations as for HIndex. |
| 768 return null; | 773 return null; |
| 769 } | 774 } |
| 770 } | 775 } |
| OLD | NEW |