| 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 import '../compiler.dart' show Compiler; | 5 import '../compiler.dart' show Compiler; |
| 6 import '../constants/constant_system.dart'; | 6 import '../constants/constant_system.dart'; |
| 7 import '../constants/values.dart'; | 7 import '../constants/values.dart'; |
| 8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
| 9 import '../js_backend/js_backend.dart'; | 9 import '../js_backend/js_backend.dart'; |
| 10 import '../types/types.dart'; | 10 import '../types/types.dart'; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 HInvokeDynamic instruction, Compiler compiler) { | 27 HInvokeDynamic instruction, Compiler compiler) { |
| 28 return TypeMaskFactory.inferredTypeForSelector( | 28 return TypeMaskFactory.inferredTypeForSelector( |
| 29 instruction.selector, instruction.mask, compiler); | 29 instruction.selector, instruction.mask, compiler); |
| 30 } | 30 } |
| 31 | 31 |
| 32 HInstruction tryConvertToBuiltin( | 32 HInstruction tryConvertToBuiltin( |
| 33 HInvokeDynamic instruction, Compiler compiler) { | 33 HInvokeDynamic instruction, Compiler compiler) { |
| 34 return null; | 34 return null; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void clearAllSideEffects(HInstruction instruction) { | |
| 38 instruction.sideEffects.clearAllSideEffects(); | |
| 39 instruction.sideEffects.clearAllDependencies(); | |
| 40 instruction.setUseGvn(); | |
| 41 } | |
| 42 | |
| 43 Operation operation(ConstantSystem constantSystem) => null; | 37 Operation operation(ConstantSystem constantSystem) => null; |
| 44 | 38 |
| 45 static InvokeDynamicSpecializer lookupSpecializer(Selector selector) { | 39 static InvokeDynamicSpecializer lookupSpecializer(Selector selector) { |
| 46 if (selector.isIndex) { | 40 if (selector.isIndex) { |
| 47 return const IndexSpecializer(); | 41 return const IndexSpecializer(); |
| 48 } else if (selector.isIndexSet) { | 42 } else if (selector.isIndexSet) { |
| 49 return const IndexAssignSpecializer(); | 43 return const IndexAssignSpecializer(); |
| 50 } else if (selector.isOperator) { | 44 } else if (selector.isOperator) { |
| 51 if (selector.name == 'unary-') { | 45 if (selector.name == 'unary-') { |
| 52 return const UnaryNegateSpecializer(); | 46 return const UnaryNegateSpecializer(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 return const GreaterSpecializer(); | 78 return const GreaterSpecializer(); |
| 85 } else if (selector.name == '>=') { | 79 } else if (selector.name == '>=') { |
| 86 return const GreaterEqualSpecializer(); | 80 return const GreaterEqualSpecializer(); |
| 87 } | 81 } |
| 88 } else if (selector.isCall) { | 82 } else if (selector.isCall) { |
| 89 if (selector.argumentCount == 1 && selector.namedArguments.length == 0) { | 83 if (selector.argumentCount == 1 && selector.namedArguments.length == 0) { |
| 90 if (selector.name == 'codeUnitAt') { | 84 if (selector.name == 'codeUnitAt') { |
| 91 return const CodeUnitAtSpecializer(); | 85 return const CodeUnitAtSpecializer(); |
| 92 } | 86 } |
| 93 } | 87 } |
| 94 if (selector.argumentCount == 0 && selector.namedArguments.length == 0) { | |
| 95 if (selector.name == 'round') { | |
| 96 return const RoundSpecializer(); | |
| 97 } | |
| 98 } | |
| 99 } | 88 } |
| 100 return const InvokeDynamicSpecializer(); | 89 return const InvokeDynamicSpecializer(); |
| 101 } | 90 } |
| 102 } | 91 } |
| 103 | 92 |
| 104 class IndexAssignSpecializer extends InvokeDynamicSpecializer { | 93 class IndexAssignSpecializer extends InvokeDynamicSpecializer { |
| 105 const IndexAssignSpecializer(); | 94 const IndexAssignSpecializer(); |
| 106 | 95 |
| 107 HInstruction tryConvertToBuiltin( | 96 HInstruction tryConvertToBuiltin( |
| 108 HInvokeDynamic instruction, Compiler compiler) { | 97 HInvokeDynamic instruction, Compiler compiler) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 HInstruction builtin = newBuiltinVariant(instruction, compiler); | 212 HInstruction builtin = newBuiltinVariant(instruction, compiler); |
| 224 if (builtin != null) return builtin; | 213 if (builtin != null) return builtin; |
| 225 // Even if there is no builtin equivalent instruction, we know | 214 // Even if there is no builtin equivalent instruction, we know |
| 226 // the instruction does not have any side effect, and that it | 215 // the instruction does not have any side effect, and that it |
| 227 // can be GVN'ed. | 216 // can be GVN'ed. |
| 228 clearAllSideEffects(instruction); | 217 clearAllSideEffects(instruction); |
| 229 } | 218 } |
| 230 return null; | 219 return null; |
| 231 } | 220 } |
| 232 | 221 |
| 222 void clearAllSideEffects(HInstruction instruction) { |
| 223 instruction.sideEffects.clearAllSideEffects(); |
| 224 instruction.sideEffects.clearAllDependencies(); |
| 225 instruction.setUseGvn(); |
| 226 } |
| 227 |
| 233 bool inputsArePositiveIntegers(HInstruction instruction, Compiler compiler) { | 228 bool inputsArePositiveIntegers(HInstruction instruction, Compiler compiler) { |
| 234 HInstruction left = instruction.inputs[1]; | 229 HInstruction left = instruction.inputs[1]; |
| 235 HInstruction right = instruction.inputs[2]; | 230 HInstruction right = instruction.inputs[2]; |
| 236 return left.isPositiveIntegerOrNull(compiler) && | 231 return left.isPositiveIntegerOrNull(compiler) && |
| 237 right.isPositiveIntegerOrNull(compiler); | 232 right.isPositiveIntegerOrNull(compiler); |
| 238 } | 233 } |
| 239 | 234 |
| 240 bool inputsAreUInt31(HInstruction instruction, Compiler compiler) { | 235 bool inputsAreUInt31(HInstruction instruction, Compiler compiler) { |
| 241 HInstruction left = instruction.inputs[1]; | 236 HInstruction left = instruction.inputs[1]; |
| 242 HInstruction right = instruction.inputs[2]; | 237 HInstruction right = instruction.inputs[2]; |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 return constantSystem.codeUnitAt; | 752 return constantSystem.codeUnitAt; |
| 758 } | 753 } |
| 759 | 754 |
| 760 HInstruction tryConvertToBuiltin( | 755 HInstruction tryConvertToBuiltin( |
| 761 HInvokeDynamic instruction, Compiler compiler) { | 756 HInvokeDynamic instruction, Compiler compiler) { |
| 762 // TODO(sra): Implement a builtin HCodeUnitAt instruction and the same index | 757 // TODO(sra): Implement a builtin HCodeUnitAt instruction and the same index |
| 763 // bounds checking optimizations as for HIndex. | 758 // bounds checking optimizations as for HIndex. |
| 764 return null; | 759 return null; |
| 765 } | 760 } |
| 766 } | 761 } |
| 767 | |
| 768 class RoundSpecializer extends InvokeDynamicSpecializer { | |
| 769 const RoundSpecializer(); | |
| 770 | |
| 771 UnaryOperation operation(ConstantSystem constantSystem) { | |
| 772 return constantSystem.round; | |
| 773 } | |
| 774 | |
| 775 HInstruction tryConvertToBuiltin( | |
| 776 HInvokeDynamic instruction, Compiler compiler) { | |
| 777 HInstruction receiver = instruction.getDartReceiver(compiler); | |
| 778 if (receiver.isNumberOrNull(compiler)) { | |
| 779 // Even if there is no builtin equivalent instruction, we know the | |
| 780 // instruction does not have any side effect, and that it can be GVN'ed. | |
| 781 clearAllSideEffects(instruction); | |
| 782 } | |
| 783 return null; | |
| 784 } | |
| 785 } | |
| OLD | NEW |