Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / teams_distribute_parallel_for_simd_ast_print.cpp
blobf8b49f2b3d37de165ecbab545af2a2d8a07f628e
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
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 -DOMP5 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix CHECK --check-prefix OMP50
5 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -DOMP5 -x c++ -std=c++11 -emit-pch -o %t %s
6 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -DOMP5 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix CHECK --check-prefix OMP50
7 // RUN: %clang_cc1 -verify -fopenmp -DOMP51 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix CHECK --check-prefix OMP51
8 // RUN: %clang_cc1 -fopenmp -DOMP51 -x c++ -std=c++11 -emit-pch -o %t %s
9 // RUN: %clang_cc1 -fopenmp -DOMP51 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix CHECK --check-prefix OMP51
11 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix CHECK --check-prefix OMP45
12 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o %t %s
13 // 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
14 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=50 -DOMP5 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix CHECK --check-prefix OMP50
15 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -DOMP5 -x c++ -std=c++11 -emit-pch -o %t %s
16 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -DOMP5 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix CHECK --check-prefix OMP50
17 // RUN: %clang_cc1 -verify -fopenmp-simd -DOMP51 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix CHECK --check-prefix OMP51
18 // RUN: %clang_cc1 -fopenmp-simd -DOMP51 -x c++ -std=c++11 -emit-pch -o %t %s
19 // RUN: %clang_cc1 -fopenmp-simd -DOMP51 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix CHECK --check-prefix OMP51
20 // expected-no-diagnostics
22 #ifndef HEADER
23 #define HEADER
25 void foo() {}
27 struct S {
28 S(): a(0) {}
29 S(int v) : a(v) {}
30 int a;
31 typedef int type;
34 template <typename T>
35 class S7 : public T {
36 protected:
37 T a;
38 S7() : a(0) {}
40 public:
41 S7(typename T::type v) : a(v) {
42 #pragma omp target
43 #pragma omp teams distribute parallel for simd private(a) private(this->a) private(T::a)
44 for (int k = 0; k < a.a; ++k)
45 ++this->a.a;
47 S7 &operator=(S7 &s) {
48 int k;
49 #pragma omp target
50 #pragma omp teams distribute parallel for simd private(a) private(this->a) linear(k)
51 for (k = 0; k < s.a.a; ++k)
52 ++s.a.a;
54 foo();
55 bar();
56 return *this;
58 void foo() {
59 int b, argv, d, c, e, f;
60 #pragma omp target
61 #pragma omp teams distribute parallel for simd default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
62 for (int k = 0; k < a.a; ++k)
63 ++a.a;
65 void bar() {
66 int arr[10];
67 const int alen = 16;
68 const int slen1 = 8;
69 const int slen2 = 8;
70 #pragma omp target
71 #pragma omp teams distribute parallel for simd simdlen(slen1) safelen(slen2) aligned(arr:alen)
72 for (int k = 0; k < a.a; ++k)
73 ++a.a;
76 // CHECK: #pragma omp target
77 // CHECK-NEXT: #pragma omp teams distribute parallel for simd private(this->a) private(this->a) private(T::a)
78 // CHECK: #pragma omp target
79 // CHECK-NEXT: #pragma omp teams distribute parallel for simd private(this->a) private(this->a) linear(k)
80 // CHECK: #pragma omp target
81 // CHECK-NEXT: #pragma omp teams distribute parallel for simd default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
82 // CHECK: #pragma omp target
83 // CHECK-NEXT: #pragma omp teams distribute parallel for simd simdlen(slen1) safelen(slen2) aligned(arr: alen)
85 class S8 : public S7<S> {
86 S8() {}
88 public:
89 S8(int v) : S7<S>(v){
90 #pragma omp target
91 #pragma omp teams distribute parallel for simd private(a) private(this->a) private(S7<S>::a)
92 for (int k = 0; k < a.a; ++k)
93 ++this->a.a;
95 S8 &operator=(S8 &s) {
96 #pragma omp target
97 #pragma omp teams distribute parallel for simd private(a) private(this->a)
98 for (int k = 0; k < s.a.a; ++k)
99 ++s.a.a;
101 foo();
102 bar();
103 return *this;
105 void bar() {
106 int b, argv, d, c, e, f8;
107 #pragma omp target
108 #pragma omp teams distribute parallel for simd default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f8) thread_limit(d)
109 for (int k = 0; k < a.a; ++k)
110 ++a.a;
112 void foo() {
113 const int alen = 16;
114 const int slen1 = 8;
115 const int slen2 = 8;
116 int arr[10];
117 #pragma omp target
118 #pragma omp teams distribute parallel for simd simdlen(slen1) safelen(slen2) aligned(arr:alen)
119 for (int k = 0; k < a.a; ++k)
120 ++a.a;
123 // CHECK: #pragma omp target
124 // CHECK-NEXT: #pragma omp teams distribute parallel for simd private(this->a) private(this->a) private(this->S::a)
125 // CHECK: #pragma omp target
126 // CHECK-NEXT: #pragma omp teams distribute parallel for simd private(this->a) private(this->a) private(this->S7<S>::a)
127 // CHECK: #pragma omp target
128 // CHECK-NEXT: #pragma omp teams distribute parallel for simd private(this->a) private(this->a)
129 // CHECK: #pragma omp target
130 // CHECK-NEXT: #pragma omp teams distribute parallel for simd default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f8) thread_limit(d)
131 // CHECK: #pragma omp target
132 // CHECK-NEXT: #pragma omp teams distribute parallel for simd simdlen(slen1) safelen(slen2) aligned(arr: alen)
134 template <class T, int N>
135 T tmain(T argc) {
136 T b = argc, c, d, e, f, g;
137 static T a;
138 // CHECK: static T a;
139 const T clen = 5;
140 const T alen = 16;
141 int arr[10];
142 #pragma omp target
143 #pragma omp teams distribute parallel for simd
144 for (int i=0; i < 2; ++i)
145 a = 2;
146 // CHECK: #pragma omp target
147 // CHECK-NEXT: #pragma omp teams distribute parallel for simd{{$}}
148 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
149 // CHECK-NEXT: a = 2;
150 #pragma omp target
151 #pragma omp teams distribute parallel for simd allocate(b) private(argc, b), firstprivate(c, d), collapse(2) allocate(d)
152 for (int i = 0; i < 10; ++i)
153 for (int j = 0; j < 10; ++j)
154 foo();
155 // CHECK: #pragma omp target
156 // CHECK-NEXT: #pragma omp teams distribute parallel for simd allocate(b) private(argc,b) firstprivate(c,d) collapse(2) allocate(d)
157 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
158 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
159 // CHECK-NEXT: foo();
160 for (int i = 0; i < 10; ++i)
161 foo();
162 // CHECK: for (int i = 0; i < 10; ++i)
163 // CHECK-NEXT: foo();
164 #pragma omp target
165 #ifdef OMP51
166 #pragma omp teams distribute parallel for simd if(simd:argc) nontemporal(argc, c, d) order(reproducible:concurrent)
167 #elif OMP5
168 #pragma omp teams distribute parallel for simd if(simd:argc) nontemporal(argc, c, d) order(concurrent)
169 #else
170 #pragma omp teams distribute parallel for simd
171 #endif // OMP51
172 for (int i = 0; i < 10; ++i)
173 foo();
174 // CHECK: #pragma omp target
175 // OMP45-NEXT: #pragma omp teams distribute parallel for simd
176 // OMP50-NEXT: #pragma omp teams distribute parallel for simd if(simd: argc) nontemporal(argc,c,d) order(concurrent)
177 // OMP51-NEXT: #pragma omp teams distribute parallel for simd if(simd: argc) nontemporal(argc,c,d) order(reproducible: concurrent)
178 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
179 // CHECK-NEXT: foo();
180 #pragma omp target
181 #pragma omp teams distribute parallel for simd default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
182 for (int k = 0; k < 10; ++k)
183 e += d + argc;
184 // CHECK: #pragma omp target
185 // CHECK-NEXT: #pragma omp teams distribute parallel for simd default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
186 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
187 // CHECK-NEXT: e += d + argc;
188 #pragma omp target
189 #pragma omp teams distribute parallel for simd simdlen(clen-1)
190 for (int k = 0; k < 10; ++k)
191 e += d + argc;
192 // CHECK: #pragma omp target
193 // CHECK-NEXT: #pragma omp teams distribute parallel for simd simdlen(clen - 1)
194 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
195 // CHECK-NEXT: e += d + argc;
196 #pragma omp target
197 #pragma omp teams distribute parallel for simd safelen(clen-1) aligned(arr:alen)
198 for (int k = 0; k < 10; ++k)
199 e += d + argc + arr[k];
200 // CHECK: #pragma omp target
201 // CHECK-NEXT: #pragma omp teams distribute parallel for simd safelen(clen - 1) aligned(arr: alen)
202 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
203 // CHECK-NEXT: e += d + argc + arr[k];
204 return T();
207 int main (int argc, char **argv) {
208 int b = argc, c, d, e, f, g;
209 static int a;
210 // CHECK: static int a;
211 const int clen = 5;
212 const int N = 10;
213 int arr[10];
214 #pragma omp target
215 #pragma omp teams distribute parallel for simd
216 for (int i=0; i < 2; ++i)
217 a = 2;
218 // CHECK: #pragma omp target
219 // CHECK-NEXT: #pragma omp teams distribute parallel for simd
220 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
221 // CHECK-NEXT: a = 2;
222 #pragma omp target
223 #pragma omp teams distribute parallel for simd private(argc,b),firstprivate(argv, c), collapse(2)
224 for (int i = 0; i < 10; ++i)
225 for (int j = 0; j < 10; ++j)
226 foo();
227 // CHECK: #pragma omp target
228 // CHECK-NEXT: #pragma omp teams distribute parallel for simd private(argc,b) firstprivate(argv,c) collapse(2)
229 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
230 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
231 // CHECK-NEXT: foo();
232 for (int i = 0; i < 10; ++i)
233 foo();
234 // CHECK: for (int i = 0; i < 10; ++i)
235 // CHECK-NEXT: foo();
236 #pragma omp target
237 #pragma omp teams distribute parallel for simd
238 for (int i = 0; i < 10; ++i)foo();
239 // CHECK: #pragma omp target
240 // CHECK-NEXT: #pragma omp teams distribute parallel for simd
241 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
242 // CHECK-NEXT: foo();
243 #pragma omp target
244 #pragma omp teams distribute parallel for simd default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
245 for (int k = 0; k < 10; ++k)
246 e += d + argc;
247 // CHECK: #pragma omp target
248 // CHECK-NEXT: #pragma omp teams distribute parallel for simd default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
249 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
250 // CHECK-NEXT: e += d + argc;
251 #pragma omp target
252 #pragma omp teams distribute parallel for simd simdlen(clen-1)
253 for (int k = 0; k < 10; ++k)
254 e += d + argc;
255 // CHECK: #pragma omp target
256 // CHECK-NEXT: #pragma omp teams distribute parallel for simd simdlen(clen - 1)
257 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
258 // CHECK-NEXT: e += d + argc;
259 #pragma omp target
260 #pragma omp teams distribute parallel for simd safelen(clen-1) aligned(arr:N+6)
261 for (int k = 0; k < 10; ++k)
262 e += d + argc + arr[k];
263 // CHECK: #pragma omp target
264 // CHECK-NEXT: #pragma omp teams distribute parallel for simd safelen(clen - 1) aligned(arr: N + 6)
265 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
266 // CHECK-NEXT: e += d + argc + arr[k];
267 return (0);
270 #endif