[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / teams_distribute_simd_ast_print.cpp
blob4836d772da1e6ea3998e9540e9ca280627db1d54
1 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -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 -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 -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
11 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
12 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
13 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -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 -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 -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 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 simd private(a) private(this->a) linear(k)
51 for (k = 0; k < s.a.a; ++k)
52 ++s.a.a;
53 return *this;
55 void foo() {
56 int b, argv, d, c, e, f;
57 #pragma omp target
58 #pragma omp teams distribute simd default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
59 for (int k = 0; k < a.a; ++k)
60 ++a.a;
62 void bar() {
63 int arr[10];
64 const int alen = 16;
65 const int slen1 = 8;
66 const int slen2 = 8;
67 #pragma omp target
68 #ifdef OMP5
69 #pragma omp teams distribute simd simdlen(slen1) safelen(slen2) aligned(arr:alen) if(arr[0])
70 #else
71 #pragma omp teams distribute simd simdlen(slen1) safelen(slen2) aligned(arr:alen)
72 #endif // OMP5
73 for (int k = 0; k < a.a; ++k)
74 ++a.a;
77 // CHECK: #pragma omp target
78 // CHECK-NEXT: #pragma omp teams distribute simd private(this->a) private(this->a) private(T::a)
79 // CHECK: #pragma omp target
80 // CHECK-NEXT: #pragma omp teams distribute simd private(this->a) private(this->a) linear(k)
81 // CHECK: #pragma omp target
82 // CHECK-NEXT: #pragma omp teams distribute simd default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
83 // CHECK: #pragma omp target
84 // OMP45-NEXT: #pragma omp teams distribute simd simdlen(slen1) safelen(slen2) aligned(arr: alen)
85 // OMP50-NEXT: #pragma omp teams distribute simd simdlen(slen1) safelen(slen2) aligned(arr: alen) if(arr[0])
86 // CHECK: #pragma omp target
87 // CHECK-NEXT: #pragma omp teams distribute simd private(this->a) private(this->a) private(this->S::a)
89 class S8 : public S7<S> {
90 S8() {}
92 public:
93 S8(int v) : S7<S>(v){
94 #pragma omp target
95 #pragma omp teams distribute simd private(a) private(this->a) private(S7 <S>::a)
96 for (int k = 0; k < a.a; ++k)
97 ++this->a.a;
99 S8 &operator=(S8 &s) {
100 #pragma omp target
101 #pragma omp teams distribute simd private(a) private(this->a)
102 for (int k = 0; k < s.a.a; ++k)
103 ++s.a.a;
104 return *this;
106 void bar() {
107 int b, argv, d, c, e, f;
108 #pragma omp target
109 #pragma omp teams distribute simd default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
110 for (int k = 0; k < a.a; ++k)
111 ++a.a;
113 void foo() {
114 const int alen = 16;
115 const int slen1 = 8;
116 const int slen2 = 8;
117 int arr[10];
118 #pragma omp target
119 #pragma omp teams distribute simd simdlen(slen1) safelen(slen2) aligned(arr:alen)
120 for (int k = 0; k < a.a; ++k)
121 ++a.a;
124 // CHECK: #pragma omp target
125 // CHECK-NEXT: #pragma omp teams distribute simd private(this->a) private(this->a) private(this->S7<S>::a)
126 // CHECK: #pragma omp target
127 // CHECK-NEXT: #pragma omp teams distribute simd private(this->a) private(this->a)
128 // CHECK: #pragma omp target
129 // CHECK-NEXT: #pragma omp teams distribute simd default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
130 // CHECK: #pragma omp target
131 // CHECK-NEXT: #pragma omp teams distribute simd simdlen(slen1) safelen(slen2) aligned(arr: alen)
133 template <class T, int N>
134 T tmain(T argc) {
135 T b = argc, c, d, e, f, g;
136 static T a;
137 // CHECK: static T a;
138 const T clen = 5;
139 const T alen = 16;
140 int arr[10];
141 #pragma omp target
142 #pragma omp teams distribute simd
143 for (int i=0; i < 2; ++i)
144 a = 2;
145 // CHECK: #pragma omp target
146 // CHECK-NEXT: #pragma omp teams distribute simd{{$}}
147 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
148 // CHECK-NEXT: a = 2;
149 #pragma omp target
150 #pragma omp teams distribute simd allocate(b) private(argc, b), firstprivate(c, d), collapse(2) allocate(c)
151 for (int i = 0; i < 10; ++i)
152 for (int j = 0; j < 10; ++j)
153 foo();
154 // CHECK: #pragma omp target
155 // CHECK-NEXT: #pragma omp teams distribute simd allocate(b) private(argc,b) firstprivate(c,d) collapse(2) allocate(c)
156 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
157 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
158 // CHECK-NEXT: foo();
159 for (int i = 0; i < 10; ++i)
160 foo();
161 // CHECK: for (int i = 0; i < 10; ++i)
162 // CHECK-NEXT: foo();
163 #pragma omp target
164 #pragma omp teams distribute simd
165 for (int i = 0; i < 10; ++i)
166 foo();
167 // CHECK: #pragma omp target
168 // CHECK-NEXT: #pragma omp teams distribute simd
169 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
170 // CHECK-NEXT: foo();
171 #pragma omp target
172 #pragma omp teams distribute simd default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
173 for (int k = 0; k < 10; ++k)
174 e += d + argc;
175 // CHECK: #pragma omp target
176 // CHECK-NEXT: #pragma omp teams distribute simd default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
177 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
178 // CHECK-NEXT: e += d + argc;
179 #pragma omp target
180 #pragma omp teams distribute simd simdlen(clen-1)
181 for (int k = 0; k < 10; ++k)
182 e += d + argc;
183 // CHECK: #pragma omp target
184 // CHECK-NEXT: #pragma omp teams distribute simd simdlen(clen - 1)
185 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
186 // CHECK-NEXT: e += d + argc;
187 #pragma omp target
188 #pragma omp teams distribute simd safelen(clen-1) aligned(arr:alen)
189 for (int k = 0; k < 10; ++k)
190 e += d + argc + arr[k];
191 // CHECK: #pragma omp target
192 // CHECK-NEXT: #pragma omp teams distribute simd safelen(clen - 1) aligned(arr: alen)
193 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
194 // CHECK-NEXT: e += d + argc + arr[k];
195 return T();
198 int main (int argc, char **argv) {
199 int b = argc, c, d, e, f, g;
200 static int a;
201 // CHECK: static int a;
202 const int clen = 5;
203 const int N = 10;
204 int arr[10];
205 #pragma omp target
206 #pragma omp teams distribute simd
207 for (int i=0; i < 2; ++i)
208 a = 2;
209 // CHECK: #pragma omp target
210 // CHECK-NEXT: #pragma omp teams distribute simd
211 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
212 // CHECK-NEXT: a = 2;
213 #pragma omp target
214 #pragma omp teams distribute simd private(argc,b),firstprivate(argv, c), collapse(2)
215 for (int i = 0; i < 10; ++i)
216 for (int j = 0; j < 10; ++j)
217 foo();
218 // CHECK: #pragma omp target
219 // CHECK-NEXT: #pragma omp teams distribute simd private(argc,b) firstprivate(argv,c) collapse(2)
220 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
221 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
222 // CHECK-NEXT: foo();
223 for (int i = 0; i < 10; ++i)
224 foo();
225 // CHECK: for (int i = 0; i < 10; ++i)
226 // CHECK-NEXT: foo();
227 #pragma omp target
228 #pragma omp teams distribute simd
229 for (int i = 0; i < 10; ++i)foo();
230 // CHECK: #pragma omp target
231 // CHECK-NEXT: #pragma omp teams distribute simd
232 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
233 // CHECK-NEXT: foo();
234 #pragma omp target
235 #pragma omp teams distribute simd default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
236 for (int k = 0; k < 10; ++k)
237 e += d + argc;
238 // CHECK: #pragma omp target
239 // CHECK-NEXT: #pragma omp teams distribute simd default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
240 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
241 // CHECK-NEXT: e += d + argc;
242 #pragma omp target
243 #pragma omp teams distribute simd simdlen(clen-1)
244 for (int k = 0; k < 10; ++k)
245 e += d + argc;
246 // CHECK: #pragma omp target
247 // CHECK-NEXT: #pragma omp teams distribute simd simdlen(clen - 1)
248 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
249 // CHECK-NEXT: e += d + argc;
250 #pragma omp target
251 #ifdef OMP51
252 #pragma omp teams distribute simd safelen(clen-1) aligned(arr:N+6) if(simd:b) nontemporal(argc, c, d) order(unconstrained:concurrent)
253 #elif OMP5
254 #pragma omp teams distribute simd safelen(clen-1) aligned(arr:N+6) if(simd:b) nontemporal(argc, c, d) order(concurrent)
255 #else
256 #pragma omp teams distribute simd safelen(clen-1) aligned(arr:N+6)
257 #endif // OMP51
258 for (int k = 0; k < 10; ++k)
259 e += d + argc + arr[k];
260 // CHECK: #pragma omp target
261 // OMP45-NEXT: #pragma omp teams distribute simd safelen(clen - 1) aligned(arr: N + 6)
262 // OMP50-NEXT: #pragma omp teams distribute simd safelen(clen - 1) aligned(arr: N + 6) if(simd: b) nontemporal(argc,c,d) order(concurrent)
263 // OMP51-NEXT: #pragma omp teams distribute simd safelen(clen - 1) aligned(arr: N + 6) if(simd: b) nontemporal(argc,c,d) order(unconstrained: concurrent)
264 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
265 // CHECK-NEXT: e += d + argc + arr[k];
266 return (0);
269 #endif