blob: 6aa7f8d31d3acc66a43696a98fa076db1d9ade90 [file] [log] [blame]
David Brazdil9a6f20e2014-12-19 11:17:21 +00001public class Inliner {
2
3 // CHECK-START: void Inliner.InlineVoid() inliner (before)
4 // CHECK-DAG: [[Const42:i[0-9]+]] IntConstant 42
5 // CHECK-DAG: InvokeStaticOrDirect
6 // CHECK-DAG: InvokeStaticOrDirect [ [[Const42]] ]
7
8 // CHECK-START: void Inliner.InlineVoid() inliner (after)
9 // CHECK-NOT: InvokeStaticOrDirect
10
11 public static void InlineVoid() {
12 returnVoid();
13 returnVoidWithOneParameter(42);
14 }
15
16 // CHECK-START: int Inliner.InlineParameter(int) inliner (before)
17 // CHECK-DAG: [[Param:i[0-9]+]] ParameterValue
18 // CHECK-DAG: [[Result:i[0-9]+]] InvokeStaticOrDirect [ [[Param]] ]
19 // CHECK-DAG: Return [ [[Result]] ]
20
21 // CHECK-START: int Inliner.InlineParameter(int) inliner (after)
22 // CHECK-DAG: [[Param:i[0-9]+]] ParameterValue
23 // CHECK-DAG: Return [ [[Param]] ]
24
25 public static int InlineParameter(int a) {
26 return returnParameter(a);
27 }
28
29 // CHECK-START: long Inliner.InlineWideParameter(long) inliner (before)
30 // CHECK-DAG: [[Param:j[0-9]+]] ParameterValue
31 // CHECK-DAG: [[Result:j[0-9]+]] InvokeStaticOrDirect [ [[Param]] ]
32 // CHECK-DAG: Return [ [[Result]] ]
33
34 // CHECK-START: long Inliner.InlineWideParameter(long) inliner (after)
35 // CHECK-DAG: [[Param:j[0-9]+]] ParameterValue
36 // CHECK-DAG: Return [ [[Param]] ]
37
38 public static long InlineWideParameter(long a) {
39 return returnWideParameter(a);
40 }
41
42 // CHECK-START: java.lang.Object Inliner.InlineReferenceParameter(java.lang.Object) inliner (before)
43 // CHECK-DAG: [[Param:l[0-9]+]] ParameterValue
44 // CHECK-DAG: [[Result:l[0-9]+]] InvokeStaticOrDirect [ [[Param]] ]
45 // CHECK-DAG: Return [ [[Result]] ]
46
47 // CHECK-START: java.lang.Object Inliner.InlineReferenceParameter(java.lang.Object) inliner (after)
48 // CHECK-DAG: [[Param:l[0-9]+]] ParameterValue
49 // CHECK-DAG: Return [ [[Param]] ]
50
51 public static Object InlineReferenceParameter(Object o) {
52 return returnReferenceParameter(o);
53 }
54
55 // CHECK-START: int Inliner.InlineInt() inliner (before)
56 // CHECK-DAG: [[Result:i[0-9]+]] InvokeStaticOrDirect
57 // CHECK-DAG: Return [ [[Result]] ]
58
59 // CHECK-START: int Inliner.InlineInt() inliner (after)
60 // CHECK-DAG: [[Const4:i[0-9]+]] IntConstant 4
61 // CHECK-DAG: Return [ [[Const4]] ]
62
63 public static int InlineInt() {
64 return returnInt();
65 }
66
67 // CHECK-START: long Inliner.InlineWide() inliner (before)
68 // CHECK-DAG: [[Result:j[0-9]+]] InvokeStaticOrDirect
69 // CHECK-DAG: Return [ [[Result]] ]
70
71 // CHECK-START: long Inliner.InlineWide() inliner (after)
72 // CHECK-DAG: [[Const8:j[0-9]+]] LongConstant 8
73 // CHECK-DAG: Return [ [[Const8]] ]
74
75 public static long InlineWide() {
76 return returnWide();
77 }
78
79 // CHECK-START: int Inliner.InlineAdd() inliner (before)
80 // CHECK-DAG: [[Const3:i[0-9]+]] IntConstant 3
81 // CHECK-DAG: [[Const5:i[0-9]+]] IntConstant 5
82 // CHECK-DAG: [[Result:i[0-9]+]] InvokeStaticOrDirect
83 // CHECK-DAG: Return [ [[Result]] ]
84
85 // CHECK-START: int Inliner.InlineAdd() inliner (after)
86 // CHECK-DAG: [[Const3:i[0-9]+]] IntConstant 3
87 // CHECK-DAG: [[Const5:i[0-9]+]] IntConstant 5
88 // CHECK-DAG: [[Add:i[0-9]+]] Add [ [[Const3]] [[Const5]] ]
89 // CHECK-DAG: Return [ [[Add]] ]
90
91 public static int InlineAdd() {
92 return returnAdd(3, 5);
93 }
94
95 // CHECK-START: int Inliner.InlineFieldAccess() inliner (before)
96 // CHECK-DAG: [[After:i[0-9]+]] InvokeStaticOrDirect
97 // CHECK-DAG: Return [ [[After]] ]
98
99 // CHECK-START: int Inliner.InlineFieldAccess() inliner (after)
100 // CHECK-DAG: [[Const1:i[0-9]+]] IntConstant 1
101 // CHECK-DAG: [[Before:i[0-9]+]] StaticFieldGet
102 // CHECK-DAG: [[After:i[0-9]+]] Add [ [[Before]] [[Const1]] ]
103 // CHECK-DAG: StaticFieldSet [ {{l[0-9]+}} [[After]] ]
104 // CHECK-DAG: Return [ [[After]] ]
105
106 // CHECK-START: int Inliner.InlineFieldAccess() inliner (after)
107 // CHECK-NOT: InvokeStaticOrDirect
108
109 public static int InlineFieldAccess() {
110 return incCounter();
111 }
112
113 // CHECK-START: int Inliner.InlineWithControlFlow(boolean) inliner (before)
114 // CHECK-DAG: [[Const1:i[0-9]+]] IntConstant 1
115 // CHECK-DAG: [[Const3:i[0-9]+]] IntConstant 3
116 // CHECK-DAG: [[Const5:i[0-9]+]] IntConstant 5
117 // CHECK-DAG: [[Add:i[0-9]+]] InvokeStaticOrDirect [ [[Const1]] [[Const3]] ]
118 // CHECK-DAG: [[Sub:i[0-9]+]] InvokeStaticOrDirect [ [[Const5]] [[Const3]] ]
119 // CHECK-DAG: [[Phi:i[0-9]+]] Phi [ [[Add]] [[Sub]] ]
120 // CHECK-DAG: Return [ [[Phi]] ]
121
122 // CHECK-START: int Inliner.InlineWithControlFlow(boolean) inliner (after)
123 // CHECK-DAG: [[Const1:i[0-9]+]] IntConstant 1
124 // CHECK-DAG: [[Const3:i[0-9]+]] IntConstant 3
125 // CHECK-DAG: [[Const5:i[0-9]+]] IntConstant 5
126 // CHECK-DAG: [[Add:i[0-9]+]] Add [ [[Const1]] [[Const3]] ]
127 // CHECK-DAG: [[Sub:i[0-9]+]] Sub [ [[Const5]] [[Const3]] ]
128 // CHECK-DAG: [[Phi:i[0-9]+]] Phi [ [[Add]] [[Sub]] ]
129 // CHECK-DAG: Return [ [[Phi]] ]
130
131 public static int InlineWithControlFlow(boolean cond) {
132 int x, const1, const3, const5;
133 const1 = 1;
134 const3 = 3;
135 const5 = 5;
136 if (cond) {
137 x = returnAdd(const1, const3);
138 } else {
139 x = returnSub(const5, const3);
140 }
141 return x;
142 }
143
144
145 private static void returnVoid() {
146 return;
147 }
148
149 private static void returnVoidWithOneParameter(int a) {
150 return;
151 }
152
153 private static int returnParameter(int a) {
154 return a;
155 }
156
157 private static long returnWideParameter(long a) {
158 return a;
159 }
160
161 private static Object returnReferenceParameter(Object o) {
162 return o;
163 }
164
165 private static int returnInt() {
166 return 4;
167 }
168
169 private static long returnWide() {
170 return 8L;
171 }
172
173 private static int returnAdd(int a, int b) {
174 return a + b;
175 }
176
177 private static int returnSub(int a, int b) {
178 return a - b;
179 }
180
181 private static int counter = 42;
182
183 private static int incCounter() {
184 return ++counter;
185 }
186}