Debian Codegraph @

clang/test/OpenMP/fuse_ast_print.cpp

raw
1 // Check no warnings/errors
2 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -std=c++20 -fopenmp-version=60 -fsyntax-only -verify %s
3 // expected-no-diagnostics
4
5 // Check AST and unparsing
6 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -std=c++20 -fopenmp-version=60 -ast-dump %s | FileCheck %s --check-prefix=DUMP
7 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -std=c++20 -fopenmp-version=60 -ast-print %s | FileCheck %s --check-prefix=PRINT
8
9 // Check same results after serialization round-trip
10 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -std=c++20 -fopenmp-version=60 -emit-pch -o %t %s
11 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -std=c++20 -fopenmp-version=60 -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP
12 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -std=c++20 -fopenmp-version=60 -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT
13
14 #ifndef HEADER
15 #define HEADER
16
17 // placeholder for loop body code
18 extern "C" void body(...);
19
20 // PRINT-LABEL: void foo1(
21 // DUMP-LABEL: FunctionDecl {{.*}} foo1
22 void foo1() {
23 // PRINT: #pragma omp fuse
24 // DUMP: OMPFuseDirective
25 #pragma omp fuse
26 // PRINT: {
27 // DUMP: CompoundStmt
28 {
29 // PRINT: for (int i = 0; i < 10; i += 2)
30 // DUMP: ForStmt
31 for (int i = 0; i < 10; i += 2)
32 // PRINT: body(i)
33 // DUMP: CallExpr
34 body(i);
35 // PRINT: for (int j = 10; j > 0; --j)
36 // DUMP: ForStmt
37 for (int j = 10; j > 0; --j)
38 // PRINT: body(j)
39 // DUMP: CallExpr
40 body(j);
41 // PRINT: for (int k = 0; k <= 10; ++k)
42 // DUMP: ForStmt
43 for (int k = 0; k <= 10; ++k)
44 // PRINT: body(k)
45 // DUMP: CallExpr
46 body(k);
47
48 }
49
50 }
51
52 // PRINT-LABEL: void foo2(
53 // DUMP-LABEL: FunctionDecl {{.*}} foo2
54 void foo2() {
55 // PRINT: #pragma omp unroll partial(4)
56 // DUMP: OMPUnrollDirective
57 // DUMP-NEXT: OMPPartialClause
58 // DUMP-NEXT: ConstantExpr
59 // DUMP-NEXT: value: Int 4
60 // DUMP-NEXT: IntegerLiteral {{.*}} 4
61 #pragma omp unroll partial(4)
62 // PRINT: #pragma omp fuse
63 // DUMP-NEXT: OMPFuseDirective
64 #pragma omp fuse
65 // PRINT: {
66 // DUMP: CompoundStmt
67 {
68 // PRINT: for (int i = 0; i < 10; i += 2)
69 // DUMP: ForStmt
70 for (int i = 0; i < 10; i += 2)
71 // PRINT: body(i)
72 // DUMP: CallExpr
73 body(i);
74 // PRINT: for (int j = 10; j > 0; --j)
75 // DUMP: ForStmt
76 for (int j = 10; j > 0; --j)
77 // PRINT: body(j)
78 // DUMP: CallExpr
79 body(j);
80 }
81
82 }
83
84 //PRINT-LABEL: void foo3(
85 //DUMP-LABEL: FunctionTemplateDecl {{.*}} foo3
86 template<int Factor1, int Factor2>
87 void foo3() {
88 // PRINT: #pragma omp fuse
89 // DUMP: OMPFuseDirective
90 #pragma omp fuse
91 // PRINT: {
92 // DUMP: CompoundStmt
93 {
94 // PRINT: #pragma omp unroll partial(Factor1)
95 // DUMP: OMPUnrollDirective
96 #pragma omp unroll partial(Factor1)
97 // PRINT: for (int i = 0; i < 12; i += 1)
98 // DUMP: ForStmt
99 for (int i = 0; i < 12; i += 1)
100 // PRINT: body(i)
101 // DUMP: CallExpr
102 body(i);
103 // PRINT: #pragma omp unroll partial(Factor2)
104 // DUMP: OMPUnrollDirective
105 #pragma omp unroll partial(Factor2)
106 // PRINT: for (int k = 0; k <= 10; ++k)
107 // DUMP: ForStmt
108 for (int k = 0; k <= 10; ++k)
109 // PRINT: body(k)
110 // DUMP: CallExpr
111 body(k);
112
113 }
114 }
115
116 // Also test instantiating the template.
117 void tfoo3() {
118 foo3<4,2>();
119 }
120
121 //PRINT-LABEL: void foo4(
122 //DUMP-LABEL: FunctionTemplateDecl {{.*}} foo4
123 template<typename T, T Step>
124 void foo4(int start, int end) {
125 // PRINT: #pragma omp fuse
126 // DUMP: OMPFuseDirective
127 #pragma omp fuse
128 // PRINT: {
129 // DUMP: CompoundStmt
130 {
131 // PRINT: for (T i = start; i < end; i += Step)
132 // DUMP: ForStmt
133 for (T i = start; i < end; i += Step)
134 // PRINT: body(i)
135 // DUMP: CallExpr
136 body(i);
137
138 // PRINT: for (T j = end; j > start; j -= Step)
139 // DUMP: ForStmt
140 for (T j = end; j > start; j -= Step) {
141 // PRINT: body(j)
142 // DUMP: CallExpr
143 body(j);
144 }
145
146 }
147 }
148
149 // Also test instantiating the template.
150 void tfoo4() {
151 foo4<int, 4>(0, 64);
152 }
153
154
155
156 // PRINT-LABEL: void foo5(
157 // DUMP-LABEL: FunctionDecl {{.*}} foo5
158 void foo5() {
159 double arr[128], arr2[128];
160 // PRINT: #pragma omp fuse
161 // DUMP: OMPFuseDirective
162 #pragma omp fuse
163 // PRINT: {
164 // DUMP: CompoundStmt
165 {
166 // PRINT-NEXT: for (auto &&a : arr)
167 // DUMP-NEXT: CXXForRangeStmt
168 for (auto &&a: arr)
169 // PRINT: body(a)
170 // DUMP: CallExpr
171 body(a);
172 // PRINT: for (double v = 42; auto &&b : arr)
173 // DUMP: CXXForRangeStmt
174 for (double v = 42; auto &&b: arr)
175 // PRINT: body(b, v);
176 // DUMP: CallExpr
177 body(b, v);
178 // PRINT: for (auto &&c : arr2)
179 // DUMP: CXXForRangeStmt
180 for (auto &&c: arr2)
181 // PRINT: body(c)
182 // DUMP: CallExpr
183 body(c);
184
185 }
186
187 }
188
189 // PRINT-LABEL: void foo6(
190 // DUMP-LABEL: FunctionDecl {{.*}} foo6
191 void foo6() {
192 // PRINT: #pragma omp fuse
193 // DUMP: OMPFuseDirective
194 #pragma omp fuse
195 // PRINT: {
196 // DUMP: CompoundStmt
197 {
198 // PRINT: #pragma omp fuse
199 // DUMP: OMPFuseDirective
200 #pragma omp fuse
201 // PRINT: {
202 // DUMP: CompoundStmt
203 {
204 // PRINT: for (int i = 0; i <= 10; ++i)
205 // DUMP: ForStmt
206 for (int i = 0; i <= 10; ++i)
207 body(i);
208 // PRINT: for (int j = 0; j < 100; ++j)
209 // DUMP: ForStmt
210 for(int j = 0; j < 100; ++j)
211 body(j);
212 }
213 // PRINT: #pragma omp unroll partial(4)
214 // DUMP: OMPUnrollDirective
215 #pragma omp unroll partial(4)
216 // PRINT: for (int k = 0; k < 250; ++k)
217 // DUMP: ForStmt
218 for (int k = 0; k < 250; ++k)
219 body(k);
220 }
221 }
222
223 // PRINT-LABEL: void foo7(
224 // DUMP-LABEL: FunctionDecl {{.*}} foo7
225 void foo7() {
226 // PRINT: #pragma omp fuse
227 // DUMP: OMPFuseDirective
228 #pragma omp fuse
229 // PRINT: {
230 // DUMP: CompoundStmt
231 {
232 // PRINT: {
233 // DUMP: CompoundStmt
234 {
235 // PRINT: {
236 // DUMP: CompoundStmt
237 {
238 // PRINT: for (int i = 0; i < 10; i += 2)
239 // DUMP: ForStmt
240 for (int i = 0; i < 10; i += 2)
241 // PRINT: body(i)
242 // DUMP: CallExpr
243 body(i);
244 // PRINT: for (int j = 10; j > 0; --j)
245 // DUMP: ForStmt
246 for (int j = 10; j > 0; --j)
247 // PRINT: body(j)
248 // DUMP: CallExpr
249 body(j);
250 }
251 }
252 // PRINT: {
253 // DUMP: CompoundStmt
254 {
255 // PRINT: {
256 // DUMP: CompoundStmt
257 {
258 // PRINT: {
259 // DUMP: CompoundStmt
260 {
261 // PRINT: for (int k = 0; k <= 10; ++k)
262 // DUMP: ForStmt
263 for (int k = 0; k <= 10; ++k)
264 // PRINT: body(k)
265 // DUMP: CallExpr
266 body(k);
267 }
268 }
269 }
270 }
271
272 }
273
274 // PRINT-LABEL: void foo8(
275 // DUMP-LABEL: FunctionDecl {{.*}} foo8
276 void foo8() {
277 // PRINT: #pragma omp fuse looprange(2,2)
278 // DUMP: OMPFuseDirective
279 // DUMP: OMPLooprangeClause
280 #pragma omp fuse looprange(2,2)
281 // PRINT: {
282 // DUMP: CompoundStmt
283 {
284 // PRINT: for (int i = 0; i < 10; i += 2)
285 // DUMP: ForStmt
286 for (int i = 0; i < 10; i += 2)
287 // PRINT: body(i)
288 // DUMP: CallExpr
289 body(i);
290 // PRINT: for (int j = 10; j > 0; --j)
291 // DUMP: ForStmt
292 for (int j = 10; j > 0; --j)
293 // PRINT: body(j)
294 // DUMP: CallExpr
295 body(j);
296 // PRINT: for (int k = 0; k <= 10; ++k)
297 // DUMP: ForStmt
298 for (int k = 0; k <= 10; ++k)
299 // PRINT: body(k)
300 // DUMP: CallExpr
301 body(k);
302
303 }
304
305 }
306
307 //PRINT-LABEL: void foo9(
308 //DUMP-LABEL: FunctionTemplateDecl {{.*}} foo9
309 //DUMP-LABEL: NonTypeTemplateParmDecl {{.*}} F
310 //DUMP-LABEL: NonTypeTemplateParmDecl {{.*}} C
311 template<int F, int C>
312 void foo9() {
313 // PRINT: #pragma omp fuse looprange(F,C)
314 // DUMP: OMPFuseDirective
315 // DUMP: OMPLooprangeClause
316 #pragma omp fuse looprange(F,C)
317 // PRINT: {
318 // DUMP: CompoundStmt
319 {
320 // PRINT: for (int i = 0; i < 10; i += 2)
321 // DUMP: ForStmt
322 for (int i = 0; i < 10; i += 2)
323 // PRINT: body(i)
324 // DUMP: CallExpr
325 body(i);
326 // PRINT: for (int j = 10; j > 0; --j)
327 // DUMP: ForStmt
328 for (int j = 10; j > 0; --j)
329 // PRINT: body(j)
330 // DUMP: CallExpr
331 body(j);
332
333 }
334 }
335
336 // Also test instantiating the template.
337 void tfoo9() {
338 foo9<1, 2>();
339 }
340
341 // PRINT-LABEL: void foo10(
342 // DUMP-LABEL: FunctionDecl {{.*}} foo10
343 void foo10() {
344 // PRINT: #pragma omp fuse looprange(2,2)
345 // DUMP: OMPFuseDirective
346 // DUMP: OMPLooprangeClause
347 #pragma omp fuse looprange(2,2)
348 // PRINT: {
349 // DUMP: CompoundStmt
350 {
351 // PRINT: for (int i = 0; i < 10; i += 2)
352 // DUMP: ForStmt
353 for (int i = 0; i < 10; i += 2)
354 // PRINT: body(i)
355 // DUMP: CallExpr
356 body(i);
357 // PRINT: for (int ii = 0; ii < 10; ii += 2)
358 // DUMP: ForStmt
359 for (int ii = 0; ii < 10; ii += 2)
360 // PRINT: body(ii)
361 // DUMP: CallExpr
362 body(ii);
363 // PRINT: #pragma omp fuse looprange(2,2)
364 // DUMP: OMPFuseDirective
365 // DUMP: OMPLooprangeClause
366 #pragma omp fuse looprange(2,2)
367 {
368 // PRINT: for (int j = 10; j > 0; --j)
369 // DUMP: ForStmt
370 for (int j = 10; j > 0; --j)
371 // PRINT: body(j)
372 // DUMP: CallExpr
373 body(j);
374 // PRINT: for (int jj = 10; jj > 0; --jj)
375 // DUMP: ForStmt
376 for (int jj = 10; jj > 0; --jj)
377 // PRINT: body(jj)
378 // DUMP: CallExpr
379 body(jj);
380 // PRINT: for (int k = 0; k <= 10; ++k)
381 // DUMP: ForStmt
382 for (int k = 0; k <= 10; ++k)
383 // PRINT: body(k)
384 // DUMP: CallExpr
385 body(k);
386 // PRINT: for (int kk = 0; kk <= 10; ++kk)
387 // DUMP: ForStmt
388 for (int kk = 0; kk <= 10; ++kk)
389 // PRINT: body(kk)
390 // DUMP: CallExpr
391 body(kk);
392 }
393 }
394
395 }
396
397 #endif