OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 abstract class HVisitor<R> { | 7 abstract class HVisitor<R> { |
8 R visitAdd(HAdd node); | 8 R visitAdd(HAdd node); |
9 R visitBitAnd(HBitAnd node); | 9 R visitBitAnd(HBitAnd node); |
10 R visitBitNot(HBitNot node); | 10 R visitBitNot(HBitNot node); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 R visitStringConcat(HStringConcat node); | 61 R visitStringConcat(HStringConcat node); |
62 R visitStringify(HStringify node); | 62 R visitStringify(HStringify node); |
63 R visitSubtract(HSubtract node); | 63 R visitSubtract(HSubtract node); |
64 R visitSwitch(HSwitch node); | 64 R visitSwitch(HSwitch node); |
65 R visitThis(HThis node); | 65 R visitThis(HThis node); |
66 R visitThrow(HThrow node); | 66 R visitThrow(HThrow node); |
67 R visitThrowExpression(HThrowExpression node); | 67 R visitThrowExpression(HThrowExpression node); |
68 R visitTry(HTry node); | 68 R visitTry(HTry node); |
69 R visitTypeConversion(HTypeConversion node); | 69 R visitTypeConversion(HTypeConversion node); |
70 R visitTypeKnown(HTypeKnown node); | 70 R visitTypeKnown(HTypeKnown node); |
71 R visitReadTypeVariable(HReadTypeVariable node); | |
72 R visitFunctionType(HFunctionType node); | |
73 R visitVoidType(HVoidType node); | |
74 R visitInterfaceType(HInterfaceType node); | |
75 R visitDynamicType(HDynamicType node); | |
71 } | 76 } |
72 | 77 |
73 abstract class HGraphVisitor { | 78 abstract class HGraphVisitor { |
74 visitDominatorTree(HGraph graph) { | 79 visitDominatorTree(HGraph graph) { |
75 void visitBasicBlockAndSuccessors(HBasicBlock block) { | 80 void visitBasicBlockAndSuccessors(HBasicBlock block) { |
76 visitBasicBlock(block); | 81 visitBasicBlock(block); |
77 List dominated = block.dominatedBlocks; | 82 List dominated = block.dominatedBlocks; |
78 for (int i = 0; i < dominated.length; i++) { | 83 for (int i = 0; i < dominated.length; i++) { |
79 visitBasicBlockAndSuccessors(dominated[i]); | 84 visitBasicBlockAndSuccessors(dominated[i]); |
80 } | 85 } |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 visitStaticStore(HStaticStore node) => visitInstruction(node); | 328 visitStaticStore(HStaticStore node) => visitInstruction(node); |
324 visitStringConcat(HStringConcat node) => visitInstruction(node); | 329 visitStringConcat(HStringConcat node) => visitInstruction(node); |
325 visitStringify(HStringify node) => visitInstruction(node); | 330 visitStringify(HStringify node) => visitInstruction(node); |
326 visitThis(HThis node) => visitParameterValue(node); | 331 visitThis(HThis node) => visitParameterValue(node); |
327 visitThrow(HThrow node) => visitControlFlow(node); | 332 visitThrow(HThrow node) => visitControlFlow(node); |
328 visitThrowExpression(HThrowExpression node) => visitInstruction(node); | 333 visitThrowExpression(HThrowExpression node) => visitInstruction(node); |
329 visitTry(HTry node) => visitControlFlow(node); | 334 visitTry(HTry node) => visitControlFlow(node); |
330 visitIs(HIs node) => visitInstruction(node); | 335 visitIs(HIs node) => visitInstruction(node); |
331 visitTypeConversion(HTypeConversion node) => visitCheck(node); | 336 visitTypeConversion(HTypeConversion node) => visitCheck(node); |
332 visitTypeKnown(HTypeKnown node) => visitCheck(node); | 337 visitTypeKnown(HTypeKnown node) => visitCheck(node); |
338 visitReadTypeVariable(HReadTypeVariable node) => visitInstruction(node); | |
339 visitFunctionType(HFunctionType node) => visitInstruction(node); | |
340 visitVoidType(HVoidType node) => visitInstruction(node); | |
341 visitInterfaceType(HInterfaceType node) => visitInstruction(node); | |
342 visitDynamicType(HDynamicType node) => visitInstruction(node); | |
333 } | 343 } |
334 | 344 |
335 class SubGraph { | 345 class SubGraph { |
336 // The first and last block of the sub-graph. | 346 // The first and last block of the sub-graph. |
337 final HBasicBlock start; | 347 final HBasicBlock start; |
338 final HBasicBlock end; | 348 final HBasicBlock end; |
339 | 349 |
340 const SubGraph(this.start, this.end); | 350 const SubGraph(this.start, this.end); |
341 | 351 |
342 bool contains(HBasicBlock block) { | 352 bool contains(HBasicBlock block) { |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 static const int STATIC_TYPECODE = 21; | 786 static const int STATIC_TYPECODE = 21; |
777 static const int STATIC_STORE_TYPECODE = 22; | 787 static const int STATIC_STORE_TYPECODE = 22; |
778 static const int FIELD_GET_TYPECODE = 23; | 788 static const int FIELD_GET_TYPECODE = 23; |
779 static const int TYPE_CONVERSION_TYPECODE = 24; | 789 static const int TYPE_CONVERSION_TYPECODE = 24; |
780 static const int TYPE_KNOWN_TYPECODE = 25; | 790 static const int TYPE_KNOWN_TYPECODE = 25; |
781 static const int INVOKE_STATIC_TYPECODE = 26; | 791 static const int INVOKE_STATIC_TYPECODE = 26; |
782 static const int INDEX_TYPECODE = 27; | 792 static const int INDEX_TYPECODE = 27; |
783 static const int IS_TYPECODE = 28; | 793 static const int IS_TYPECODE = 28; |
784 static const int INVOKE_DYNAMIC_TYPECODE = 29; | 794 static const int INVOKE_DYNAMIC_TYPECODE = 29; |
785 static const int SHIFT_RIGHT_TYPECODE = 30; | 795 static const int SHIFT_RIGHT_TYPECODE = 30; |
796 static const int READ_TYPE_VARIABLE_TYPECODE = 31; | |
797 static const int FUNCTION_TYPE_TYPECODE = 32; | |
798 static const int VOID_TYPE_TYPECODE = 33; | |
799 static const int INTERFACE_TYPE_TYPECODE = 34; | |
800 static const int DYNAMIC_TYPE_TYPECODE = 35; | |
786 | 801 |
787 HInstruction(this.inputs, this.instructionType) | 802 HInstruction(this.inputs, this.instructionType) |
788 : id = idCounter++, usedBy = <HInstruction>[] { | 803 : id = idCounter++, usedBy = <HInstruction>[] { |
789 assert(inputs.every((e) => e != null)); | 804 assert(inputs.every((e) => e != null)); |
790 } | 805 } |
791 | 806 |
792 int get hashCode => id; | 807 int get hashCode => id; |
793 | 808 |
794 bool useGvn() => _useGvn; | 809 bool useGvn() => _useGvn; |
795 void setUseGvn() { _useGvn = true; } | 810 void setUseGvn() { _useGvn = true; } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
964 } | 979 } |
965 | 980 |
966 bool isPrimitiveOrNull(Compiler compiler) { | 981 bool isPrimitiveOrNull(Compiler compiler) { |
967 return isIndexablePrimitive(compiler) | 982 return isIndexablePrimitive(compiler) |
968 || isNumberOrNull(compiler) | 983 || isNumberOrNull(compiler) |
969 || isBooleanOrNull(compiler) | 984 || isBooleanOrNull(compiler) |
970 || isNull(); | 985 || isNull(); |
971 } | 986 } |
972 | 987 |
973 /** | 988 /** |
974 * Type of the unstruction. | 989 * Type of the instruction. |
975 */ | 990 */ |
976 TypeMask instructionType; | 991 TypeMask instructionType; |
977 | 992 |
978 Selector get selector => null; | 993 Selector get selector => null; |
979 HInstruction getDartReceiver(Compiler compiler) => null; | 994 HInstruction getDartReceiver(Compiler compiler) => null; |
980 bool onlyThrowsNSM() => false; | 995 bool onlyThrowsNSM() => false; |
981 | 996 |
982 bool isInBasicBlock() => block != null; | 997 bool isInBasicBlock() => block != null; |
983 | 998 |
984 String inputsToString() { | 999 String inputsToString() { |
(...skipping 1832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2817 this.finallyBlock); | 2832 this.finallyBlock); |
2818 | 2833 |
2819 HBasicBlock get start => body.start; | 2834 HBasicBlock get start => body.start; |
2820 HBasicBlock get end => | 2835 HBasicBlock get end => |
2821 finallyBlock == null ? catchBlock.end : finallyBlock.end; | 2836 finallyBlock == null ? catchBlock.end : finallyBlock.end; |
2822 | 2837 |
2823 bool accept(HStatementInformationVisitor visitor) => | 2838 bool accept(HStatementInformationVisitor visitor) => |
2824 visitor.visitTryInfo(this); | 2839 visitor.visitTryInfo(this); |
2825 } | 2840 } |
2826 | 2841 |
2827 | |
2828 | |
2829 class HSwitchBlockInformation implements HStatementInformation { | 2842 class HSwitchBlockInformation implements HStatementInformation { |
2830 final HExpressionInformation expression; | 2843 final HExpressionInformation expression; |
2831 final List<HStatementInformation> statements; | 2844 final List<HStatementInformation> statements; |
2832 final TargetElement target; | 2845 final TargetElement target; |
2833 final List<LabelElement> labels; | 2846 final List<LabelElement> labels; |
2834 | 2847 |
2835 HSwitchBlockInformation(this.expression, | 2848 HSwitchBlockInformation(this.expression, |
2836 this.statements, | 2849 this.statements, |
2837 this.target, | 2850 this.target, |
2838 this.labels); | 2851 this.labels); |
2839 | 2852 |
2840 HBasicBlock get start => expression.start; | 2853 HBasicBlock get start => expression.start; |
2841 HBasicBlock get end { | 2854 HBasicBlock get end { |
2842 // We don't create a switch block if there are no cases. | 2855 // We don't create a switch block if there are no cases. |
2843 assert(!statements.isEmpty); | 2856 assert(!statements.isEmpty); |
2844 return statements.last.end; | 2857 return statements.last.end; |
2845 } | 2858 } |
2846 | 2859 |
2847 bool accept(HStatementInformationVisitor visitor) => | 2860 bool accept(HStatementInformationVisitor visitor) => |
2848 visitor.visitSwitchInfo(this); | 2861 visitor.visitSwitchInfo(this); |
2849 } | 2862 } |
2863 | |
2864 class HReadTypeVariable extends HInstruction { | |
2865 /// The type variable being read. | |
2866 final TypeVariableType dartType; | |
2867 | |
2868 final bool hasReceiver; | |
2869 | |
2870 HReadTypeVariable(this.dartType, | |
2871 HInstruction receiver, | |
2872 TypeMask instructionType) | |
2873 : hasReceiver = true, | |
2874 super(<HInstruction>[receiver], instructionType) { | |
2875 setUseGvn(); | |
2876 } | |
2877 | |
2878 HReadTypeVariable.noReceiver(this.dartType, | |
2879 HInstruction typeArguments, | |
Johnni Winther
2013/12/03 10:33:16
typeArguments -> typeArgument.
ahe
2013/12/05 14:24:23
Done.
| |
2880 TypeMask instructionType) | |
2881 : hasReceiver = false, | |
2882 super(<HInstruction>[typeArguments], instructionType) { | |
2883 setUseGvn(); | |
2884 } | |
2885 | |
2886 accept(HVisitor visitor) => visitor.visitReadTypeVariable(this); | |
2887 | |
2888 bool canThrow() => false; | |
2889 | |
2890 int typeCode() => HInstruction.READ_TYPE_VARIABLE_TYPECODE; | |
2891 bool typeEquals(HInstruction other) => other is HReadTypeVariable; | |
2892 | |
2893 bool dataEquals(HReadTypeVariable other) { | |
2894 return dartType.element == other.dartType.element | |
2895 && hasReceiver == other.hasReceiver; | |
2896 } | |
2897 } | |
2898 | |
2899 abstract class HRuntimeType extends HInstruction { | |
2900 final DartType dartType; | |
2901 | |
2902 HRuntimeType(List<HInstruction> inputs, | |
2903 this.dartType, | |
2904 TypeMask instructionType) | |
2905 : super(inputs, instructionType) { | |
2906 setUseGvn(); | |
2907 } | |
2908 | |
2909 bool canThrow() => false; | |
2910 | |
2911 int typeCode() { | |
2912 throw 'abstract method'; | |
2913 } | |
2914 | |
2915 bool typeEquals(HInstruction other) { | |
2916 throw 'abstract method'; | |
2917 } | |
2918 | |
2919 bool dataEquals(HRuntimeType other) { | |
2920 return dartType == other.dartType; | |
2921 } | |
2922 } | |
2923 | |
2924 class HFunctionType extends HRuntimeType { | |
2925 HFunctionType(List<HInstruction> inputs, | |
2926 FunctionType dartType, | |
2927 TypeMask instructionType) | |
2928 : super(inputs, dartType, instructionType); | |
2929 | |
2930 accept(HVisitor visitor) => visitor.visitFunctionType(this); | |
2931 | |
2932 int typeCode() => HInstruction.FUNCTION_TYPE_TYPECODE; | |
2933 | |
2934 bool typeEquals(HInstruction other) => other is HFunctionType; | |
2935 } | |
2936 | |
2937 class HVoidType extends HRuntimeType { | |
2938 HVoidType(VoidType dartType, TypeMask instructionType) | |
2939 : super(const <HInstruction>[], dartType, instructionType); | |
2940 | |
2941 accept(HVisitor visitor) => visitor.visitVoidType(this); | |
2942 | |
2943 int typeCode() => HInstruction.VOID_TYPE_TYPECODE; | |
2944 | |
2945 bool typeEquals(HInstruction other) => other is HVoidType; | |
2946 } | |
2947 | |
2948 class HInterfaceType extends HRuntimeType { | |
2949 HInterfaceType(List<HInstruction> inputs, | |
2950 InterfaceType dartType, | |
2951 TypeMask instructionType) | |
2952 : super(inputs, dartType, instructionType); | |
2953 | |
2954 accept(HVisitor visitor) => visitor.visitInterfaceType(this); | |
2955 | |
2956 int typeCode() => HInstruction.INTERFACE_TYPE_TYPECODE; | |
2957 | |
2958 bool typeEquals(HInstruction other) => other is HInterfaceType; | |
2959 } | |
2960 | |
2961 class HDynamicType extends HRuntimeType { | |
2962 HDynamicType(DynamicType dartType, TypeMask instructionType) | |
2963 : super(const <HInstruction>[], dartType, instructionType); | |
2964 | |
2965 accept(HVisitor visitor) => visitor.visitDynamicType(this); | |
2966 | |
2967 int typeCode() => HInstruction.DYNAMIC_TYPE_TYPECODE; | |
2968 | |
2969 bool typeEquals(HInstruction other) => other is HDynamicType; | |
2970 } | |
OLD | NEW |