Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / parallel_masked_ast_print.cpp
blobc56c7aa14c93622254c0be376b84311c32382761
1 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -ast-print %s | FileCheck %s
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 -fsyntax-only -verify -Wno-vla %s -ast-print | FileCheck %s
5 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -ast-print %s | FileCheck %s
6 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify -Wno-vla %s -ast-print | FileCheck %s
8 // expected-no-diagnostics
10 #ifndef HEADER
11 #define HEADER
13 void foo() {}
15 struct S1 {
16 S1(): a(0) {}
17 S1(int v) : a(v) {}
18 int a;
19 typedef int type;
20 S1& operator +(const S1&);
21 S1& operator *(const S1&);
22 S1& operator &&(const S1&);
23 S1& operator ^(const S1&);
26 template <typename T>
27 class S7 : public T {
28 protected:
29 T a;
30 T b[100];
31 S7() : a(0) {}
33 public:
34 S7(typename T::type v) : a(v) {
35 int tid = 0;
36 // CHECK: #pragma omp parallel masked filter(tid) private(this->a) private(this->a) private(T::a)
37 #pragma omp parallel masked filter(tid) private(a) private(this->a) private(T::a)
38 for (int k = 0; k < a.a; ++k)
39 ++this->a.a;
40 // CHECK: #pragma omp parallel masked filter(tid) firstprivate(this->a) firstprivate(this->a) firstprivate(T::a)
41 #pragma omp parallel masked filter(tid) firstprivate(a) firstprivate(this->a) firstprivate(T::a)
42 for (int k = 0; k < a.a; ++k)
43 ++this->a.a;
44 // CHECK: #pragma omp parallel masked filter(tid) shared(this->a) shared(this->a) shared(T::a)
45 #pragma omp parallel masked filter(tid) shared(a) shared(this->a) shared(T::a)
46 for (int k = 0; k < a.a; ++k)
47 ++this->a.a;
48 // CHECK: #pragma omp parallel masked filter(tid) reduction(+: this->a) reduction(*: this->b[:])
49 #pragma omp parallel masked filter(tid) reduction(+ : a) reduction(*: b[:])
50 for (int k = 0; k < a.a; ++k)
51 ++this->a.a;
53 S7 &operator=(S7 &s) {
54 int tid = 0;
55 // CHECK: #pragma omp parallel masked filter(tid) private(this->a) private(this->a)
56 #pragma omp parallel masked filter(tid) private(a) private(this->a)
57 for (int k = 0; k < s.a.a; ++k)
58 ++s.a.a;
59 // CHECK: #pragma omp parallel masked filter(tid) firstprivate(this->a) firstprivate(this->a)
60 #pragma omp parallel masked filter(tid) firstprivate(a) firstprivate(this->a)
61 for (int k = 0; k < s.a.a; ++k)
62 ++s.a.a;
63 // CHECK: #pragma omp parallel masked filter(tid) shared(this->a) shared(this->a)
64 #pragma omp parallel masked filter(tid) shared(a) shared(this->a)
65 for (int k = 0; k < s.a.a; ++k)
66 ++s.a.a;
67 // CHECK: #pragma omp parallel masked filter(tid) reduction(&&: this->a) reduction(^: this->b[s.a.a])
68 #pragma omp parallel masked filter(tid) reduction(&& : this->a) reduction(^: b[s.a.a])
69 for (int k = 0; k < s.a.a; ++k)
70 ++s.a.a;
71 return *this;
75 // CHECK: #pragma omp parallel masked filter(tid) private(this->a) private(this->a) private(this->S1::a)
76 // CHECK: #pragma omp parallel masked filter(tid) firstprivate(this->a) firstprivate(this->a) firstprivate(this->S1::a)
77 // CHECK: #pragma omp parallel masked filter(tid) shared(this->a) shared(this->a) shared(this->S1::a)
78 // CHECK: #pragma omp parallel masked filter(tid) reduction(+: this->a) reduction(*: this->b[:])
80 class S8 : public S7<S1> {
81 S8() {}
83 public:
84 S8(int v) : S7<S1>(v){
85 // CHECK: #pragma omp parallel masked private(this->a) private(this->a) private(this->S7<S1>::a)
86 #pragma omp parallel masked private(a) private(this->a) private(S7 < S1 > ::a)
87 for (int k = 0; k < a.a; ++k)
88 ++this->a.a;
89 // CHECK: #pragma omp parallel masked firstprivate(this->a) firstprivate(this->a) firstprivate(this->S7<S1>::a)
90 #pragma omp parallel masked firstprivate(a) firstprivate(this->a) firstprivate(S7 < S1 > ::a)
91 for (int k = 0; k < a.a; ++k)
92 ++this->a.a;
93 // CHECK: #pragma omp parallel masked shared(this->a) shared(this->a) shared(this->S7<S1>::a)
94 #pragma omp parallel masked shared(a) shared(this->a) shared(S7 < S1 > ::a)
95 for (int k = 0; k < a.a; ++k)
96 ++this->a.a;
97 // CHECK: #pragma omp parallel masked reduction(^: this->S7<S1>::a) reduction(+: this->S7<S1>::b[:this->S7<S1>::a.a])
98 #pragma omp parallel masked reduction(^ : S7 < S1 > ::a) reduction(+ : S7 < S1 > ::b[ : S7 < S1 > ::a.a])
99 for (int k = 0; k < a.a; ++k)
100 ++this->a.a;
102 S8 &operator=(S8 &s) {
103 // CHECK: #pragma omp parallel masked private(this->a) private(this->a)
104 #pragma omp parallel masked private(a) private(this->a)
105 for (int k = 0; k < s.a.a; ++k)
106 ++s.a.a;
107 // CHECK: #pragma omp parallel masked firstprivate(this->a) firstprivate(this->a)
108 #pragma omp parallel masked firstprivate(a) firstprivate(this->a)
109 for (int k = 0; k < s.a.a; ++k)
110 ++s.a.a;
111 // CHECK: #pragma omp parallel masked shared(this->a) shared(this->a)
112 #pragma omp parallel masked shared(a) shared(this->a)
113 for (int k = 0; k < s.a.a; ++k)
114 ++s.a.a;
115 // CHECK: #pragma omp parallel masked reduction(*: this->a) reduction(&&: this->b[this->a.a:])
116 #pragma omp parallel masked reduction(* : this->a) reduction(&&:this->b[a.a:])
117 for (int k = 0; k < s.a.a; ++k)
118 ++s.a.a;
119 return *this;
124 template <class T>
125 struct S {
126 operator T() {return T();}
127 static T TS;
128 #pragma omp threadprivate(TS)
131 // CHECK: template <class T> struct S {
132 // CHECK: static T TS;
133 // CHECK-NEXT: #pragma omp threadprivate(S::TS)
134 // CHECK: };
135 // CHECK: template<> struct S<int> {
136 // CHECK: static int TS;
137 // CHECK-NEXT: #pragma omp threadprivate(S<int>::TS)
138 // CHECK-NEXT: }
139 // CHECK: template<> struct S<long> {
140 // CHECK: static long TS;
141 // CHECK-NEXT: #pragma omp threadprivate(S<long>::TS)
142 // CHECK-NEXT: }
144 int thrp;
145 #pragma omp threadprivate(thrp)
147 template <typename T, int C>
148 T tmain(T argc, T *argv) {
149 T b = argc, c, d, e, f, g;
150 static T a;
151 S<T> s;
152 T arr[C][10], arr1[C];
153 #pragma omp parallel masked
154 a=2;
155 #pragma omp parallel masked 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])
156 foo();
157 #pragma omp parallel masked if (C) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:C][:argc]) reduction(task, && : g)
158 foo();
159 return 0;
162 // CHECK: template <typename T, int C> T tmain(T argc, T *argv) {
163 // CHECK-NEXT: T b = argc, c, d, e, f, g;
164 // CHECK-NEXT: static T a;
165 // CHECK-NEXT: S<T> s;
166 // CHECK-NEXT: T arr[C][10], arr1[C];
167 // CHECK-NEXT: #pragma omp parallel masked
168 // CHECK-NEXT: a = 2;
169 // CHECK-NEXT: #pragma omp parallel masked 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])
170 // CHECK-NEXT: foo()
171 // CHECK-NEXT: #pragma omp parallel masked if(C) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:C][:argc]) reduction(task, &&: g)
172 // CHECK-NEXT: foo()
173 // CHECK: template<> int tmain<int, 5>(int argc, int *argv) {
174 // CHECK-NEXT: int b = argc, c, d, e, f, g;
175 // CHECK-NEXT: static int a;
176 // CHECK-NEXT: S<int> s;
177 // CHECK-NEXT: int arr[5][10], arr1[5];
178 // CHECK-NEXT: #pragma omp parallel masked
179 // CHECK-NEXT: a = 2;
180 // CHECK-NEXT: #pragma omp parallel masked 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])
181 // CHECK-NEXT: foo()
182 // CHECK-NEXT: #pragma omp parallel masked if(5) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:5][:argc]) reduction(task, &&: g)
183 // CHECK-NEXT: foo()
184 // CHECK: template<> long tmain<long, 1>(long argc, long *argv) {
185 // CHECK-NEXT: long b = argc, c, d, e, f, g;
186 // CHECK-NEXT: static long a;
187 // CHECK-NEXT: S<long> s;
188 // CHECK-NEXT: long arr[1][10], arr1[1];
189 // CHECK-NEXT: #pragma omp parallel masked
190 // CHECK-NEXT: a = 2;
191 // CHECK-NEXT: #pragma omp parallel masked 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])
192 // CHECK-NEXT: foo()
193 // CHECK-NEXT: #pragma omp parallel masked if(1) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:1][:argc]) reduction(task, &&: g)
194 // CHECK-NEXT: foo()
196 enum Enum { };
198 int main (int argc, char **argv) {
199 long x;
200 int b = argc, c, d, e, f, g;
201 int tid = 0;
202 static int a;
203 #pragma omp threadprivate(a)
204 int arr[10][argc], arr1[2];
205 Enum ee;
206 // CHECK: Enum ee;
207 #pragma omp parallel masked
208 // CHECK-NEXT: #pragma omp parallel masked
209 a=2;
210 // CHECK-NEXT: a = 2;
211 #pragma omp parallel masked 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) filter(tid)
212 // CHECK-NEXT: #pragma omp parallel masked 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) filter(tid)
213 foo();
214 // CHECK-NEXT: foo();
215 // CHECK-NEXT: #pragma omp parallel masked allocate(e) if(b) num_threads(c) proc_bind(close) reduction(^: e,f) reduction(&&: g,arr[0:argc][:10])
216 // CHECK-NEXT: foo()
217 #pragma omp parallel masked allocate(e) if (b) num_threads(c) proc_bind(close) reduction(^:e, f) reduction(&& : g, arr[0:argc][:10])
218 foo();
219 return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);
222 template<typename T>
223 T S<T>::TS = 0;
225 #endif