Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / parallel_ast_print.cpp
blobdcfec564ed07401019bd7aece2a877b8611a41eb
1 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -fopenmp-version=50 -ast-print %s | FileCheck %s
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 -Wno-vla %s -ast-print | FileCheck %s
5 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -fopenmp-version=50 -ast-print %s | FileCheck %s
6 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify -Wno-vla %s -ast-print | FileCheck %s
9 // RUN: %clang_cc1 -DOMP51 -verify -Wno-vla -fopenmp -ast-print %s | FileCheck -check-prefixes=CHECK,OMP51 %s
10 // RUN: %clang_cc1 -DOMP51 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
11 // RUN: %clang_cc1 -DOMP51 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify -Wno-vla %s -ast-print | FileCheck -check-prefixes=CHECK,OMP51 %s
13 // RUN: %clang_cc1 -DOMP51 -verify -Wno-vla -fopenmp-simd -ast-print %s | FileCheck -check-prefixes=CHECK,OMP51 %s
14 // RUN: %clang_cc1 -DOMP51 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
15 // RUN: %clang_cc1 -DOMP51 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify -Wno-vla %s -ast-print | FileCheck -check-prefixes=CHECK,OMP51 %s
16 // expected-no-diagnostics
18 #ifndef HEADER
19 #define HEADER
21 void foo() {}
23 struct S1 {
24 S1(): a(0) {}
25 S1(int v) : a(v) {}
26 int a;
27 typedef int type;
28 S1& operator +(const S1&);
29 S1& operator *(const S1&);
30 S1& operator &&(const S1&);
31 S1& operator ^(const S1&);
34 template <typename T>
35 class S7 : public T {
36 protected:
37 T a;
38 T b[100];
39 S7() : a(0) {}
41 public:
42 S7(typename T::type v) : a(v) {
43 #pragma omp parallel private(a) private(this->a) private(T::a)
44 for (int k = 0; k < a.a; ++k)
45 ++this->a.a;
46 #pragma omp parallel firstprivate(a) firstprivate(this->a) firstprivate(T::a)
47 for (int k = 0; k < a.a; ++k)
48 ++this->a.a;
49 #pragma omp parallel shared(a) shared(this->a) shared(T::a)
50 for (int k = 0; k < a.a; ++k)
51 ++this->a.a;
52 #pragma omp parallel reduction(+ : a) reduction(*: b[:])
53 for (int k = 0; k < a.a; ++k)
54 ++this->a.a;
56 S7 &operator=(S7 &s) {
57 #pragma omp parallel private(a) private(this->a)
58 for (int k = 0; k < s.a.a; ++k)
59 ++s.a.a;
60 #pragma omp parallel firstprivate(a) firstprivate(this->a)
61 for (int k = 0; k < s.a.a; ++k)
62 ++s.a.a;
63 #pragma omp parallel shared(a) shared(this->a)
64 for (int k = 0; k < s.a.a; ++k)
65 ++s.a.a;
66 #pragma omp parallel reduction(&& : this->a) reduction(^: b[s.a.a])
67 for (int k = 0; k < s.a.a; ++k)
68 ++s.a.a;
69 return *this;
73 // CHECK: #pragma omp parallel private(this->a) private(this->a) private(T::a)
74 // CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a) firstprivate(T::a)
75 // CHECK: #pragma omp parallel shared(this->a) shared(this->a) shared(T::a)
76 // CHECK: #pragma omp parallel reduction(+: this->a) reduction(*: this->b[:])
77 // CHECK: #pragma omp parallel private(this->a) private(this->a)
78 // CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a)
79 // CHECK: #pragma omp parallel shared(this->a) shared(this->a)
80 // CHECK: #pragma omp parallel reduction(&&: this->a) reduction(^: this->b[s.a.a])
81 // CHECK: #pragma omp parallel private(this->a) private(this->a) private(this->S1::a)
82 // CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a) firstprivate(this->S1::a)
83 // CHECK: #pragma omp parallel shared(this->a) shared(this->a) shared(this->S1::a)
84 // CHECK: #pragma omp parallel reduction(+: this->a) reduction(*: this->b[:])
86 class S8 : public S7<S1> {
87 S8() {}
89 public:
90 S8(int v) : S7<S1>(v){
91 #pragma omp parallel private(a) private(this->a) private(S7 < S1 > ::a)
92 for (int k = 0; k < a.a; ++k)
93 ++this->a.a;
94 #pragma omp parallel firstprivate(a) firstprivate(this->a) firstprivate(S7 < S1 > ::a)
95 for (int k = 0; k < a.a; ++k)
96 ++this->a.a;
97 #pragma omp parallel shared(a) shared(this->a) shared(S7 < S1 > ::a)
98 for (int k = 0; k < a.a; ++k)
99 ++this->a.a;
100 #pragma omp parallel reduction(default, ^ : S7 < S1 > ::a) reduction(+ : S7 < S1 > ::b[ : S7 < S1 > ::a.a])
101 for (int k = 0; k < a.a; ++k)
102 ++this->a.a;
104 S8 &operator=(S8 &s) {
105 #pragma omp parallel private(a) private(this->a)
106 for (int k = 0; k < s.a.a; ++k)
107 ++s.a.a;
108 #pragma omp parallel firstprivate(a) firstprivate(this->a)
109 for (int k = 0; k < s.a.a; ++k)
110 ++s.a.a;
111 #pragma omp parallel shared(a) shared(this->a)
112 for (int k = 0; k < s.a.a; ++k)
113 ++s.a.a;
114 #pragma omp parallel reduction(* : this->a) reduction(&&:this->b[a.a:])
115 for (int k = 0; k < s.a.a; ++k)
116 ++s.a.a;
117 return *this;
121 // CHECK: #pragma omp parallel private(this->a) private(this->a) private(this->S7<S1>::a)
122 // CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a) firstprivate(this->S7<S1>::a)
123 // CHECK: #pragma omp parallel shared(this->a) shared(this->a) shared(this->S7<S1>::a)
124 // CHECK: #pragma omp parallel reduction(default, ^: this->S7<S1>::a) reduction(+: this->S7<S1>::b[:this->S7<S1>::a.a])
125 // CHECK: #pragma omp parallel private(this->a) private(this->a)
126 // CHECK: #pragma omp parallel firstprivate(this->a) firstprivate(this->a)
127 // CHECK: #pragma omp parallel shared(this->a) shared(this->a)
128 // CHECK: #pragma omp parallel reduction(*: this->a) reduction(&&: this->b[this->a.a:])
130 template <class T>
131 struct S {
132 operator T() {return T();}
133 static T TS;
134 #pragma omp threadprivate(TS)
137 // CHECK: template <class T> struct S {
138 // CHECK: static T TS;
139 // CHECK-NEXT: #pragma omp threadprivate(S::TS)
140 // CHECK: };
141 // CHECK: template<> struct S<int> {
142 // CHECK: static int TS;
143 // CHECK-NEXT: #pragma omp threadprivate(S<int>::TS)
144 // CHECK-NEXT: }
145 // CHECK: template<> struct S<long> {
146 // CHECK: static long TS;
147 // CHECK-NEXT: #pragma omp threadprivate(S<long>::TS)
148 // CHECK-NEXT: }
150 int thrp;
151 #pragma omp threadprivate(thrp)
153 template <typename T, int C>
154 T tmain(T argc, T *argv) {
155 T b = argc, c, d, e, f, g;
156 static T a;
157 S<T> s;
158 T arr[C][10], arr1[C];
159 #pragma omp parallel
160 a=2;
161 #pragma omp parallel default(none), private(argc,b) firstprivate(argv) shared (d) if (parallel:argc > 0) num_threads(C) copyin(S<T>::TS, thrp) proc_bind(master) reduction(+:c, arr1[argc]) reduction(max:e, arr[:C][0:10])
162 foo();
163 #ifdef OMP51
164 #pragma omp parallel default(none), private(argc,b) firstprivate(argv) shared (d) if (parallel:argc > 0) num_threads(C) copyin(S<T>::TS, thrp) proc_bind(primary) reduction(+:c, arr1[argc]) reduction(max:e, arr[:C][0:10])
165 foo();
166 #endif
167 #pragma omp parallel if (C) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:C][:argc]) reduction(default, && : g) reduction(task,+:argc)
168 foo();
169 return 0;
172 // CHECK: template <typename T, int C> T tmain(T argc, T *argv) {
173 // CHECK-NEXT: T b = argc, c, d, e, f, g;
174 // CHECK-NEXT: static T a;
175 // CHECK-NEXT: S<T> s;
176 // CHECK-NEXT: T arr[C][10], arr1[C];
177 // CHECK-NEXT: #pragma omp parallel{{$}}
178 // CHECK-NEXT: a = 2;
179 // CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(C) copyin(S<T>::TS,thrp) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:C][0:10])
180 // CHECK-NEXT: foo()
181 // OMP51-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(C) copyin(S<T>::TS,thrp) proc_bind(primary) reduction(+: c,arr1[argc]) reduction(max: e,arr[:C][0:10])
182 // OMP51-NEXT: foo()
183 // CHECK-NEXT: #pragma omp parallel if(C) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:C][:argc]) reduction(default, &&: g) reduction(task, +: argc)
184 // CHECK-NEXT: foo()
185 // CHECK: template<> int tmain<int, 5>(int argc, int *argv) {
186 // CHECK-NEXT: int b = argc, c, d, e, f, g;
187 // CHECK-NEXT: static int a;
188 // CHECK-NEXT: S<int> s;
189 // CHECK-NEXT: int arr[5][10], arr1[5];
190 // CHECK-NEXT: #pragma omp parallel
191 // CHECK-NEXT: a = 2;
192 // CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(5) copyin(S<int>::TS,thrp) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:5][0:10])
193 // CHECK-NEXT: foo()
194 // OMP51-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(5) copyin(S<int>::TS,thrp) proc_bind(primary) reduction(+: c,arr1[argc]) reduction(max: e,arr[:5][0:10])
195 // OMP51-NEXT: foo()
196 // CHECK-NEXT: #pragma omp parallel if(5) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:5][:argc]) reduction(default, &&: g) reduction(task, +: argc)
197 // CHECK-NEXT: foo()
198 // CHECK: template<> long tmain<long, 1>(long argc, long *argv) {
199 // CHECK-NEXT: long b = argc, c, d, e, f, g;
200 // CHECK-NEXT: static long a;
201 // CHECK-NEXT: S<long> s;
202 // CHECK-NEXT: long arr[1][10], arr1[1];
203 // CHECK-NEXT: #pragma omp parallel
204 // CHECK-NEXT: a = 2;
205 // CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(1) copyin(S<long>::TS,thrp) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:1][0:10])
206 // CHECK-NEXT: foo()
207 // OMP51-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(1) copyin(S<long>::TS,thrp) proc_bind(primary) reduction(+: c,arr1[argc]) reduction(max: e,arr[:1][0:10])
208 // OMP51-NEXT: foo()
209 // CHECK-NEXT: #pragma omp parallel if(1) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:1][:argc]) reduction(default, &&: g) reduction(task, +: argc)
210 // CHECK-NEXT: foo()
212 enum Enum { };
214 int main (int argc, char **argv) {
215 long x;
216 int b = argc, c, d, e, f, g;
217 static int a;
218 #pragma omp threadprivate(a)
219 int arr[10][argc], arr1[2];
220 Enum ee;
221 // CHECK: Enum ee;
222 #pragma omp parallel
223 // CHECK-NEXT: #pragma omp parallel
224 a=2;
225 // CHECK-NEXT: a = 2;
226 #pragma omp parallel default(none), private(argc,b) firstprivate(argv) if (parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(| : c, d, arr1[argc]) reduction(* : e, arr[:10][0:argc]) allocate(e)
227 // CHECK-NEXT: #pragma omp parallel default(none) private(argc,b) firstprivate(argv) if(parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(|: c,d,arr1[argc]) reduction(*: e,arr[:10][0:argc]) allocate(e)
228 foo();
229 // CHECK-NEXT: foo();
230 // CHECK-NEXT: #pragma omp parallel allocate(e) if(b) num_threads(c) proc_bind(close) reduction(^: e,f) reduction(&&: g,arr[0:argc][:10])
231 // CHECK-NEXT: foo()
232 #pragma omp parallel allocate(e) if (b) num_threads(c) proc_bind(close) reduction(^:e, f) reduction(&& : g, arr[0:argc][:10])
233 foo();
234 return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);
237 template <class T>
238 struct Foo {
239 int foo;
242 void foo(const Foo<int> &arg) {
243 // CHECK: #pragma omp parallel
244 #pragma omp parallel
246 // CHECK: #pragma omp for schedule(static)
247 #pragma omp for schedule(static)
248 for (int idx = 0; idx < 1234; ++idx) {
249 //arg.foo = idx;
250 idx = arg.foo;
255 template<typename T>
256 T S<T>::TS = 0;
258 #endif