[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / distribute_parallel_for_ast_print.cpp
blob7af4e5f6b2b440f3d138a8144ca73435a9870dc5
1 // RUN: %clang_cc1 -verify -std=c++11 -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 -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
4 // RUN: %clang_cc1 -verify -std=c++11 -fopenmp -ast-print %s -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
5 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
6 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -verify %s -ast-print -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
7 // RUN: %clang_cc1 -verify -std=c++11 -fopenmp -fopenmp-version=51 -ast-print %s -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
8 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
9 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -std=c++11 -include-pch %t -verify %s -ast-print -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
11 // RUN: %clang_cc1 -verify -std=c++11 -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 -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
14 // RUN: %clang_cc1 -verify -std=c++11 -fopenmp-simd -ast-print %s -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
15 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
16 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify %s -ast-print -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
17 // RUN: %clang_cc1 -verify -std=c++11 -fopenmp-simd -fopenmp-version=51 -ast-print %s -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
18 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
19 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -std=c++11 -include-pch %t -verify %s -ast-print -Wno-openmp-mapping -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
20 // expected-no-diagnostics
22 #ifndef HEADER
23 #define HEADER
25 struct S {
26 S(): a(0) {}
27 S(int v) : a(v) {}
28 int a;
29 typedef int type;
32 template <typename T>
33 class S7 : public T {
34 protected:
35 T a;
36 S7() : a(0) {}
38 public:
39 S7(typename T::type v) : a(v) {
40 #pragma omp target
41 #pragma omp teams
42 #pragma omp distribute parallel for private(a) private(this->a) private(T::a)
43 for (int k = 0; k < a.a; ++k)
44 ++this->a.a;
46 S7 &operator=(S7 &s) {
47 #pragma omp target
48 #pragma omp teams
49 #pragma omp distribute parallel for private(a) private(this->a)
50 for (int k = 0; k < s.a.a; ++k)
51 ++s.a.a;
52 return *this;
56 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a) private(T::a){{$}}
57 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a)
58 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a) private(this->S::a)
60 class S8 : public S7<S> {
61 S8() {}
63 public:
64 S8(int v) : S7<S>(v){
65 #pragma omp target
66 #pragma omp teams
67 #pragma omp distribute parallel for private(a) private(this->a) private(S7<S>::a)
68 for (int k = 0; k < a.a; ++k)
69 ++this->a.a;
71 S8 &operator=(S8 &s) {
72 #pragma omp target
73 #pragma omp teams
74 #pragma omp distribute parallel for private(a) private(this->a)
75 for (int k = 0; k < s.a.a; ++k)
76 ++s.a.a;
77 return *this;
81 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a) private(this->S7<S>::a)
82 // CHECK: #pragma omp distribute parallel for private(this->a) private(this->a)
84 template <class T, int N>
85 T tmain(T argc) {
86 T b = argc, c, d, e, f, h;
87 static T a;
88 // CHECK: static T a;
89 static T g;
90 #pragma omp threadprivate(g)
91 #pragma omp target
92 #pragma omp teams
93 #pragma omp distribute parallel for dist_schedule(static, a) schedule(dynamic) default(none) copyin(g) firstprivate(a) allocate(a)
94 // CHECK: #pragma omp distribute parallel for dist_schedule(static, a) schedule(dynamic) default(none) copyin(g) firstprivate(a) allocate(a)
95 for (int i = 0; i < 2; ++i)
96 a = 2;
97 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
98 // CHECK-NEXT: a = 2;
99 #pragma omp target
100 #pragma omp teams
101 #pragma omp distribute parallel for allocate(argc) private(argc, b), firstprivate(c, d), lastprivate(f) collapse(N) schedule(static, N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h) dist_schedule(static,N)
102 for (int i = 0; i < 2; ++i)
103 for (int j = 0; j < 2; ++j)
104 for (int j = 0; j < 2; ++j)
105 for (int j = 0; j < 2; ++j)
106 for (int j = 0; j < 2; ++j)
107 for (int i = 0; i < 2; ++i)
108 for (int j = 0; j < 2; ++j)
109 for (int j = 0; j < 2; ++j)
110 for (int j = 0; j < 2; ++j)
111 for (int j = 0; j < 2; ++j)
112 a++;
113 // CHECK: #pragma omp distribute parallel for allocate(argc) private(argc,b) firstprivate(c,d) lastprivate(f) collapse(N) schedule(static, N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h) dist_schedule(static, N)
114 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
115 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
116 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
117 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
118 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
119 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
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 j = 0; j < 2; ++j)
123 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
124 // CHECK-NEXT: a++;
125 return T();
128 void foo(int argc, char **argv) {
129 int b, c, d, e, f, h;
130 static int a;
131 // CHECK: static int a;
132 static float g;
133 #pragma omp threadprivate(g)
134 [&]() {
135 #pragma omp target
136 #pragma omp teams
137 #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc)
138 // CHECK: #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc)
139 for (int i = 0; i < 2; ++i)
140 // CHECK: for (int i = 0; i < 2; ++i)
141 [&]() {
142 a = 2;
143 // CHECK: a = 2;
144 }();
146 }();
147 [&]() {
148 #pragma omp target
149 #pragma omp teams
150 #pragma omp distribute parallel for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) if (argc) num_threads(a) default(shared) shared(e) reduction(+ : h) dist_schedule(static, b)
151 for (int i = 0; i < 10; ++i)
152 for (int j = 0; j < 10; ++j)
153 [&]() {
154 a++;
155 }();
156 // CHECK: #pragma omp distribute parallel for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) if(argc) num_threads(a) default(shared) shared(e) reduction(+: h) dist_schedule(static, b)
157 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
158 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
159 // CHECK: a++;
160 }();
163 int main(int argc, char **argv) {
164 int b = argc, c, d, e, f, h;
165 static int a;
166 // CHECK: static int a;
167 static float g;
168 #pragma omp threadprivate(g)
169 #pragma omp target
170 #pragma omp teams
171 #ifdef OMP51
172 #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc) order(reproducible:concurrent) reduction(task,+:c)
173 #elif OMP5
174 #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc) order(concurrent) reduction(task,+:c)
175 #else
176 #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc)
177 #endif // OMP5
178 // OMP51: #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc) order(reproducible: concurrent) reduction(task, +: c)
179 // OMP50: #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc) order(concurrent) reduction(task, +: c)
180 // OMP45: #pragma omp distribute parallel for schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc)
181 for (int i = 0; i < 2; ++i)
182 a = 2;
183 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
184 // CHECK-NEXT: a = 2;
185 #pragma omp target
186 #pragma omp teams
187 #pragma omp distribute parallel for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) if (argc) num_threads(a) default(shared) shared(e) reduction(+ : h) dist_schedule(static, b)
188 for (int i = 0; i < 10; ++i)
189 for (int j = 0; j < 10; ++j)
190 a++;
191 // CHECK: #pragma omp distribute parallel for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) if(argc) num_threads(a) default(shared) shared(e) reduction(+: h) dist_schedule(static, b)
192 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
193 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
194 // CHECK-NEXT: a++;
195 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
198 #endif