1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class Main {
/// CHECK-START: void Main.InlineVoid() inliner (before)
/// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
/// CHECK-DAG: InvokeStaticOrDirect
/// CHECK-DAG: InvokeStaticOrDirect [<<Const42>>,{{[ij]\d+}}]
/// CHECK-START: void Main.InlineVoid() inliner (after)
/// CHECK-NOT: InvokeStaticOrDirect
public static void InlineVoid() {
returnVoid();
returnVoidWithOneParameter(42);
}
/// CHECK-START: int Main.InlineParameter(int) inliner (before)
/// CHECK-DAG: <<Param:i\d+>> ParameterValue
/// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect [<<Param>>,{{[ij]\d+}}]
/// CHECK-DAG: Return [<<Result>>]
/// CHECK-START: int Main.InlineParameter(int) inliner (after)
/// CHECK-DAG: <<Param:i\d+>> ParameterValue
/// CHECK-DAG: Return [<<Param>>]
public static int InlineParameter(int a) {
return returnParameter(a);
}
/// CHECK-START: long Main.InlineWideParameter(long) inliner (before)
/// CHECK-DAG: <<Param:j\d+>> ParameterValue
/// CHECK-DAG: <<Result:j\d+>> InvokeStaticOrDirect [<<Param>>,{{[ij]\d+}}]
/// CHECK-DAG: Return [<<Result>>]
/// CHECK-START: long Main.InlineWideParameter(long) inliner (after)
/// CHECK-DAG: <<Param:j\d+>> ParameterValue
/// CHECK-DAG: Return [<<Param>>]
public static long InlineWideParameter(long a) {
return returnWideParameter(a);
}
/// CHECK-START: java.lang.Object Main.InlineReferenceParameter(java.lang.Object) inliner (before)
/// CHECK-DAG: <<Param:l\d+>> ParameterValue
/// CHECK-DAG: <<Result:l\d+>> InvokeStaticOrDirect [<<Param>>,{{[ij]\d+}}]
/// CHECK-DAG: Return [<<Result>>]
/// CHECK-START: java.lang.Object Main.InlineReferenceParameter(java.lang.Object) inliner (after)
/// CHECK-DAG: <<Param:l\d+>> ParameterValue
/// CHECK-DAG: Return [<<Param>>]
public static Object InlineReferenceParameter(Object o) {
return returnReferenceParameter(o);
}
/// CHECK-START: int Main.InlineInt() inliner (before)
/// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect
/// CHECK-DAG: Return [<<Result>>]
/// CHECK-START: int Main.InlineInt() inliner (after)
/// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
/// CHECK-DAG: Return [<<Const4>>]
public static int InlineInt() {
return returnInt();
}
/// CHECK-START: long Main.InlineWide() inliner (before)
/// CHECK-DAG: <<Result:j\d+>> InvokeStaticOrDirect
/// CHECK-DAG: Return [<<Result>>]
/// CHECK-START: long Main.InlineWide() inliner (after)
/// CHECK-DAG: <<Const8:j\d+>> LongConstant 8
/// CHECK-DAG: Return [<<Const8>>]
public static long InlineWide() {
return returnWide();
}
/// CHECK-START: int Main.InlineAdd() inliner (before)
/// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
/// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
/// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect
/// CHECK-DAG: Return [<<Result>>]
/// CHECK-START: int Main.InlineAdd() inliner (after)
/// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
/// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
/// CHECK-DAG: <<Add:i\d+>> Add [<<Const3>>,<<Const5>>]
/// CHECK-DAG: Return [<<Add>>]
public static int InlineAdd() {
return returnAdd(3, 5);
}
/// CHECK-START: int Main.InlineFieldAccess() inliner (before)
/// CHECK-DAG: <<After:i\d+>> InvokeStaticOrDirect
/// CHECK-DAG: Return [<<After>>]
/// CHECK-START: int Main.InlineFieldAccess() inliner (after)
/// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
/// CHECK-DAG: <<Before:i\d+>> StaticFieldGet
/// CHECK-DAG: <<After:i\d+>> Add [<<Before>>,<<Const1>>]
/// CHECK-DAG: StaticFieldSet [{{l\d+}},<<After>>]
/// CHECK-DAG: Return [<<After>>]
/// CHECK-START: int Main.InlineFieldAccess() inliner (after)
/// CHECK-NOT: InvokeStaticOrDirect
public static int InlineFieldAccess() {
return incCounter();
}
/// CHECK-START: int Main.InlineWithControlFlow(boolean) inliner (before)
/// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
/// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
/// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
/// CHECK-DAG: <<Add:i\d+>> InvokeStaticOrDirect [<<Const1>>,<<Const3>>,{{[ij]\d+}}]
/// CHECK-DAG: <<Sub:i\d+>> InvokeStaticOrDirect [<<Const5>>,<<Const3>>,{{[ij]\d+}}]
/// CHECK-DAG: <<Phi:i\d+>> Phi [<<Add>>,<<Sub>>]
/// CHECK-DAG: Return [<<Phi>>]
/// CHECK-START: int Main.InlineWithControlFlow(boolean) inliner (after)
/// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
/// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
/// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
/// CHECK-DAG: <<Add:i\d+>> Add [<<Const1>>,<<Const3>>]
/// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const5>>,<<Const3>>]
/// CHECK-DAG: <<Phi:i\d+>> Phi [<<Add>>,<<Sub>>]
/// CHECK-DAG: Return [<<Phi>>]
public static int InlineWithControlFlow(boolean cond) {
int x, const1, const3, const5;
const1 = 1;
const3 = 3;
const5 = 5;
if (cond) {
x = returnAdd(const1, const3);
} else {
x = returnSub(const5, const3);
}
return x;
}
/// CHECK-START: int Main.returnAbs(int) intrinsics_recognition (before)
/// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect
/// CHECK-DAG: Return [<<Result>>]
/// CHECK-START: int Main.returnAbs(int) intrinsics_recognition (after)
/// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:MathAbsInt
/// CHECK-DAG: Return [<<Result>>]
private static int returnAbs(int i) {
return Math.abs(i);
}
/// CHECK-START: int Main.InlinedIntrinsicsAreStillIntrinsic() inliner (before)
/// CHECK-DAG: <<ConstMinus1:i\d+>> IntConstant -1
/// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect
/// CHECK-DAG: Return [<<Result>>]
/// CHECK-START: int Main.InlinedIntrinsicsAreStillIntrinsic() inliner (after)
/// CHECK-DAG: <<ConstMinus1:i\d+>> IntConstant -1
/// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:MathAbsInt
/// CHECK-DAG: Return [<<Result>>]
public static int InlinedIntrinsicsAreStillIntrinsic() {
return returnAbs(-1);
}
private static void returnVoid() {
return;
}
private static void returnVoidWithOneParameter(int a) {
return;
}
private static int returnParameter(int a) {
return a;
}
private static long returnWideParameter(long a) {
return a;
}
private static Object returnReferenceParameter(Object o) {
return o;
}
private static int returnInt() {
return 4;
}
private static long returnWide() {
return 8L;
}
private static int returnAdd(int a, int b) {
return a + b;
}
private static int returnSub(int a, int b) {
return a - b;
}
private static int counter = 42;
private static int incCounter() {
return ++counter;
}
public static void main(String[] args) {
InlineVoid();
if (InlineInt() != 4) {
throw new Error();
}
if (InlineWide() != 8L) {
throw new Error();
}
if (InlineParameter(42) != 42) {
throw new Error();
}
if (InlineWideParameter(0x100000001L) != 0x100000001L) {
throw new Error();
}
if (InlineReferenceParameter(Main.class) != Main.class) {
throw new Error();
}
if (InlineAdd() != 8) {
throw new Error();
}
if (InlineFieldAccess() != 43 || InlineFieldAccess() != 44) {
throw new Error();
}
if (InlineWithControlFlow(true) != 4) {
throw new Error();
}
if (InlineWithControlFlow(false) != 2) {
throw new Error();
}
if (InlinedIntrinsicsAreStillIntrinsic() != 1) {
throw new Error();
}
if (returnAbs(-1) != 1) {
throw new Error();
}
}
}
|