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