1 // expected-no-diagnostics
2 #ifndef HEADER
3 #define HEADER
4 
5 // Test host codegen.
6 // RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-64
7 // RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
8 // RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-64
9 // RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-32
10 // RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
11 // RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-32
12 #ifdef CK1
13 
14 template <typename T, int X, long long Y>
15 struct SS{
16   T a[X];
17   float b;
18   // CK1: define {{.*}}i32 @{{.+}}foo{{.+}}(
19   int foo(void) {
20 
21   // CK1: call i32 @__tgt_target_teams(
22   // CK1: call void @[[OFFL1:.+]](
23     #pragma omp target
24     #pragma omp teams distribute parallel for
25     for(int i = 0; i < X; i++) {
26       a[i] = (T)0;
27     }
28   // CK1: call i32 @__tgt_target_teams(
29   // CK1: call void @[[OFFL2:.+]](
30     #pragma omp target
31     #pragma omp teams distribute parallel for schedule(static)
32     for(int i = 0; i < X; i++) {
33       a[i] = (T)0;
34     }
35   // CK1: call i32 @__tgt_target_teams(
36   // CK1: call void @[[OFFL3:.+]](
37     #pragma omp target
38     #pragma omp teams distribute parallel for schedule(static, X/2)
39     for(int i = 0; i < X; i++) {
40       a[i] = (T)0;
41     }
42 
43   // CK1: call i32 @__tgt_target_teams(
44   // CK1: call void @[[OFFL4:.+]](
45     #pragma omp target
46     #pragma omp teams distribute parallel for schedule(dynamic)
47     for(int i = 0; i < X; i++) {
48       a[i] = (T)0;
49     }
50 
51   // CK1: call i32 @__tgt_target_teams(
52   // CK1: call void @[[OFFL5:.+]](
53     #pragma omp target
54     #pragma omp teams distribute parallel for schedule(dynamic, X/2)
55     for(int i = 0; i < X; i++) {
56       a[i] = (T)0;
57     }
58 
59   // CK1: define internal void @[[OFFL1]](
60   // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL1:.+]] to {{.+}},
61   // CK1: ret void
62 
63   // CK1: define internal void @[[OUTL1]]({{.+}})
64   // CK1: call void @__kmpc_for_static_init_4(
65   // CK1: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL1:.+]] to
66   // CK1: call void @__kmpc_for_static_fini(
67   // CK1: ret void
68 
69   // CK1: define internal void @[[PAR_OUTL1]]({{.+}})
70   // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34,
71   // CK1: call void @__kmpc_for_static_fini(
72   // CK1: ret void
73 
74   // CK1: define internal void @[[OFFL2]](
75   // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL2:.+]] to {{.+}},
76   // CK1: ret void
77 
78   // CK1: define internal void @[[OUTL2]]({{.+}})
79   // CK1: call void @__kmpc_for_static_init_4(
80   // CK1: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL2:.+]] to
81   // CK1: call void @__kmpc_for_static_fini(
82   // CK1: ret void
83 
84   // CK1: define internal void @[[PAR_OUTL2]]({{.+}})
85   // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34,
86   // CK1: call void @__kmpc_for_static_fini(
87   // CK1: ret void
88 
89   // CK1: define internal void @[[OFFL3]](
90   // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL3:.+]] to {{.+}},
91   // CK1: ret void
92 
93   // CK1: define internal void @[[OUTL3]]({{.+}})
94   // CK1: call void @__kmpc_for_static_init_4(
95   // CK1: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL3:.+]] to
96   // CK1: call void @__kmpc_for_static_fini(
97   // CK1: ret void
98 
99   // CK1: define internal void @[[PAR_OUTL3]]({{.+}})
100   // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 33,
101   // CK1: call void @__kmpc_for_static_fini(
102   // CK1: ret void
103 
104   // CK1: define internal void @[[OFFL4]](
105   // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL4:.+]] to {{.+}},
106   // CK1: ret void
107 
108   // CK1: define internal void @[[OUTL4]]({{.+}})
109   // CK1: call void @__kmpc_for_static_init_4(
110   // CK1: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL4:.+]] to
111   // CK1: call void @__kmpc_for_static_fini(
112   // CK1: ret void
113 
114   // CK1: define internal void @[[PAR_OUTL4]]({{.+}})
115   // CK1: call void @__kmpc_dispatch_init_4({{.+}}, {{.+}}, i32 35,
116   // CK1: call {{.+}} @__kmpc_dispatch_next_4(
117   // CK1: ret void
118 
119   // CK1: define internal void @[[OFFL5]](
120   // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL5:.+]] to {{.+}},
121   // CK1: ret void
122 
123   // CK1: define internal void @[[OUTL5]]({{.+}})
124   // CK1: call void @__kmpc_for_static_init_4(
125   // CK1: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL5:.+]] to
126   // CK1: call void @__kmpc_for_static_fini(
127   // CK1: ret void
128 
129   // CK1: define internal void @[[PAR_OUTL5]]({{.+}})
130   // CK1: call void @__kmpc_dispatch_init_4({{.+}}, {{.+}}, i32 35,
131   // CK1: call {{.+}} @__kmpc_dispatch_next_4(
132   // CK1: ret void
133 
134     return a[0];
135   }
136 };
137 
138 int teams_template_struct(void) {
139   SS<int, 123, 456> V;
140   return V.foo();
141 
142 }
143 #endif // CK1
144 
145 // Test host codegen.
146 // RUN: %clang_cc1 -DCK2 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-64
147 // RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
148 // RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-64
149 // RUN: %clang_cc1 -DCK2 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-32
150 // RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
151 // RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-32
152 #ifdef CK2
153 
154 template <typename T, int n>
155 int tmain(T argc) {
156   T a[n];
157   int m = 10;
158 #pragma omp target
159 #pragma omp teams distribute parallel for
160   for(int i = 0; i < n; i++) {
161     a[i] = (T)0;
162   }
163 #pragma omp target
164 #pragma omp teams distribute parallel for schedule(static)
165   for(int i = 0; i < n; i++) {
166     a[i] = (T)0;
167   }
168 #pragma omp target
169 #pragma omp teams distribute parallel for schedule(static, m)
170   for(int i = 0; i < n; i++) {
171     a[i] = (T)0;
172   }
173 #pragma omp target
174 #pragma omp teams distribute parallel for schedule(dynamic)
175   for(int i = 0; i < n; i++) {
176     a[i] = (T)0;
177   }
178 #pragma omp target
179 #pragma omp teams distribute parallel for schedule(dynamic, m)
180   for(int i = 0; i < n; i++) {
181     a[i] = (T)0;
182   }
183   return 0;
184 }
185 
186 int main (int argc, char **argv) {
187   int n = 100;
188   int a[n];
189   int m = 10;
190 #pragma omp target
191 #pragma omp teams distribute parallel for
192   for(int i = 0; i < n; i++) {
193     a[i] = 0;
194   }
195 #pragma omp target
196 #pragma omp teams distribute parallel for dist_schedule(static)
197   for(int i = 0; i < n; i++) {
198     a[i] = 0;
199   }
200 #pragma omp target
201 #pragma omp teams distribute parallel for dist_schedule(static, m)
202   for(int i = 0; i < n; i++) {
203     a[i] = 0;
204   }
205 #pragma omp target
206 #pragma omp teams distribute parallel for schedule(dynamic)
207   for(int i = 0; i < n; i++) {
208     a[i] = 0;
209   }
210 #pragma omp target
211 #pragma omp teams distribute parallel for schedule(dynamic, m)
212   for(int i = 0; i < n; i++) {
213     a[i] = 0;
214   }
215   return tmain<int, 10>(argc);
216 }
217 
218 // CK2: define {{.*}}i32 @{{[^,]+}}(i{{.+}}{{.+}} %[[ARGC:.+]], {{.+}})
219 // CK2: call i32 @__tgt_target_teams(
220 // CK2: call void @[[OFFL1:.+]]({{.+}})
221 // CK2: call i32 @__tgt_target_teams(
222 // CK2: call void @[[OFFL2:.+]]({{.+}})
223 // CK2: call i32 @__tgt_target_teams(
224 // CK2: call void @[[OFFL3:.+]]({{.+}})
225 // CK2: call i32 @__tgt_target_teams(
226 // CK2: call void @[[OFFL4:.+]]({{.+}})
227 // CK2: call i32 @__tgt_target_teams(
228 // CK2: call void @[[OFFL5:.+]]({{.+}})
229 // CK2: {{%.+}} = call{{.*}} i32 @[[TMAIN:.+]]({{.+}})
230 // CK2: ret
231 
232 // CK2:  define {{.*}}void @[[OFFL1]]({{.+}})
233 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 3, {{.+}} @[[OUTL1:.+]] to {{.+}},
234 // CK2: ret void
235 
236 // CK2: define internal void @[[OUTL1]]({{.+}})
237 // CK2: call void @__kmpc_for_static_init_4(
238 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL1:.+]] to
239 // CK2: call void @__kmpc_for_static_fini(
240 // CK2: ret void
241 
242 // CK2: define internal void @[[PAR_OUTL1]]({{.+}})
243 // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34,
244 // CK2: call void @__kmpc_for_static_fini(
245 // CK2: ret void
246 
247 // CK2: define {{.*}}void @[[OFFL2]]({{.+}})
248 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 3, {{.+}} @[[OUTL2:.+]] to {{.+}},
249 // CK2: ret void
250 
251 // CK2: define internal void @[[OUTL2]]({{.+}})
252 // CK2: call void @__kmpc_for_static_init_4(
253 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL2:.+]] to
254 // CK2: call void @__kmpc_for_static_fini(
255 // CK2: ret void
256 
257 // CK2: define internal void @[[PAR_OUTL2]]({{.+}})
258 // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34,
259 // CK2: call void @__kmpc_for_static_fini(
260 // CK2: ret void
261 
262 // CK2:  define {{.*}}void @[[OFFL3]]({{.+}})
263 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 4, {{.+}} @[[OUTL3:.+]] to {{.+}},
264 // CK2: ret void
265 
266 // CK2: define internal void @[[OUTL3]]({{.+}})
267 // CK2: call void @__kmpc_for_static_init_4(
268 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL3:.+]] to
269 // CK2: call void @__kmpc_for_static_fini(
270 // CK2: ret void
271 
272 // CK2: define internal void @[[PAR_OUTL3]]({{.+}})
273 // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34
274 // CK2: call void @__kmpc_for_static_fini(
275 // CK2: ret void
276 
277 // CK2:  define {{.*}}void @[[OFFL4]]({{.+}})
278 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 {{.+}}, {{.+}} @[[OUTL4:.+]] to {{.+}},
279 // CK2: ret void
280 
281 // CK2: define internal void @[[OUTL4]]({{.+}})
282 // CK2: call void @__kmpc_for_static_init_4(
283 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL4:.+]] to
284 // CK2: call void @__kmpc_for_static_fini(
285 // CK2: ret void
286 
287 // CK2: define internal void @[[PAR_OUTL4]]({{.+}})
288 // CK2: call void @__kmpc_dispatch_init_4({{.+}}, {{.+}}, i32 35,
289 // CK2: call {{.+}} @__kmpc_dispatch_next_4(
290 // CK2: ret void
291 
292 
293 // CK2: define {{.*}}void @[[OFFL5]]({{.+}})
294 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 {{.+}}, {{.+}} @[[OUTL5:.+]] to {{.+}},
295 // CK2: ret void
296 
297 // CK2: define internal void @[[OUTL5]]({{.+}})
298 // CK2: call void @__kmpc_for_static_init_4(
299 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL5:.+]] to
300 // CK2: call void @__kmpc_for_static_fini(
301 // CK2: ret void
302 
303 // CK2: define internal void @[[PAR_OUTL5]]({{.+}})
304 // CK2: call void @__kmpc_dispatch_init_4({{.+}}, {{.+}}, i32 35,
305 // CK2: call {{.+}} @__kmpc_dispatch_next_4(
306 // CK2: ret void
307 
308 // CK2: define {{.*}}i32 @[[TMAIN]]({{.+}})
309 // CK2: call i32 @__tgt_target_teams(
310 // CK2: call void @[[OFFLT1:.+]]({{.+}})
311 // CK2: call i32 @__tgt_target_teams(
312 // CK2: call void @[[OFFLT2:.+]]({{.+}})
313 // CK2: call i32 @__tgt_target_teams(
314 // CK2: call void @[[OFFLT3:.+]]({{.+}})
315 // CK2: call i32 @__tgt_target_teams(
316 // CK2: call void @[[OFFLT4:.+]]({{.+}})
317 // CK2: call i32 @__tgt_target_teams(
318 // CK2: call void @[[OFFLT5:.+]]({{.+}})
319 // CK2:  ret
320 // CK2-NEXT: }
321 
322 // CK2:  define {{.*}}void @[[OFFLT1]]({{.+}})
323 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT1:.+]] to {{.+}},
324 // CK2: ret void
325 
326 // CK2: define internal void @[[OUTLT1]]({{.+}})
327 // CK2: call void @__kmpc_for_static_init_4(
328 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTLT1:.+]] to
329 // CK2: call void @__kmpc_for_static_fini(
330 // CK2: ret void
331 
332 // CK2: define internal void @[[PAR_OUTLT1]]({{.+}})
333 // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34,
334 // CK2: call void @__kmpc_for_static_fini(
335 // CK2: ret void
336 
337 // CK2:  define {{.*}}void @[[OFFLT2]]({{.+}})
338 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT2:.+]] to {{.+}},
339 // CK2: ret void
340 
341 // CK2: define internal void @[[OUTLT2]]({{.+}})
342 // CK2: call void @__kmpc_for_static_init_4(
343 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTLT2:.+]] to
344 // CK2: call void @__kmpc_for_static_fini(
345 // CK2: ret void
346 
347 // CK2: define internal void @[[PAR_OUTLT2]]({{.+}})
348 // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34,
349 // CK2: call void @__kmpc_for_static_fini(
350 // CK2: ret void
351 
352 // CK2:  define {{.*}}void @[[OFFLT3]]({{.+}})
353 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 {{.+}}, {{.+}} @[[OUTLT3:.+]] to {{.+}},
354 // CK2: ret void
355 
356 // CK2: define internal void @[[OUTLT3]]({{.+}})
357 // CK2: call void @__kmpc_for_static_init_4(
358 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTLT3:.+]] to
359 // CK2: call void @__kmpc_for_static_fini(
360 // CK2: ret void
361 
362 // CK2: define internal void @[[PAR_OUTLT3]]({{.+}})
363 // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 33,
364 // CK2: call void @__kmpc_for_static_fini(
365 // CK2: ret void
366 
367 // CK2:  define {{.*}}void @[[OFFLT4]]({{.+}})
368 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 {{.+}}, {{.+}} @[[OUTLT4:.+]] to {{.+}},
369 // CK2: ret void
370 
371 // CK2: define internal void @[[OUTLT4]]({{.+}})
372 // CK2: call void @__kmpc_for_static_init_4(
373 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTLT4:.+]] to
374 // CK2: call void @__kmpc_for_static_fini(
375 // CK2: ret void
376 
377 // CK2: define internal void @[[PAR_OUTLT4]]({{.+}})
378 // CK2: call void @__kmpc_dispatch_init_4({{.+}}, {{.+}}, i32 35,
379 // CK2: call {{.+}} @__kmpc_dispatch_next_4(
380 // CK2: ret void
381 
382 // CK2:  define {{.*}}void @[[OFFLT5]]({{.+}})
383 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 {{.+}}, {{.+}} @[[OUTLT5:.+]] to {{.+}},
384 // CK2: ret void
385 
386 // CK2: define internal void @[[OUTLT5]]({{.+}})
387 // CK2: call void @__kmpc_for_static_init_4(
388 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTLT5:.+]] to
389 // CK2: call void @__kmpc_for_static_fini(
390 // CK2: ret void
391 
392 // CK2: define internal void @[[PAR_OUTLT5]]({{.+}})
393 // CK2: call void @__kmpc_dispatch_init_4({{.+}}, {{.+}}, i32 35,
394 // CK2: call {{.+}} @__kmpc_dispatch_next_4(
395 // CK2: ret void
396 
397 #endif // CK2
398 #endif // #ifndef HEADER
399