Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_parallel_for_ast_print.cpp
blob16c2175099acd4e19c66b6003ed66231d83ecdaf
1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
2 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping
3 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
4 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
5 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping -DOMP51
6 // 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
8 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=50 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
9 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping
10 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
11 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
12 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s -Wno-openmp-mapping -DOMP51
13 // 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
14 // expected-no-diagnostics
16 #ifndef HEADER
17 #define HEADER
19 typedef void **omp_allocator_handle_t;
20 extern const omp_allocator_handle_t omp_null_allocator;
21 extern const omp_allocator_handle_t omp_default_mem_alloc;
22 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
23 extern const omp_allocator_handle_t omp_const_mem_alloc;
24 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
25 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
26 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
27 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
28 extern const omp_allocator_handle_t omp_thread_mem_alloc;
30 void foo() {}
32 struct S {
33 S(): a(0) {}
34 S(int v) : a(v) {}
35 int a;
36 typedef int type;
39 template <typename T>
40 class S7 : public T {
41 protected:
42 T a;
43 S7() : a(0) {}
45 public:
46 S7(typename T::type v) : a(v) {
47 #pragma omp target parallel for private(a) private(this->a) private(T::a)
48 for (int k = 0; k < a.a; ++k)
49 ++this->a.a;
51 S7 &operator=(S7 &s) {
52 #pragma omp target parallel for private(a) private(this->a)
53 for (int k = 0; k < s.a.a; ++k)
54 ++s.a.a;
55 return *this;
59 // CHECK: #pragma omp target parallel for private(this->a) private(this->a) private(T::a){{$}}
60 // CHECK: #pragma omp target parallel for private(this->a) private(this->a)
61 // CHECK: #pragma omp target parallel for private(this->a) private(this->a) private(this->S::a)
63 class S8 : public S7<S> {
64 S8() {}
66 public:
67 S8(int v) : S7<S>(v){
68 #pragma omp target parallel for private(a) private(this->a) private(S7<S>::a)
69 for (int k = 0; k < a.a; ++k)
70 ++this->a.a;
72 S8 &operator=(S8 &s) {
73 #pragma omp target parallel for private(a) private(this->a)
74 for (int k = 0; k < s.a.a; ++k)
75 ++s.a.a;
76 return *this;
80 // CHECK: #pragma omp target parallel for private(this->a) private(this->a) private(this->S7<S>::a)
81 // CHECK: #pragma omp target parallel for private(this->a) private(this->a)
83 template <class T, int N>
84 T tmain(T argc, T *argv) {
85 T b = argc, c, d, e, f, h;
86 T arr[N][10], arr1[N];
87 T i, j;
88 T s;
89 static T a;
90 // CHECK: static T a;
91 static T g;
92 #pragma omp threadprivate(g)
93 #ifdef OMP51
94 #pragma omp target parallel for schedule(dynamic) default(none) linear(a) allocate(a) order(reproducible:concurrent)
95 #else
96 #pragma omp target parallel for schedule(dynamic) default(none) linear(a) allocate(a) order(concurrent)
97 #endif // OMP51
98 // OMP51: #pragma omp target parallel for schedule(dynamic) default(none) linear(a) allocate(a) order(reproducible: concurrent)
99 // OMP50: #pragma omp target parallel for schedule(dynamic) default(none) linear(a) allocate(a) order(concurrent)
100 for (int i = 0; i < 2; ++i)
101 a = 2;
102 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
103 // CHECK-NEXT: a = 2;
104 #pragma omp target parallel for allocate(b) private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered(N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h)
105 for (int i = 0; i < 2; ++i)
106 for (int j = 0; j < 2; ++j)
107 for (int j = 0; j < 2; ++j)
108 for (int j = 0; j < 2; ++j)
109 for (int j = 0; j < 2; ++j)
110 for (int i = 0; i < 2; ++i)
111 for (int j = 0; j < 2; ++j)
112 for (int j = 0; j < 2; ++j)
113 for (int j = 0; j < 2; ++j)
114 for (int j = 0; j < 2; ++j)
115 foo();
116 // CHECK-NEXT: #pragma omp target parallel for allocate(b) private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered(N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h)
117 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
118 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
119 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
120 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
121 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
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();
128 #pragma omp target parallel for 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])
129 for (int i = 0; i < 2; ++i) {}
130 // CHECK-NEXT: #pragma omp target parallel for 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])
131 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
132 // CHECK-NEXT: }
133 #pragma omp target parallel for if (N) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:N][:argc]) reduction(&& : h)
134 // CHECK-NEXT: #pragma omp target parallel for if(N) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:N][:argc]) reduction(&&: h)
135 for (int i = 0; i < 2; ++i) {}
136 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
137 // CHECK-NEXT: }
138 #pragma omp target parallel for if (target:argc > 0)
139 // CHECK-NEXT: #pragma omp target parallel for if(target: argc > 0)
140 for (int i = 0; i < 2; ++i) {}
141 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
142 // CHECK-NEXT: }
143 #pragma omp target parallel for if (parallel:argc > 0)
144 // CHECK-NEXT: #pragma omp target parallel for if(parallel: argc > 0)
145 for (int i = 0; i < 2; ++i) {}
146 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
147 // CHECK-NEXT: }
148 #pragma omp target parallel for if (N)
149 // CHECK-NEXT: #pragma omp target parallel for if(N)
150 for (int i = 0; i < 2; ++i) {}
151 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
152 // CHECK-NEXT: }
153 #pragma omp target parallel for map(i)
154 // CHECK-NEXT: #pragma omp target parallel for map(tofrom: i)
155 for (int i = 0; i < 2; ++i) {}
156 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
157 // CHECK-NEXT: }
158 #pragma omp target parallel for map(arr1[0:10], i)
159 // CHECK-NEXT: #pragma omp target parallel for map(tofrom: arr1[0:10],i)
160 for (int i = 0; i < 2; ++i) {}
161 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
162 // CHECK-NEXT: }
163 #pragma omp target parallel for map(to: i) map(from: j)
164 // CHECK-NEXT: #pragma omp target parallel for map(to: i) map(from: j)
165 for (int i = 0; i < 2; ++i) {}
166 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
167 // CHECK-NEXT: }
168 #pragma omp target parallel for map(always,alloc: i)
169 // CHECK-NEXT: #pragma omp target parallel for map(always,alloc: i)
170 for (int i = 0; i < 2; ++i) {}
171 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
172 // CHECK-NEXT: }
173 #pragma omp target parallel for nowait
174 // CHECK-NEXT: #pragma omp target parallel for nowait
175 for (int i = 0; i < 2; ++i) {}
176 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
177 // CHECK-NEXT: }
178 #pragma omp target parallel for depend(in : argc, arr[i:argc], arr1[:])
179 // CHECK-NEXT: #pragma omp target parallel for depend(in : argc,arr[i:argc],arr1[:])
180 for (int i = 0; i < 2; ++i) {}
181 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
182 // CHECK-NEXT: }
183 #pragma omp target parallel for defaultmap(tofrom: scalar)
184 // CHECK-NEXT: #pragma omp target parallel for defaultmap(tofrom: scalar)
185 for (int i = 0; i < 2; ++i) {}
186 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
187 // CHECK-NEXT: }
189 return T();
192 int main(int argc, char **argv) {
193 int b = argc, c, d, e, f, h;
194 int arr[5][10], arr1[5];
195 int i, j;
196 int s;
197 static int a;
198 // CHECK: static int a;
199 static float g;
200 #pragma omp threadprivate(g)
201 #pragma omp target parallel for schedule(guided, argc) default(none) linear(a) shared(argc)
202 // CHECK: #pragma omp target parallel for schedule(guided, argc) default(none) linear(a) shared(argc)
203 for (int i = 0; i < 2; ++i)
204 a = 2;
205 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
206 // CHECK-NEXT: a = 2;
207 #pragma omp target parallel for 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)
208 for (int i = 0; i < 10; ++i)
209 for (int j = 0; j < 10; ++j)
210 foo();
211 // CHECK-NEXT: #pragma omp target parallel for 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))
212 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
213 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
214 // CHECK-NEXT: foo();
215 #pragma omp target parallel for 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])
216 for (int i = 0; i < 2; ++i) {}
217 // CHECK-NEXT: #pragma omp target parallel for 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])
218 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
219 // CHECK-NEXT: }
220 #pragma omp target parallel for if (5) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:5][:argc]) reduction(&& : h) allocate(omp_const_mem_alloc: h) uses_allocators(omp_const_mem_alloc)
221 // CHECK-NEXT: #pragma omp target parallel for if(5) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:5][:argc]) reduction(&&: h) allocate(omp_const_mem_alloc: h) uses_allocators(omp_const_mem_alloc)
222 for (int i = 0; i < 2; ++i) {}
223 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
224 // CHECK-NEXT: }
225 #pragma omp target parallel for if (target:argc > 0)
226 // CHECK-NEXT: #pragma omp target parallel for if(target: argc > 0)
227 for (int i = 0; i < 2; ++i) {}
228 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
229 // CHECK-NEXT: }
230 #pragma omp target parallel for if (parallel:argc > 0)
231 // CHECK-NEXT: #pragma omp target parallel for if(parallel: argc > 0)
232 for (int i = 0; i < 2; ++i) {}
233 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
234 // CHECK-NEXT: }
235 #pragma omp target parallel for if (5)
236 // CHECK-NEXT: #pragma omp target parallel for if(5)
237 for (int i = 0; i < 2; ++i) {}
238 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
239 // CHECK-NEXT: }
240 #pragma omp target parallel for map(i)
241 // CHECK-NEXT: #pragma omp target parallel for map(tofrom: i)
242 for (int i = 0; i < 2; ++i) {}
243 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
244 // CHECK-NEXT: }
245 #pragma omp target parallel for map(arr1[0:10], i)
246 // CHECK-NEXT: #pragma omp target parallel for map(tofrom: arr1[0:10],i)
247 for (int i = 0; i < 2; ++i) {}
248 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
249 // CHECK-NEXT: }
250 #pragma omp target parallel for map(to: i) map(from: j)
251 // CHECK-NEXT: #pragma omp target parallel for map(to: i) map(from: j)
252 for (int i = 0; i < 2; ++i) {}
253 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
254 // CHECK-NEXT: }
255 #pragma omp target parallel for map(always,alloc: i)
256 // CHECK-NEXT: #pragma omp target parallel for map(always,alloc: i)
257 for (int i = 0; i < 2; ++i) {}
258 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
259 // CHECK-NEXT: }
260 #pragma omp target parallel for nowait
261 // CHECK-NEXT: #pragma omp target parallel for nowait
262 for (int i = 0; i < 2; ++i) {}
263 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
264 // CHECK-NEXT: }
265 #pragma omp target parallel for depend(in : argc, arr[i:argc], arr1[:])
266 // CHECK-NEXT: #pragma omp target parallel for depend(in : argc,arr[i:argc],arr1[:])
267 for (int i = 0; i < 2; ++i) {}
268 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
269 // CHECK-NEXT: }
270 #pragma omp target parallel for defaultmap(tofrom: scalar) reduction(task, +: argc)
271 // CHECK-NEXT: #pragma omp target parallel for defaultmap(tofrom: scalar) reduction(task, +: argc)
272 for (int i = 0; i < 2; ++i) {}
273 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
274 // CHECK-NEXT: }
275 return (tmain<int, 5>(argc, &argc) + tmain<char, 1>(argv[0][0], argv[0]));
278 #endif