[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / target_teams_distribute_parallel_for_ast_print.cpp
blob9187d41e78e10f23a73acbd2774511d51c9f7d8c
1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -ast-print %s -Wno-openmp-mapping -Wsign-conversion | 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 -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 -Wsign-conversion -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 -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 -Wsign-conversion | 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 -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 -Wsign-conversion -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 -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 teams distribute parallel for private(a) private(this->a) private(T::a) allocate(omp_cgroup_mem_alloc:a) uses_allocators(omp_cgroup_mem_alloc)
48 for (int k = 0; k < a.a; ++k) {
49 ++this->a.a;
50 #pragma omp cancel for
53 S7 &operator=(S7 &s) {
54 #pragma omp target teams distribute parallel for private(a) private(this->a)
55 for (int k = 0; k < s.a.a; ++k)
56 ++s.a.a;
58 foo();
59 return *this;
61 void foo() {
62 int b, argv, d, c, e, f;
63 #pragma omp target teams distribute parallel for default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
64 for (int k = 0; k < a.a; ++k)
65 ++a.a;
68 // CHECK: #pragma omp target teams distribute parallel for private(this->a) private(this->a) private(T::a) allocate(omp_cgroup_mem_alloc: this->a) uses_allocators(omp_cgroup_mem_alloc)
69 // CHECK: #pragma omp cancel for
70 // CHECK: #pragma omp target teams distribute parallel for private(this->a) private(this->a)
71 // CHECK: #pragma omp target teams distribute parallel for default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
73 class S8 : public S7<S> {
74 S8() {}
76 public:
77 S8(int v) : S7<S>(v){
78 #pragma omp target teams distribute parallel for private(a) private(this->a) private(S7<S>::a)
79 for (int k = 0; k < a.a; ++k)
80 ++this->a.a;
82 S8 &operator=(S8 &s) {
83 #pragma omp target teams distribute parallel for private(a) private(this->a)
84 for (int k = 0; k < s.a.a; ++k)
85 ++s.a.a;
87 bar();
88 return *this;
90 void bar() {
91 int b, argv, d, c, e, f8;
92 #pragma omp target teams distribute parallel for allocate(b) default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f8) thread_limit(d) allocate(e)
93 for (int k = 0; k < a.a; ++k)
94 ++a.a;
97 // CHECK: #pragma omp target teams distribute parallel for private(this->a) private(this->a) private(this->S::a)
98 // CHECK: #pragma omp target teams distribute parallel for private(this->a) private(this->a) private(this->S7<S>::a)
99 // CHECK: #pragma omp target teams distribute parallel for private(this->a) private(this->a)
100 // CHECK: #pragma omp target teams distribute parallel for allocate(b) default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f8) thread_limit(d) allocate(e)
102 template <class T, int N>
103 T tmain(T argc) {
104 T b = argc, c, d, e, f, g;
105 static T a;
106 // CHECK: static T a;
107 const T clen = 5;
108 const T alen = 16;
109 int arr[10];
110 #pragma omp target teams distribute parallel for
111 for (int i=0; i < 2; ++i)
112 a = 2;
113 // CHECK: #pragma omp target teams distribute parallel for{{$}}
114 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
115 // CHECK-NEXT: a = 2;
116 #ifdef OMP51
117 #pragma omp target teams distribute parallel for private(argc, b), firstprivate(c, d), collapse(2) order(unconstrained:concurrent)
118 #else
119 #pragma omp target teams distribute parallel for private(argc, b), firstprivate(c, d), collapse(2) order(concurrent)
120 #endif // OMP51
121 for (int i = 0; i < 10; ++i)
122 for (int j = 0; j < 10; ++j)
123 foo();
124 // OMP51: #pragma omp target teams distribute parallel for private(argc,b) firstprivate(c,d) collapse(2) order(unconstrained: concurrent)
125 // OMP50: #pragma omp target teams distribute parallel for private(argc,b) firstprivate(c,d) collapse(2) order(concurrent)
126 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
127 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
128 // CHECK-NEXT: foo();
129 for (int i = 0; i < 10; ++i)
130 foo();
131 // CHECK: for (int i = 0; i < 10; ++i)
132 // CHECK-NEXT: foo();
133 #pragma omp target teams distribute parallel for
134 for (int i = 0; i < 10; ++i)
135 foo();
136 // CHECK: #pragma omp target teams distribute parallel for
137 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
138 // CHECK-NEXT: foo();
139 #pragma omp target teams distribute parallel for default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
140 for (int k = 0; k < 10; ++k)
141 e += d + argc;
142 // CHECK: #pragma omp target teams distribute parallel for default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
143 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
144 // CHECK-NEXT: e += d + argc;
145 #pragma omp target teams distribute parallel for
146 for (int k = 0; k < 10; ++k)
147 e += d + argc;
148 // CHECK: #pragma omp target teams distribute parallel for
149 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
150 // CHECK-NEXT: e += d + argc;
151 return T();
154 int main (int argc, char **argv) {
155 int b = argc, c, d, e, f, g;
156 static int a;
157 // CHECK: static int a;
158 const int clen = 5;
159 const int N = 10;
160 int arr[10];
161 #pragma omp target teams distribute parallel for
162 for (int i=0; i < 2; ++i)
163 a = 2;
164 // CHECK: #pragma omp target teams distribute parallel for
165 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
166 // CHECK-NEXT: a = 2;
167 #pragma omp target teams distribute parallel for private(argc,b),firstprivate(argv, c), collapse(2)
168 for (int i = 0; i < 10; ++i)
169 for (int j = 0; j < 10; ++j)
170 foo();
171 // CHECK: #pragma omp target teams distribute parallel for private(argc,b) firstprivate(argv,c) collapse(2)
172 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
173 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
174 // CHECK-NEXT: foo();
175 for (int i = 0; i < 10; ++i)
176 foo();
177 // CHECK: for (int i = 0; i < 10; ++i)
178 // CHECK-NEXT: foo();
179 #pragma omp target teams distribute parallel for
180 for (int i = 0; i < 10; ++i)foo();
181 // CHECK: #pragma omp target teams distribute parallel for
182 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
183 // CHECK-NEXT: foo();
184 #pragma omp target teams distribute parallel for default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
185 for (int k = 0; k < 10; ++k)
186 e += d + argc;
187 // CHECK: #pragma omp target teams distribute parallel for default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
188 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
189 // CHECK-NEXT: e += d + argc;
190 #pragma omp target teams distribute parallel for reduction(task,+:argc)
191 for (int k = 0; k < 10; ++k)
192 e += d + argc;
193 // CHECK: #pragma omp target teams distribute parallel for reduction(task, +: argc)
194 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
195 // CHECK-NEXT: e += d + argc;
196 return (0);
199 #endif