Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_parallel_for_simd_ast_print.cpp
blobc3b115dafa0912b05bbf9c87969361a4e730c124
1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
2 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping
3 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
4 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -ast-print %s -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
5 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping -DOMP5
6 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
7 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
8 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping -DOMP51
9 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
10 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -ast-print %s -Wno-openmp-mapping -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
11 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping -DOMP52
12 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
14 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
15 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping
16 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
17 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=50 -ast-print %s -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
18 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping -DOMP5
19 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
20 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
21 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping -DOMP51
22 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
23 // expected-no-diagnostics
24 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -ast-print %s -Wno-openmp-mapping -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
25 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping -DOMP52
26 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
27 // expected-no-diagnostics
29 #ifndef HEADER
30 #define HEADER
32 typedef void **omp_allocator_handle_t;
33 extern const omp_allocator_handle_t omp_null_allocator;
34 extern const omp_allocator_handle_t omp_default_mem_alloc;
35 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
36 extern const omp_allocator_handle_t omp_const_mem_alloc;
37 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
38 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
39 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
40 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
41 extern const omp_allocator_handle_t omp_thread_mem_alloc;
43 void foo() {}
45 struct S {
46 S(): a(0) {}
47 S(int v) : a(v) {}
48 int a;
49 typedef int type;
52 template <typename T>
53 class S7 : public T {
54 protected:
55 T a;
56 S7() : a(0) {}
58 public:
59 S7(typename T::type v) : a(v) {
60 #pragma omp target parallel for simd private(a) private(this->a) private(T::a)
61 for (int k = 0; k < a.a; ++k)
62 ++this->a.a;
64 S7 &operator=(S7 &s) {
65 #pragma omp target parallel for simd private(a) private(this->a)
66 for (int k = 0; k < s.a.a; ++k)
67 ++s.a.a;
68 return *this;
72 // CHECK: #pragma omp target parallel for simd private(this->a) private(this->a) private(T::a){{$}}
73 // CHECK: #pragma omp target parallel for simd private(this->a) private(this->a)
74 // CHECK: #pragma omp target parallel for simd private(this->a) private(this->a) private(this->S::a)
76 class S8 : public S7<S> {
77 S8() {}
79 public:
80 S8(int v) : S7<S>(v){
81 #pragma omp target parallel for simd private(a) private(this->a) private(S7<S>::a)
82 for (int k = 0; k < a.a; ++k)
83 ++this->a.a;
85 S8 &operator=(S8 &s) {
86 #pragma omp target parallel for simd private(a) private(this->a)
87 for (int k = 0; k < s.a.a; ++k)
88 ++s.a.a;
89 return *this;
93 // CHECK: #pragma omp target parallel for simd private(this->a) private(this->a) private(this->S7<S>::a)
94 // CHECK: #pragma omp target parallel for simd private(this->a) private(this->a)
96 template <class T, int N>
97 T tmain(T argc, T *argv) {
98 T b = argc, c, d, e, f, h;
99 T arr[N][10], arr1[N];
100 T i, j;
101 T s;
102 static T a;
103 // CHECK: static T a;
104 static T g;
105 const T clen = 5;
106 // CHECK: T clen = 5;
107 #pragma omp threadprivate(g)
108 #pragma omp target parallel for simd schedule(dynamic) default(none) linear(a) allocate(a)
109 // CHECK: #pragma omp target parallel for simd schedule(dynamic) default(none) linear(a) allocate(a)
110 for (T i = 0; i < 2; ++i)
111 a = 2;
112 // CHECK-NEXT: for (T i = 0; i < 2; ++i)
113 // CHECK-NEXT: a = 2;
114 #pragma omp target parallel for simd allocate(d) private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h)
115 for (int i = 0; i < 2; ++i)
116 for (int j = 0; j < 2; ++j)
117 for (int j = 0; j < 2; ++j)
118 for (int j = 0; j < 2; ++j)
119 for (int j = 0; j < 2; ++j)
120 foo();
121 // CHECK-NEXT: #pragma omp target parallel for simd allocate(d) private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h)
122 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
123 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
124 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
125 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
126 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
127 // CHECK-NEXT: foo();
129 #pragma omp target parallel for simd default(none), private(argc,b) firstprivate(argv) shared (d) if(parallel:argc > 0) num_threads(N) proc_bind(master) reduction(+:c, arr1[argc]) reduction(max:e, arr[:N][0:10])
130 for (T i = 0; i < 2; ++i) {}
131 // CHECK: #pragma omp target parallel for simd default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(N) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:N][0:10])
132 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
133 // CHECK-NEXT: }
135 #pragma omp target parallel for simd if(N) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:N][:argc]) reduction(&& : h)
136 for (T i = 0; i < 2; ++i) {}
137 // CHECK: #pragma omp target parallel for simd if(N) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:N][:argc]) reduction(&&: h)
138 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
139 // CHECK-NEXT: }
141 #if defined(OMP51) || defined(OMP52)
142 #pragma omp target parallel for simd if(target:argc > 0) if (simd: argc) nontemporal(argc, c, d) order(unconstrained:concurrent) allocate(omp_high_bw_mem_alloc:f) private(f) uses_allocators(omp_high_bw_mem_alloc)
143 #elif OMP5
144 #pragma omp target parallel for simd if(target:argc > 0) if (simd: argc) nontemporal(argc, c, d) order(concurrent) allocate(omp_high_bw_mem_alloc:f) private(f) uses_allocators(omp_high_bw_mem_alloc)
145 #else
146 #pragma omp target parallel for simd if(target:argc > 0)
147 #endif // OMP51
148 for (T i = 0; i < 2; ++i) {}
149 // OMP45: #pragma omp target parallel for simd if(target: argc > 0)
150 // OMP50: #pragma omp target parallel for simd if(target: argc > 0) if(simd: argc) nontemporal(argc,c,d) order(concurrent) allocate(omp_high_bw_mem_alloc: f) private(f) uses_allocators(omp_high_bw_mem_alloc)
151 // OMP51: #pragma omp target parallel for simd if(target: argc > 0) if(simd: argc) nontemporal(argc,c,d) order(unconstrained: concurrent) allocate(omp_high_bw_mem_alloc: f) private(f) uses_allocators(omp_high_bw_mem_alloc)
152 // OMP52: #pragma omp target parallel for simd if(target: argc > 0) if(simd: argc) nontemporal(argc,c,d) order(unconstrained: concurrent) allocate(omp_high_bw_mem_alloc: f) private(f) uses_allocators(omp_high_bw_mem_alloc)
153 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
154 // CHECK-NEXT: }
156 #pragma omp target parallel for simd if(parallel:argc > 0)
157 for (T i = 0; i < 2; ++i) {}
158 // CHECK: #pragma omp target parallel for simd if(parallel: argc > 0)
159 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
160 // CHECK-NEXT: }
162 #pragma omp target parallel for simd if(N)
163 for (T i = 0; i < 2; ++i) {}
164 // CHECK: #pragma omp target parallel for simd if(N)
165 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
166 // CHECK-NEXT: }
168 #pragma omp target parallel for simd map(i)
169 for (T i = 0; i < 2; ++i) {}
170 // CHECK: #pragma omp target parallel for simd map(tofrom: i)
171 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
172 // CHECK-NEXT: }
174 #pragma omp target parallel for simd map(arr1[0:10], i)
175 for (T i = 0; i < 2; ++i) {}
176 // CHECK: #pragma omp target parallel for simd map(tofrom: arr1[0:10],i)
177 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
178 // CHECK-NEXT: }
180 #pragma omp target parallel for simd map(to: i) map(from: j)
181 for (T i = 0; i < 2; ++i) {}
182 // CHECK: #pragma omp target parallel for simd map(to: i) map(from: j)
183 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
184 // CHECK-NEXT: }
186 #pragma omp target parallel for simd map(always,alloc: i)
187 for (T i = 0; i < 2; ++i) {}
188 // CHECK: #pragma omp target parallel for simd map(always,alloc: i)
189 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
190 // CHECK-NEXT: }
192 #pragma omp target parallel for simd nowait
193 for (T i = 0; i < 2; ++i) {}
194 // CHECK: #pragma omp target parallel for simd nowait
195 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
196 // CHECK-NEXT: }
198 #pragma omp target parallel for simd depend(in : argc, arr[i:argc], arr1[:])
199 for (T i = 0; i < 2; ++i) {}
200 // CHECK: #pragma omp target parallel for simd depend(in : argc,arr[i:argc],arr1[:])
201 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
202 // CHECK-NEXT: }
204 #pragma omp target parallel for simd defaultmap(tofrom: scalar)
205 for (T i = 0; i < 2; ++i) {}
206 // CHECK: #pragma omp target parallel for simd defaultmap(tofrom: scalar)
207 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
208 // CHECK-NEXT: }
210 #pragma omp target parallel for simd safelen(clen-1)
211 for (T i = 0; i < 2; ++i) {}
212 // CHECK: #pragma omp target parallel for simd safelen(clen - 1)
213 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
214 // CHECK-NEXT: }
216 #pragma omp target parallel for simd simdlen(clen-1)
217 for (T i = 0; i < 2; ++i) {}
218 // CHECK: #pragma omp target parallel for simd simdlen(clen - 1)
219 // CHECK-NEXT: for (T i = 0; i < 2; ++i) {
220 // CHECK-NEXT: }
222 #pragma omp target parallel for simd aligned(arr1:N-1)
223 for (T i = 0; i < N; ++i) {}
224 // CHECK: #pragma omp target parallel for simd aligned(arr1: N - 1)
225 // CHECK-NEXT: for (T i = 0; i < N; ++i) {
226 // CHECK-NEXT: }
228 return T();
231 int main(int argc, char **argv) {
232 int b = argc, c, d, e, f, h;
233 int arr[5][10], arr1[5];
234 int i, j;
235 int s;
236 static int a;
237 // CHECK: static int a;
238 const int clen = 5;
239 // CHECK: int clen = 5;
240 static float g;
241 #pragma omp threadprivate(g)
242 #pragma omp target parallel for simd schedule(guided, argc) default(none) linear(a) shared(argc)
243 // CHECK: #pragma omp target parallel for simd schedule(guided, argc) default(none) linear(a) shared(argc)
244 for (int i = 0; i < 2; ++i)
245 a = 2;
246 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
247 // CHECK-NEXT: a = 2;
248 #ifdef OMP52
249 #pragma omp target parallel for simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) ordered if (target: argc) num_threads(a) default(shared) shared(e) reduction(+ : h) linear(a: step(-5))
250 #else
251 #pragma omp target parallel for simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) ordered if (target: argc) num_threads(a) default(shared) shared(e) reduction(+ : h) linear(a:-5)
252 #endif
253 for (int i = 0; i < 10; ++i)
254 for (int j = 0; j < 10; ++j)
255 foo();
256 // CHECK: #pragma omp target parallel for simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) ordered if(target: argc) num_threads(a) default(shared) shared(e) reduction(+: h) linear(a: step(-5))
257 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
258 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
259 // CHECK-NEXT: foo();
261 #pragma omp target parallel for simd default(none), private(argc,b) firstprivate(argv) shared (d) if (parallel:argc > 0) num_threads(5) proc_bind(master) reduction(+:c, arr1[argc]) reduction(max:e, arr[:5][0:10])
262 for (int i = 0; i < 2; ++i) {}
263 // CHECK: #pragma omp target parallel for simd default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(5) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:5][0:10])
264 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
265 // CHECK-NEXT: }
267 #pragma omp target parallel for simd if (5) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:5][:argc]) reduction(&& : h)
268 for (int i = 0; i < 2; ++i) {}
269 // CHECK: #pragma omp target parallel for simd if(5) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:5][:argc]) reduction(&&: h)
270 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
271 // CHECK-NEXT: }
273 #pragma omp target parallel for simd if (target:argc > 0)
274 for (int i = 0; i < 2; ++i) {}
275 // CHECK: #pragma omp target parallel for simd if(target: argc > 0)
276 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
277 // CHECK-NEXT: }
279 #if defined(OMP51) || defined(OMP52)
280 #pragma omp target parallel for simd if (parallel:argc > 0)
281 #elif OMP5
282 #pragma omp target parallel for simd if (parallel:argc > 0) if(simd: argc)
283 #else
284 #pragma omp target parallel for simd if (parallel:argc > 0)
285 #endif // OMP51
286 for (int i = 0; i < 2; ++i) {}
287 // OMP45: #pragma omp target parallel for simd if(parallel: argc > 0)
288 // OMP50: #pragma omp target parallel for simd if(parallel: argc > 0) if(simd: argc)
289 // OMP51: #pragma omp target parallel for simd if(parallel: argc > 0)
290 // OMP52: #pragma omp target parallel for simd if(parallel: argc > 0)
291 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
292 // CHECK-NEXT: }
294 #pragma omp target parallel for simd if (5)
295 for (int i = 0; i < 2; ++i) {}
296 // CHECK: #pragma omp target parallel for simd if(5)
297 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
298 // CHECK-NEXT: }
300 #pragma omp target parallel for simd map(i)
301 for (int i = 0; i < 2; ++i) {}
302 // CHECK: #pragma omp target parallel for simd map(tofrom: i)
303 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
304 // CHECK-NEXT: }
306 #pragma omp target parallel for simd map(arr1[0:10], i)
307 for (int i = 0; i < 2; ++i) {}
308 // CHECK: #pragma omp target parallel for simd map(tofrom: arr1[0:10],i)
309 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
310 // CHECK-NEXT: }
312 #pragma omp target parallel for simd map(to: i) map(from: j)
313 for (int i = 0; i < 2; ++i) {}
314 // CHECK: #pragma omp target parallel for simd map(to: i) map(from: j)
315 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
316 // CHECK-NEXT: }
318 #pragma omp target parallel for simd map(always,alloc: i)
319 for (int i = 0; i < 2; ++i) {}
320 // CHECK: #pragma omp target parallel for simd map(always,alloc: i)
321 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
322 // CHECK-NEXT: }
324 #pragma omp target parallel for simd nowait
325 for (int i = 0; i < 2; ++i) {}
326 // CHECK: #pragma omp target parallel for simd nowait
327 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
328 // CHECK-NEXT: }
330 #pragma omp target parallel for simd depend(in : argc, arr[i:argc], arr1[:])
331 for (int i = 0; i < 2; ++i) {}
332 // CHECK: #pragma omp target parallel for simd depend(in : argc,arr[i:argc],arr1[:])
333 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
334 // CHECK-NEXT: }
336 #pragma omp target parallel for simd defaultmap(tofrom: scalar)
337 for (int i = 0; i < 2; ++i) {}
338 // CHECK: #pragma omp target parallel for simd defaultmap(tofrom: scalar)
339 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
340 // CHECK-NEXT: }
342 #pragma omp target parallel for simd safelen(clen-1)
343 for (int i = 0; i < 2; ++i) {}
344 // CHECK: #pragma omp target parallel for simd safelen(clen - 1)
345 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
346 // CHECK-NEXT: }
348 #pragma omp target parallel for simd simdlen(clen-1)
349 for (int i = 0; i < 2; ++i) {}
350 // CHECK: #pragma omp target parallel for simd simdlen(clen - 1)
351 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
352 // CHECK-NEXT: }
354 #pragma omp target parallel for simd aligned(arr1:4)
355 for (int i = 0; i < 2; ++i) {}
356 // CHECK: #pragma omp target parallel for simd aligned(arr1: 4)
357 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
358 // CHECK-NEXT: }
360 return (tmain<int, 5>(argc, &argc));
363 #endif