| 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 Selector selector = instruction.selector; | 18 return TypeMaskFactory.inferredTypeForSelector( |
| 19 return TypeMaskFactory.inferredTypeForSelector(selector, compiler); | 19 instruction.selector, instruction.mask, 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 Selector refined = new TypedSelector(receiverType, instruction.selector, | 116 TypeMask type = TypeMaskFactory.inferredTypeForSelector( |
| 117 compiler.world); | 117 instruction.selector, receiverType, compiler); |
| 118 TypeMask type = TypeMaskFactory.inferredTypeForSelector(refined, compiler); | |
| 119 return new HIndex( | 118 return new HIndex( |
| 120 instruction.inputs[1], instruction.inputs[2], | 119 instruction.inputs[1], instruction.inputs[2], |
| 121 instruction.selector, type); | 120 instruction.selector, type); |
| 122 } | 121 } |
| 123 } | 122 } |
| 124 | 123 |
| 125 class BitNotSpecializer extends InvokeDynamicSpecializer { | 124 class BitNotSpecializer extends InvokeDynamicSpecializer { |
| 126 const BitNotSpecializer(); | 125 const BitNotSpecializer(); |
| 127 | 126 |
| 128 UnaryOperation operation(ConstantSystem constantSystem) { | 127 UnaryOperation operation(ConstantSystem constantSystem) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 return left.isUInt31(compiler) && right.isUInt31(compiler); | 231 return left.isUInt31(compiler) && right.isUInt31(compiler); |
| 233 } | 232 } |
| 234 | 233 |
| 235 HInstruction newBuiltinVariant(HInvokeDynamic instruction, Compiler compiler); | 234 HInstruction newBuiltinVariant(HInvokeDynamic instruction, Compiler compiler); |
| 236 | 235 |
| 237 Selector renameToOptimizedSelector(String name, | 236 Selector renameToOptimizedSelector(String name, |
| 238 Selector selector, | 237 Selector selector, |
| 239 Compiler compiler) { | 238 Compiler compiler) { |
| 240 if (selector.name == name) return selector; | 239 if (selector.name == name) return selector; |
| 241 JavaScriptBackend backend = compiler.backend; | 240 JavaScriptBackend backend = compiler.backend; |
| 242 Selector newSelector = new Selector( | 241 return new Selector( |
| 243 SelectorKind.CALL, new Name(name, backend.interceptorsLibrary), | 242 SelectorKind.CALL, new Name(name, backend.interceptorsLibrary), |
| 244 new CallStructure(selector.argumentCount)); | 243 new CallStructure(selector.argumentCount)); |
| 245 return selector.mask == null | |
| 246 ? newSelector | |
| 247 : new TypedSelector(selector.mask, newSelector, compiler.world); | |
| 248 } | 244 } |
| 249 } | 245 } |
| 250 | 246 |
| 251 class AddSpecializer extends BinaryArithmeticSpecializer { | 247 class AddSpecializer extends BinaryArithmeticSpecializer { |
| 252 const AddSpecializer(); | 248 const AddSpecializer(); |
| 253 | 249 |
| 254 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, | 250 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, |
| 255 Compiler compiler) { | 251 Compiler compiler) { |
| 256 if (inputsAreUInt31(instruction, compiler)) { | 252 if (inputsAreUInt31(instruction, compiler)) { |
| 257 JavaScriptBackend backend = compiler.backend; | 253 JavaScriptBackend backend = compiler.backend; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 | 658 |
| 663 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, | 659 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, |
| 664 Compiler compiler) { | 660 Compiler compiler) { |
| 665 HInstruction left = instruction.inputs[1]; | 661 HInstruction left = instruction.inputs[1]; |
| 666 HInstruction right = instruction.inputs[2]; | 662 HInstruction right = instruction.inputs[2]; |
| 667 TypeMask instructionType = left.instructionType; | 663 TypeMask instructionType = left.instructionType; |
| 668 if (right.isConstantNull() || left.isPrimitiveOrNull(compiler)) { | 664 if (right.isConstantNull() || left.isPrimitiveOrNull(compiler)) { |
| 669 return newBuiltinVariant(instruction, compiler); | 665 return newBuiltinVariant(instruction, compiler); |
| 670 } | 666 } |
| 671 World world = compiler.world; | 667 World world = compiler.world; |
| 672 Selector selector = | |
| 673 new TypedSelector(instructionType, instruction.selector, world); | |
| 674 JavaScriptBackend backend = compiler.backend; | 668 JavaScriptBackend backend = compiler.backend; |
| 675 Iterable<Element> matches = world.allFunctions.filter(selector); | 669 Iterable<Element> matches = world.allFunctions.filter( |
| 670 instruction.selector, instructionType); |
| 676 // This test relies the on `Object.==` and `Interceptor.==` always being | 671 // This test relies the on `Object.==` and `Interceptor.==` always being |
| 677 // implemented because if the selector matches by subtype, it still will be | 672 // implemented because if the selector matches by subtype, it still will be |
| 678 // a regular object or an interceptor. | 673 // a regular object or an interceptor. |
| 679 if (matches.every(backend.isDefaultEqualityImplementation)) { | 674 if (matches.every(backend.isDefaultEqualityImplementation)) { |
| 680 return newBuiltinVariant(instruction, compiler); | 675 return newBuiltinVariant(instruction, compiler); |
| 681 } | 676 } |
| 682 return null; | 677 return null; |
| 683 } | 678 } |
| 684 | 679 |
| 685 BinaryOperation operation(ConstantSystem constantSystem) { | 680 BinaryOperation operation(ConstantSystem constantSystem) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 return constantSystem.codeUnitAt; | 761 return constantSystem.codeUnitAt; |
| 767 } | 762 } |
| 768 | 763 |
| 769 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, | 764 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, |
| 770 Compiler compiler) { | 765 Compiler compiler) { |
| 771 // TODO(sra): Implement a builtin HCodeUnitAt instruction and the same index | 766 // TODO(sra): Implement a builtin HCodeUnitAt instruction and the same index |
| 772 // bounds checking optimizations as for HIndex. | 767 // bounds checking optimizations as for HIndex. |
| 773 return null; | 768 return null; |
| 774 } | 769 } |
| 775 } | 770 } |
| OLD | NEW |