Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / teams_distribute_parallel_for_ast_print.cpp
blobb289af7b1c72bc29ed1b89b678760fe0627afa40
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
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 -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
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 -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 void foo() {}
21 int x;
22 #pragma omp threadprivate(x)
24 struct S {
25 S(): a(0) {}
26 S(int v) : a(v) {}
27 int a;
28 typedef int type;
31 template <typename T>
32 class S7 : public T {
33 protected:
34 T a;
35 S7() : a(0) {}
37 public:
38 S7(typename T::type v) : a(v) {
39 #pragma omp target
40 #pragma omp teams distribute parallel for private(a) private(this->a) private(T::a)
41 for (int k = 0; k < a.a; ++k)
42 ++this->a.a;
44 S7 &operator=(S7 &s) {
45 #pragma omp target
46 #pragma omp teams distribute parallel for private(a) private(this->a)
47 for (int k = 0; k < s.a.a; ++k)
48 ++s.a.a;
50 foo();
51 return *this;
53 void foo() {
54 int b, argv, d, c, e, f;
55 #pragma omp target
56 #pragma omp teams distribute parallel for default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d) copyin(x)
57 for (int k = 0; k < a.a; ++k)
58 ++a.a;
61 // CHECK: #pragma omp target
62 // CHECK-NEXT: #pragma omp teams distribute parallel for private(this->a) private(this->a) private(T::a)
63 // CHECK: #pragma omp target
64 // CHECK-NEXT: #pragma omp teams distribute parallel for private(this->a) private(this->a)
65 // CHECK: #pragma omp target
66 // CHECK-NEXT: #pragma omp teams distribute parallel for default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d) copyin(x)
68 class S8 : public S7<S> {
69 S8() {}
71 public:
72 S8(int v) : S7<S>(v){
73 #pragma omp target
74 #pragma omp teams distribute parallel for private(a) private(this->a) private(S7<S>::a)
75 for (int k = 0; k < a.a; ++k)
76 ++this->a.a;
78 S8 &operator=(S8 &s) {
79 #pragma omp target
80 #pragma omp teams distribute parallel for private(a) private(this->a)
81 for (int k = 0; k < s.a.a; ++k)
82 ++s.a.a;
84 bar();
85 return *this;
87 void bar() {
88 int b, argv, d, c, e, f8;
89 #pragma omp target
90 #pragma omp 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) copyin(x) allocate(argv)
91 for (int k = 0; k < a.a; ++k)
92 ++a.a;
95 // CHECK: #pragma omp target
96 // CHECK-NEXT: #pragma omp teams distribute parallel for private(this->a) private(this->a) private(this->S::a)
97 // CHECK: #pragma omp target
98 // CHECK-NEXT: #pragma omp teams distribute parallel for private(this->a) private(this->a) private(this->S7<S>::a)
99 // CHECK: #pragma omp target
100 // CHECK-NEXT: #pragma omp teams distribute parallel for private(this->a) private(this->a)
101 // CHECK: #pragma omp target
102 // CHECK-NEXT: #pragma omp 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) copyin(x) allocate(argv)
104 template <class T, int N>
105 T tmain(T argc) {
106 T b = argc, c, d, e, f, g;
107 static T a;
108 // CHECK: static T a;
109 const T clen = 5;
110 const T alen = 16;
111 int arr[10];
112 #pragma omp target
113 #pragma omp teams distribute parallel for
114 for (int i=0; i < 2; ++i)
115 a = 2;
116 // CHECK: #pragma omp target
117 // CHECK-NEXT: #pragma omp teams distribute parallel for{{$}}
118 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
119 // CHECK-NEXT: a = 2;
120 #pragma omp target
121 #ifdef OMP51
122 #pragma omp teams distribute parallel for private(argc, b), firstprivate(c, d), collapse(2) order(unconstrained:concurrent)
123 #else
124 #pragma omp teams distribute parallel for private(argc, b), firstprivate(c, d), collapse(2) order(concurrent)
125 #endif // OMP51
126 for (int i = 0; i < 10; ++i)
127 for (int j = 0; j < 10; ++j)
128 foo();
129 // CHECK: #pragma omp target
130 // OMP50: #pragma omp teams distribute parallel for private(argc,b) firstprivate(c,d) collapse(2) order(concurrent)
131 // OMP51: #pragma omp teams distribute parallel for private(argc,b) firstprivate(c,d) collapse(2) order(unconstrained: concurrent)
132 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
133 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
134 // CHECK-NEXT: foo();
135 for (int i = 0; i < 10; ++i)
136 foo();
137 // CHECK: for (int i = 0; i < 10; ++i)
138 // CHECK-NEXT: foo();
139 #pragma omp target
140 #pragma omp teams distribute parallel for
141 for (int i = 0; i < 10; ++i)
142 foo();
143 // CHECK: #pragma omp target
144 // CHECK-NEXT: #pragma omp teams distribute parallel for
145 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
146 // CHECK-NEXT: foo();
147 #pragma omp target
148 #pragma omp teams distribute parallel for default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d) copyin(x)
149 for (int k = 0; k < 10; ++k)
150 e += d + argc;
151 // CHECK: #pragma omp target
152 // CHECK-NEXT: #pragma omp teams distribute parallel for default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d) copyin(x)
153 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
154 // CHECK-NEXT: e += d + argc;
155 #pragma omp target
156 #pragma omp teams distribute parallel for
157 for (int k = 0; k < 10; ++k)
158 e += d + argc;
159 // CHECK: #pragma omp target
160 // CHECK-NEXT: #pragma omp teams distribute parallel for
161 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
162 // CHECK-NEXT: e += d + argc;
163 return T();
166 int main (int argc, char **argv) {
167 int b = argc, c, d, e, f, g;
168 static int a;
169 // CHECK: static int a;
170 const int clen = 5;
171 const int N = 10;
172 int arr[10];
173 #pragma omp target
174 #pragma omp teams distribute parallel for
175 for (int i=0; i < 2; ++i)
176 a = 2;
177 // CHECK: #pragma omp target
178 // CHECK-NEXT: #pragma omp teams distribute parallel for
179 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
180 // CHECK-NEXT: a = 2;
181 #pragma omp target
182 #pragma omp teams distribute parallel for private(argc,b),firstprivate(argv, c), collapse(2)
183 for (int i = 0; i < 10; ++i)
184 for (int j = 0; j < 10; ++j)
185 foo();
186 // CHECK: #pragma omp target
187 // CHECK-NEXT: #pragma omp teams distribute parallel for private(argc,b) firstprivate(argv,c) collapse(2)
188 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
189 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
190 // CHECK-NEXT: foo();
191 for (int i = 0; i < 10; ++i)
192 foo();
193 // CHECK: for (int i = 0; i < 10; ++i)
194 // CHECK-NEXT: foo();
195 #pragma omp target
196 #pragma omp teams distribute parallel for
197 for (int i = 0; i < 10; ++i)foo();
198 // CHECK: #pragma omp target
199 // CHECK-NEXT: #pragma omp teams distribute parallel for
200 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
201 // CHECK-NEXT: foo();
202 #pragma omp target
203 #pragma omp teams distribute parallel for default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d) copyin(x)
204 for (int k = 0; k < 10; ++k)
205 e += d + argc;
206 // CHECK: #pragma omp target
207 // CHECK-NEXT: #pragma omp teams distribute parallel for default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d) copyin(x)
208 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
209 // CHECK-NEXT: e += d + argc;
210 #pragma omp target
211 #pragma omp teams distribute parallel for reduction(task,&&:argc)
212 for (int k = 0; k < 10; ++k)
213 e += d + argc;
214 // CHECK: #pragma omp target
215 // CHECK-NEXT: #pragma omp teams distribute parallel for reduction(task, &&: argc)
216 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
217 // CHECK-NEXT: e += d + argc;
218 return (0);
221 #endif