Chromium Code Reviews| 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 25 matching lines...) Expand all Loading... | |
| 36 | 36 |
| 37 void clearAllSideEffects(HInstruction instruction) { | 37 void clearAllSideEffects(HInstruction instruction) { |
| 38 instruction.sideEffects.clearAllSideEffects(); | 38 instruction.sideEffects.clearAllSideEffects(); |
| 39 instruction.sideEffects.clearAllDependencies(); | 39 instruction.sideEffects.clearAllDependencies(); |
| 40 instruction.setUseGvn(); | 40 instruction.setUseGvn(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 Operation operation(ConstantSystem constantSystem) => null; | 43 Operation operation(ConstantSystem constantSystem) => null; |
| 44 | 44 |
| 45 static InvokeDynamicSpecializer lookupSpecializer(Selector selector) { | 45 static InvokeDynamicSpecializer lookupSpecializer(Selector selector) { |
| 46 if (selector.isIndex) { | 46 if (selector.isIndex) return const IndexSpecializer(); |
| 47 return const IndexSpecializer(); | 47 if (selector.isIndexSet) return const IndexAssignSpecializer(); |
| 48 } else if (selector.isIndexSet) { | 48 String name = selector.name; |
| 49 return const IndexAssignSpecializer(); | 49 if (selector.isOperator) { |
| 50 } else if (selector.isOperator) { | 50 if (name == 'unary-') return const UnaryNegateSpecializer(); |
|
Siggi Cherem (dart-lang)
2016/10/07 22:35:36
yay, much better style, thank you!
| |
| 51 if (selector.name == 'unary-') { | 51 if (name == '~') return const BitNotSpecializer(); |
| 52 return const UnaryNegateSpecializer(); | 52 if (name == '+') return const AddSpecializer(); |
| 53 } else if (selector.name == '~') { | 53 if (name == '-') return const SubtractSpecializer(); |
| 54 return const BitNotSpecializer(); | 54 if (name == '*') return const MultiplySpecializer(); |
| 55 } else if (selector.name == '+') { | 55 if (name == '/') return const DivideSpecializer(); |
| 56 return const AddSpecializer(); | 56 if (name == '~/') return const TruncatingDivideSpecializer(); |
| 57 } else if (selector.name == '-') { | 57 if (name == '%') return const ModuloSpecializer(); |
| 58 return const SubtractSpecializer(); | 58 if (name == '>>') return const ShiftRightSpecializer(); |
| 59 } else if (selector.name == '*') { | 59 if (name == '<<') return const ShiftLeftSpecializer(); |
| 60 return const MultiplySpecializer(); | 60 if (name == '&') return const BitAndSpecializer(); |
| 61 } else if (selector.name == '/') { | 61 if (name == '|') return const BitOrSpecializer(); |
| 62 return const DivideSpecializer(); | 62 if (name == '^') return const BitXorSpecializer(); |
| 63 } else if (selector.name == '~/') { | 63 if (name == '==') return const EqualsSpecializer(); |
| 64 return const TruncatingDivideSpecializer(); | 64 if (name == '<') return const LessSpecializer(); |
| 65 } else if (selector.name == '%') { | 65 if (name == '<=') return const LessEqualSpecializer(); |
| 66 return const ModuloSpecializer(); | 66 if (name == '>') return const GreaterSpecializer(); |
| 67 } else if (selector.name == '>>') { | 67 if (name == '>=') return const GreaterEqualSpecializer(); |
| 68 return const ShiftRightSpecializer(); | 68 return const InvokeDynamicSpecializer(); |
| 69 } else if (selector.name == '<<') { | 69 } |
| 70 return const ShiftLeftSpecializer(); | 70 if (selector.isCall) { |
| 71 } else if (selector.name == '&') { | 71 if (selector.namedArguments.length == 0) { |
| 72 return const BitAndSpecializer(); | 72 int argumentCount = selector.argumentCount; |
| 73 } else if (selector.name == '|') { | 73 if (argumentCount == 0) { |
| 74 return const BitOrSpecializer(); | 74 if (name == 'round') return const RoundSpecializer(); |
| 75 } else if (selector.name == '^') { | 75 } else if (argumentCount == 0) { |
|
Siggi Cherem (dart-lang)
2016/10/07 22:35:36
argumentCount == 1
| |
| 76 return const BitXorSpecializer(); | 76 if (name == 'codeUnitAt') return const CodeUnitAtSpecializer(); |
| 77 } else if (selector.name == '==') { | |
| 78 return const EqualsSpecializer(); | |
| 79 } else if (selector.name == '<') { | |
| 80 return const LessSpecializer(); | |
| 81 } else if (selector.name == '<=') { | |
| 82 return const LessEqualSpecializer(); | |
| 83 } else if (selector.name == '>') { | |
| 84 return const GreaterSpecializer(); | |
| 85 } else if (selector.name == '>=') { | |
| 86 return const GreaterEqualSpecializer(); | |
| 87 } | |
| 88 } else if (selector.isCall) { | |
| 89 if (selector.argumentCount == 1 && selector.namedArguments.length == 0) { | |
| 90 if (selector.name == 'codeUnitAt') { | |
| 91 return const CodeUnitAtSpecializer(); | |
| 92 } | |
| 93 } | |
| 94 if (selector.argumentCount == 0 && selector.namedArguments.length == 0) { | |
| 95 if (selector.name == 'round') { | |
| 96 return const RoundSpecializer(); | |
| 97 } | 77 } |
| 98 } | 78 } |
| 99 } | 79 } |
| 100 return const InvokeDynamicSpecializer(); | 80 return const InvokeDynamicSpecializer(); |
| 101 } | 81 } |
| 102 } | 82 } |
| 103 | 83 |
| 104 class IndexAssignSpecializer extends InvokeDynamicSpecializer { | 84 class IndexAssignSpecializer extends InvokeDynamicSpecializer { |
| 105 const IndexAssignSpecializer(); | 85 const IndexAssignSpecializer(); |
| 106 | 86 |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 754 const CodeUnitAtSpecializer(); | 734 const CodeUnitAtSpecializer(); |
| 755 | 735 |
| 756 BinaryOperation operation(ConstantSystem constantSystem) { | 736 BinaryOperation operation(ConstantSystem constantSystem) { |
| 757 return constantSystem.codeUnitAt; | 737 return constantSystem.codeUnitAt; |
| 758 } | 738 } |
| 759 | 739 |
| 760 HInstruction tryConvertToBuiltin( | 740 HInstruction tryConvertToBuiltin( |
| 761 HInvokeDynamic instruction, Compiler compiler) { | 741 HInvokeDynamic instruction, Compiler compiler) { |
| 762 // TODO(sra): Implement a builtin HCodeUnitAt instruction and the same index | 742 // TODO(sra): Implement a builtin HCodeUnitAt instruction and the same index |
| 763 // bounds checking optimizations as for HIndex. | 743 // bounds checking optimizations as for HIndex. |
| 744 HInstruction receiver = instruction.getDartReceiver(compiler); | |
| 745 if (receiver.isStringOrNull(compiler)) { | |
| 746 // Even if there is no builtin equivalent instruction, we know | |
| 747 // String.codeUnitAt does not have any side effect (other than throwing), | |
| 748 // and that it can be GVN'ed. | |
| 749 clearAllSideEffects(instruction); | |
| 750 } | |
| 764 return null; | 751 return null; |
| 765 } | 752 } |
| 766 } | 753 } |
| 767 | 754 |
| 768 class RoundSpecializer extends InvokeDynamicSpecializer { | 755 class RoundSpecializer extends InvokeDynamicSpecializer { |
| 769 const RoundSpecializer(); | 756 const RoundSpecializer(); |
| 770 | 757 |
| 771 UnaryOperation operation(ConstantSystem constantSystem) { | 758 UnaryOperation operation(ConstantSystem constantSystem) { |
| 772 return constantSystem.round; | 759 return constantSystem.round; |
| 773 } | 760 } |
| 774 | 761 |
| 775 HInstruction tryConvertToBuiltin( | 762 HInstruction tryConvertToBuiltin( |
| 776 HInvokeDynamic instruction, Compiler compiler) { | 763 HInvokeDynamic instruction, Compiler compiler) { |
| 777 HInstruction receiver = instruction.getDartReceiver(compiler); | 764 HInstruction receiver = instruction.getDartReceiver(compiler); |
| 778 if (receiver.isNumberOrNull(compiler)) { | 765 if (receiver.isNumberOrNull(compiler)) { |
| 779 // Even if there is no builtin equivalent instruction, we know the | 766 // 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. | 767 // instruction does not have any side effect, and that it can be GVN'ed. |
| 781 clearAllSideEffects(instruction); | 768 clearAllSideEffects(instruction); |
| 782 } | 769 } |
| 783 return null; | 770 return null; |
| 784 } | 771 } |
| 785 } | 772 } |
| OLD | NEW |