Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / task_ast_print.cpp
blob79f56b0362f1e0523972b35a5e3a88459bebf411
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 typedef void *omp_depend_t;
14 typedef unsigned long omp_event_handle_t;
16 void foo() {}
18 struct S1 {
19 S1(): a(0) {}
20 S1(int v) : a(v) {}
21 int a;
22 typedef int type;
23 S1 operator +(const S1&);
26 template <typename T>
27 class S7 : public T {
28 protected:
29 T a, b, c[10], d[10];
30 S7() : a(0) {}
32 public:
33 S7(typename T::type v) : a(v) {
34 omp_depend_t x;
35 omp_event_handle_t evt;
36 #pragma omp taskgroup allocate(b) task_reduction(+:b)
37 #pragma omp task private(a) private(this->a) private(T::a) in_reduction(+:this->b) allocate(b) depend(depobj:x) detach(evt) depend(iterator(i=0:10:1, T *k = &a:&b), in: c[i], d[(int)(k-&a)]) affinity(iterator(i=0:10:1, T *k = &a:&b): c[i], d[(int)(k-&a)])
38 for (int k = 0; k < a.a; ++k)
39 ++this->a.a;
41 S7 &operator=(S7 &s) {
42 #pragma omp task private(a) private(this->a)
43 for (int k = 0; k < s.a.a; ++k)
44 ++s.a.a;
45 return *this;
49 // CHECK: #pragma omp taskgroup allocate(this->b) task_reduction(+: this->b)
50 // CHECK: #pragma omp task private(this->a) private(this->a) private(T::a) in_reduction(+: this->b) allocate(this->b) depend(depobj : x) detach(evt) depend(iterator(int i = 0:10:1, T * k = &this->a:&this->b), in : this->c[i],this->d[(int)(k - &this->a)]) affinity(iterator(int i = 0:10:1, T * k = &this->a:&this->b) : this->c[i],this->d[(int)(k - &this->a)]){{$}}
51 // CHECK: #pragma omp task private(this->a) private(this->a)
52 // CHECK: #pragma omp task private(this->a) private(this->a) private(this->S1::a) in_reduction(+: this->b) allocate(this->b) depend(depobj : x) detach(evt) depend(iterator(int i = 0:10:1, S1 * k = &this->a:&this->b), in : this->c[i],this->d[(int)(k - &this->a)]) affinity(iterator(int i = 0:10:1, S1 * k = &this->a:&this->b) : this->c[i],this->d[(int)(k - &this->a)])
54 class S8 : public S7<S1> {
55 S8() {}
57 public:
58 S8(int v) : S7<S1>(v){
59 #pragma omp task private(a) private(this->a) private(S7<S1>::a)
60 for (int k = 0; k < a.a; ++k)
61 ++this->a.a;
63 S8 &operator=(S8 &s) {
64 #pragma omp task private(a) private(this->a)
65 for (int k = 0; k < s.a.a; ++k)
66 ++s.a.a;
67 return *this;
71 // CHECK: #pragma omp task private(this->a) private(this->a) private(this->S7<S1>::a)
72 // CHECK: #pragma omp task private(this->a) private(this->a)
74 template <class T>
75 struct S {
76 operator T() { return T(); }
77 static T TS;
78 #pragma omp threadprivate(TS)
81 // CHECK: template <class T> struct S {
82 // CHECK: static T TS;
83 // CHECK-NEXT: #pragma omp threadprivate(S::TS)
84 // CHECK: };
85 // CHECK: template<> struct S<int> {
86 // CHECK: static int TS;
87 // CHECK-NEXT: #pragma omp threadprivate(S<int>::TS)
88 // CHECK-NEXT: }
89 // CHECK: template<> struct S<long> {
90 // CHECK: static long TS;
91 // CHECK-NEXT: #pragma omp threadprivate(S<long>::TS)
92 // CHECK-NEXT: }
94 template <typename T, int C>
95 T tmain(T argc, T *argv) {
96 T b = argc, c, d, e, f, g;
97 static T a;
98 S<T> s;
99 T arr[argc];
100 omp_depend_t x;
101 omp_event_handle_t evt;
102 double *arr_double;
103 #pragma omp task untied depend(in : argc, argv[b:argc], arr[:], ([argc][sizeof(T)])argv, arr_double[argc]) if (task : argc > 0) depend(depobj: x) detach(evt)
104 a = 2;
105 #pragma omp task default(none), private(argc, b) firstprivate(argv) shared(d) if (argc > 0) final(S<T>::TS > 0) priority(argc) affinity(argc, argv[b:argc], arr[:], ([argc][sizeof(T)])argv)
106 foo();
107 #pragma omp taskgroup task_reduction(-: argc)
108 #pragma omp task if (C) mergeable priority(C) in_reduction(-: argc)
109 foo();
110 return 0;
113 // CHECK: template <typename T, int C> T tmain(T argc, T *argv) {
114 // CHECK-NEXT: T b = argc, c, d, e, f, g;
115 // CHECK-NEXT: static T a;
116 // CHECK-NEXT: S<T> s;
117 // CHECK-NEXT: T arr[argc];
118 // CHECK-NEXT: omp_depend_t x;
119 // CHECK-NEXT: omp_event_handle_t evt;
120 // CHECK-NEXT: double *arr_double;
121 // CHECK-NEXT: #pragma omp task untied depend(in : argc,argv[b:argc],arr[:],([argc][sizeof(T)])argv,arr_double[argc]) if(task: argc > 0) depend(depobj : x) detach(evt)
122 // CHECK-NEXT: a = 2;
123 // CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) final(S<T>::TS > 0) priority(argc) affinity(argc,argv[b:argc],arr[:],([argc][sizeof(T)])argv)
124 // CHECK-NEXT: foo()
125 // CHECK-NEXT: #pragma omp taskgroup task_reduction(-: argc)
126 // CHECK-NEXT: #pragma omp task if(C) mergeable priority(C) in_reduction(-: argc)
127 // CHECK-NEXT: foo()
128 // CHECK: template<> int tmain<int, 5>(int argc, int *argv) {
129 // CHECK-NEXT: int b = argc, c, d, e, f, g;
130 // CHECK-NEXT: static int a;
131 // CHECK-NEXT: S<int> s;
132 // CHECK-NEXT: int arr[argc];
133 // CHECK-NEXT: omp_depend_t x;
134 // CHECK-NEXT: omp_event_handle_t evt;
135 // CHECK-NEXT: double *arr_double;
136 // CHECK-NEXT: #pragma omp task untied depend(in : argc,argv[b:argc],arr[:],([argc][sizeof(int)])argv,arr_double[argc]) if(task: argc > 0) depend(depobj : x) detach(evt)
137 // CHECK-NEXT: a = 2;
138 // CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) final(S<int>::TS > 0) priority(argc) affinity(argc,argv[b:argc],arr[:],([argc][sizeof(int)])argv)
139 // CHECK-NEXT: foo()
140 // CHECK-NEXT: #pragma omp taskgroup task_reduction(-: argc)
141 // CHECK-NEXT: #pragma omp task if(5) mergeable priority(5) in_reduction(-: argc)
142 // CHECK-NEXT: foo()
143 // CHECK: template<> long tmain<long, 1>(long argc, long *argv) {
144 // CHECK-NEXT: long b = argc, c, d, e, f, g;
145 // CHECK-NEXT: static long a;
146 // CHECK-NEXT: S<long> s;
147 // CHECK-NEXT: long arr[argc];
148 // CHECK-NEXT: omp_depend_t x;
149 // CHECK-NEXT: omp_event_handle_t evt;
150 // CHECK-NEXT: double *arr_double;
151 // CHECK-NEXT: #pragma omp task untied depend(in : argc,argv[b:argc],arr[:],([argc][sizeof(long)])argv,arr_double[argc]) if(task: argc > 0) depend(depobj : x) detach(evt)
152 // CHECK-NEXT: a = 2;
153 // CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) final(S<long>::TS > 0) priority(argc) affinity(argc,argv[b:argc],arr[:],([argc][sizeof(long)])argv)
154 // CHECK-NEXT: foo()
155 // CHECK-NEXT: #pragma omp taskgroup task_reduction(-: argc)
156 // CHECK-NEXT: #pragma omp task if(1) mergeable priority(1) in_reduction(-: argc)
157 // CHECK-NEXT: foo()
159 enum Enum {};
161 int main(int argc, char **argv) {
162 long x;
163 int b = argc, c, d, e, f, g;
164 static int a;
165 int arr[10], arr1[argc];
166 omp_depend_t y;
167 omp_event_handle_t evt;
168 #pragma omp threadprivate(a)
169 Enum ee;
170 // CHECK: Enum ee;
171 #pragma omp task untied mergeable depend(out:argv[:a][1], (arr)[0:],([argc][10])argv,b) if(task: argc > 0) priority(f) depend(depobj:y)
172 // CHECK-NEXT: #pragma omp task untied mergeable depend(out : argv[:a][1],(arr)[0:],([argc][10])argv,b) if(task: argc > 0) priority(f) depend(depobj : y)
173 a = 2;
174 // CHECK-NEXT: a = 2;
175 #pragma omp taskgroup task_reduction(min: arr1)
176 #pragma omp task default(none), private(argc, b) firstprivate(argv, evt) if (argc > 0) final(a > 0) depend(inout : a, argv[:argc],arr[:a], ([10][argc])argv) priority(23) in_reduction(min: arr1), detach(evt)
177 // CHECK-NEXT: #pragma omp taskgroup task_reduction(min: arr1)
178 // CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv,evt) if(argc > 0) final(a > 0) depend(inout : a,argv[:argc],arr[:a],([10][argc])argv) priority(23) in_reduction(min: arr1) detach(evt)
179 foo();
180 // CHECK-NEXT: foo();
181 #pragma omp taskgroup task_reduction(min: arr1)
182 #pragma omp parallel reduction(+:arr1)
183 #pragma omp task in_reduction(min: arr1) depend(iterator(i=0:argc, unsigned j=argc:0:a), out: argv[i][j])
184 // CHECK-NEXT: #pragma omp taskgroup task_reduction(min: arr1)
185 // CHECK-NEXT: #pragma omp parallel reduction(+: arr1)
186 // CHECK-NEXT: #pragma omp task in_reduction(min: arr1) depend(iterator(int i = 0:argc, unsigned int j = argc:0:a), out : argv[i][j])
187 foo();
188 // CHECK-NEXT: foo();
189 // CHECK-NEXT: #pragma omp task in_reduction(+: arr1)
190 #pragma omp task in_reduction(+: arr1)
191 foo();
192 // CHECK-NEXT: foo();
193 // CHECK-NEXT: #pragma omp task depend(out : arr,omp_all_memory)
194 #pragma omp task depend(out: omp_all_memory, arr)
195 foo();
196 // CHECK-NEXT: foo();
197 // CHECK-NEXT: #pragma omp task depend(inout : b,arr,a,x,omp_all_memory)
198 #pragma omp task depend(inout: b, arr, omp_all_memory, a, x)
199 foo();
200 // CHECK-NEXT: foo();
201 // CHECK-NEXT: #pragma omp task depend(inout : omp_all_memory)
202 #pragma omp task depend(inout: omp_all_memory)
203 foo();
204 // CHECK-NEXT: foo();
205 return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);
208 extern template int S<int>::TS;
209 extern template long S<long>::TS;
211 #endif