Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / simd_ast_print.cpp
blob057f1e7c03c0ec2cc95406620e06d23f8b3a1a04
1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -ast-print %s | 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 -fsyntax-only -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
4 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -ast-print %s -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
5 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
6 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
7 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
8 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
9 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
10 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -ast-print %s -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
11 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP52
12 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
14 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
15 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o %t %s
16 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
17 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=50 -ast-print %s -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
18 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
19 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
20 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
21 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
22 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
23 // expected-no-diagnostics
24 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -ast-print %s -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
25 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP52
26 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
27 // expected-no-diagnostics
29 #ifndef HEADER
30 #define HEADER
32 struct SS {
33 SS(): a(0) {}
34 SS(int v) : a(v) {}
35 int a;
36 typedef int type;
39 template <typename T>
40 class S7 : public T {
41 protected:
42 T *a;
43 T b[2];
44 S7() : a(0) {}
46 public:
47 S7(typename T::type &v) : a((T*)&v) {
48 #pragma omp simd aligned(a)
49 for (int k = 0; k < a->a; ++k)
50 ++this->a->a;
52 S7 &operator=(S7 &s) {
53 #pragma omp simd aligned(this->b : 8)
54 for (int k = 0; k < s.a->a; ++k)
55 ++s.a->a;
56 return *this;
60 // CHECK: #pragma omp simd aligned(this->a){{$}}
61 // CHECK: #pragma omp simd aligned(this->b: 8)
62 // CHECK: #pragma omp simd aligned(this->a)
64 class S8 : public S7<SS> {
65 S8() {}
67 public:
68 S8(int v) : S7<SS>(v){
69 #pragma omp simd aligned(S7<SS>::a)
70 for (int k = 0; k < a->a; ++k)
71 ++this->a->a;
73 S8 &operator=(S8 &s) {
74 #pragma omp simd aligned(this->b: 4)
75 for (int k = 0; k < s.a->a; ++k)
76 ++s.a->a;
77 return *this;
81 // CHECK: #pragma omp simd aligned(this->S7<SS>::a)
82 // CHECK: #pragma omp simd aligned(this->b: 4)
84 void foo() {}
85 int g_ind = 1;
86 template<class T, class N> T reduct(T* arr, N num) {
87 N i;
88 N ind;
89 N myind;
90 N &r = i;
91 T sum = (T)0;
92 // CHECK: T sum = (T)0;
93 #ifdef OMP52
94 #pragma omp simd private(myind, g_ind), linear(ind), aligned(arr), linear(r: uval)
95 #else
96 #pragma omp simd private(myind, g_ind), linear(ind), aligned(arr), linear(uval(r))
97 #endif
98 // CHECK-NEXT: #pragma omp simd private(myind,g_ind) linear(ind) aligned(arr) linear(r: uval)
99 for (i = 0; i < num; ++i) {
100 myind = ind;
101 T cur = arr[myind];
102 ind += g_ind;
103 sum += cur;
107 template<class T> struct S {
108 S(const T &a)
109 :m_a(a)
111 T result(T *v) const {
112 T res;
113 T val;
114 T lin = 0;
115 T &r = res;
116 // CHECK: T res;
117 // CHECK: T val;
118 // CHECK: T lin = 0;
119 // CHECK: T &r = res;
120 #ifdef OMP52
121 #pragma omp simd allocate(res) private(val) safelen(7) linear(lin : step(-5)) lastprivate(res) simdlen(5) linear(r: ref)
122 #else
123 #pragma omp simd allocate(res) private(val) safelen(7) linear(lin : -5) lastprivate(res) simdlen(5) linear(ref(r))
124 #endif
125 // CHECK-NEXT: #pragma omp simd allocate(res) private(val) safelen(7) linear(lin: step(-5)) lastprivate(res) simdlen(5) linear(r: ref)
126 for (T i = 7; i < m_a; ++i) {
127 val = v[i-7] + m_a;
128 res = val;
129 lin -= 5;
131 const T clen = 3;
132 // CHECK: T clen = 3;
133 #pragma omp simd safelen(clen-1) simdlen(clen-1)
134 // CHECK-NEXT: #pragma omp simd safelen(clen - 1) simdlen(clen - 1)
135 for(T i = clen+2; i < 20; ++i) {
136 // CHECK-NEXT: for (T i = clen + 2; i < 20; ++i) {
137 v[i] = v[v-clen] + 1;
138 // CHECK-NEXT: v[i] = v[v - clen] + 1;
140 // CHECK-NEXT: }
141 return res;
143 ~S()
145 T m_a;
148 template<int LEN> struct S2 {
149 static void func(int n, float *a, float *b, float *c) {
150 int k1 = 0, k2 = 0;
151 #pragma omp simd safelen(LEN) linear(k1,k2:LEN) aligned(a:LEN) simdlen(LEN) allocate(k1)
152 for(int i = 0; i < n; i++) {
153 c[i] = a[i] + b[i];
154 c[k1] = a[k1] + b[k1];
155 c[k2] = a[k2] + b[k2];
156 k1 = k1 + LEN;
157 k2 = k2 + LEN;
162 // S2<4>::func is called below in main.
163 // CHECK: template<> struct S2<4> {
164 // CHECK-NEXT: static void func(int n, float *a, float *b, float *c) {
165 // CHECK-NEXT: int k1 = 0, k2 = 0;
166 // CHECK-NEXT: #pragma omp simd safelen(4) linear(k1,k2: step(4)) aligned(a: 4) simdlen(4) allocate(k1)
167 // CHECK-NEXT: for (int i = 0; i < n; i++) {
168 // CHECK-NEXT: c[i] = a[i] + b[i];
169 // CHECK-NEXT: c[k1] = a[k1] + b[k1];
170 // CHECK-NEXT: c[k2] = a[k2] + b[k2];
171 // CHECK-NEXT: k1 = k1 + 4;
172 // CHECK-NEXT: k2 = k2 + 4;
173 // CHECK-NEXT: }
174 // CHECK-NEXT: }
176 int main (int argc, char **argv) {
177 int b = argc, c, d, e, f, g;
178 int k1=0,k2=0;
179 int &r = b;
180 static int *a;
181 // CHECK: static int *a;
182 #pragma omp simd
183 // CHECK-NEXT: #pragma omp simd{{$}}
184 for (int i=0; i < 2; ++i)*a=2;
185 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
186 // CHECK-NEXT: *a = 2;
187 #ifdef OMP52
188 #pragma omp simd private(argc, b),lastprivate(d,f) collapse(2) aligned(a : 4) if(simd:a) nontemporal(argc, c, d) lastprivate(conditional: e, f) order(unconstrained:concurrent)
189 // OMP52-NEXT: #pragma omp simd private(argc,b) lastprivate(d,f) collapse(2) aligned(a: 4) if(simd: a) nontemporal(argc,c,d) lastprivate(conditional: e,f) order(unconstrained: concurrent)
190 #elif OMP51
191 #pragma omp simd private(argc, b),lastprivate(d,f) collapse(2) aligned(a : 4) if(simd:a) nontemporal(argc, c, d) lastprivate(conditional: e, f) order(unconstrained:concurrent)
192 // OMP51-NEXT: #pragma omp simd private(argc,b) lastprivate(d,f) collapse(2) aligned(a: 4) if(simd: a) nontemporal(argc,c,d) lastprivate(conditional: e,f) order(unconstrained: concurrent)
193 #elif OMP5
194 #pragma omp simd private(argc, b),lastprivate(d,f) collapse(2) aligned(a : 4) if(simd:a) nontemporal(argc, c, d) lastprivate(conditional: e, f) order(concurrent)
195 // OMP50-NEXT: #pragma omp simd private(argc,b) lastprivate(d,f) collapse(2) aligned(a: 4) if(simd: a) nontemporal(argc,c,d) lastprivate(conditional: e,f) order(concurrent)
196 #else
197 #pragma omp simd private(argc, b),lastprivate(d,f) collapse(2) aligned(a : 4)
198 // OMP45-NEXT: #pragma omp simd private(argc,b) lastprivate(d,f) collapse(2) aligned(a: 4)
199 #endif // OMP51
200 for (int i = 0; i < 10; ++i)
201 for (int j = 0; j < 10; ++j) {foo(); k1 += 8; k2 += 8;}
202 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
203 // CHECK-NEXT: for (int j = 0; j < 10; ++j) {
204 // CHECK-NEXT: foo();
205 // CHECK-NEXT: k1 += 8;
206 // CHECK-NEXT: k2 += 8;
207 // CHECK-NEXT: }
208 for (int i = 0; i < 10; ++i)foo();
209 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
210 // CHECK-NEXT: foo();
211 const int CLEN = 4;
212 // CHECK-NEXT: const int CLEN = 4;
213 #ifdef OMP52
214 #pragma omp simd aligned(a:CLEN) linear(a: step(CLEN)) safelen(CLEN) collapse( 1 ) simdlen(CLEN) linear(r: val, step(CLEN)) if(a)
215 #elif OMP5
216 #pragma omp simd aligned(a:CLEN) linear(a:CLEN) safelen(CLEN) collapse( 1 ) simdlen(CLEN) linear(val(r): CLEN) if(a)
217 // OMP50-NEXT: #pragma omp simd aligned(a: CLEN) linear(a: step(CLEN)) safelen(CLEN) collapse(1) simdlen(CLEN) linear(r: val, step(CLEN)) if(a)
218 #else
219 #pragma omp simd aligned(a:CLEN) linear(a:CLEN) safelen(CLEN) collapse( 1 ) simdlen(CLEN) linear(val(r): CLEN)
220 // OMP45-NEXT: #pragma omp simd aligned(a: CLEN) linear(a: step(CLEN)) safelen(CLEN) collapse(1) simdlen(CLEN) linear(r: val, step(CLEN))
221 // OMP51-NEXT: #pragma omp simd aligned(a: CLEN) linear(a: step(CLEN)) safelen(CLEN) collapse(1) simdlen(CLEN) linear(r: val, step(CLEN))
222 // OMP52-NEXT: #pragma omp simd aligned(a: CLEN) linear(a: step(CLEN)) safelen(CLEN) collapse(1) simdlen(CLEN) linear(r: val, step(CLEN))
223 #endif // OMP5
224 for (int i = 0; i < 10; ++i)foo();
225 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
226 // CHECK-NEXT: foo();
228 float arr[16];
229 S2<4>::func(0,arr,arr,arr);
230 return (0);
233 #endif