[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / for_simd_ast_print.cpp
blob7f77107b8ed7ce8d52aac57edd7e382dccf076bc
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 -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
4 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
5 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
6 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -verify %s -ast-print -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
7 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -ast-print %s -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
8 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
9 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -std=c++11 -include-pch %t -verify %s -ast-print -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
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 -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 -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
17 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
18 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
19 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify %s -ast-print -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
20 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -ast-print %s -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
21 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
22 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -std=c++11 -include-pch %t -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 -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 S1 {
33 S1(): a(0) {}
34 S1(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 S7() : a(0) {}
45 public:
46 S7(typename T::type v) : a(v) {
47 #pragma omp for simd private(a) private(this->a) private(T::a)
48 for (int k = 0; k < a.a; ++k)
49 ++this->a.a;
51 S7 &operator=(S7 &s) {
52 #pragma omp for simd private(a) private(this->a)
53 for (int k = 0; k < s.a.a; ++k)
54 ++s.a.a;
55 return *this;
59 // CHECK: #pragma omp for simd private(this->a) private(this->a) private(T::a){{$}}
60 // CHECK: #pragma omp for simd private(this->a) private(this->a)
61 // CHECK: #pragma omp for simd private(this->a) private(this->a) private(this->S1::a)
63 class S8 : public S7<S1> {
64 S8() {}
66 public:
67 S8(int v) : S7<S1>(v){
68 #pragma omp for simd private(a) private(this->a) private(S7<S1>::a)
69 for (int k = 0; k < a.a; ++k)
70 ++this->a.a;
72 S8 &operator=(S8 &s) {
73 #pragma omp for simd private(a) private(this->a)
74 for (int k = 0; k < s.a.a; ++k)
75 ++s.a.a;
76 return *this;
80 // CHECK: #pragma omp for simd private(this->a) private(this->a) private(this->S7<S1>::a)
81 // CHECK: #pragma omp for simd private(this->a) private(this->a)
83 void foo() {}
84 int g_ind = 1;
85 template<class T, class N> T reduct(T* arr, N num) {
86 N i;
87 N ind;
88 N myind;
89 T sum = (T)0;
90 // CHECK: T sum = (T)0;
91 #pragma omp for simd private(myind, g_ind), linear(ind), aligned(arr) ordered
92 // CHECK-NEXT: #pragma omp for simd private(myind,g_ind) linear(ind) aligned(arr) ordered
93 for (i = 0; i < num; ++i) {
94 myind = ind;
95 T cur = arr[myind];
96 ind += g_ind;
97 sum += cur;
101 template<class T> struct S {
102 S(const T &a)
103 :m_a(a)
105 T result(T *v) const {
106 T res;
107 T val;
108 T lin = 0;
109 // CHECK: T res;
110 // CHECK: T val;
111 // CHECK: T lin = 0;
112 #ifdef OMP52
113 #pragma omp for simd private(val) safelen(7) linear(lin : step(-5)) lastprivate(res) simdlen(5) allocate(res) if(res) nontemporal(res, val, lin) order(reproducible:concurrent)
114 #elif OMP51
115 #pragma omp for simd private(val) safelen(7) linear(lin : -5) lastprivate(res) simdlen(5) allocate(res) if(res) nontemporal(res, val, lin) order(reproducible:concurrent)
116 #elif OMP5
117 #pragma omp for simd private(val) safelen(7) linear(lin : -5) lastprivate(res) simdlen(5) allocate(res) if(res) nontemporal(res, val, lin) order(concurrent)
118 #else
119 #pragma omp for simd private(val) safelen(7) linear(lin : -5) lastprivate(res) simdlen(5) allocate(res)
120 #endif // OMP51
121 // OMP52-NEXT: #pragma omp for simd private(val) safelen(7) linear(lin: step(-5)) lastprivate(res) simdlen(5) allocate(res) if(res) nontemporal(res,val,lin) order(reproducible: concurrent)
122 // OMP51-NEXT: #pragma omp for simd private(val) safelen(7) linear(lin: step(-5)) lastprivate(res) simdlen(5) allocate(res) if(res) nontemporal(res,val,lin) order(reproducible: concurrent)
123 // OMP50-NEXT: #pragma omp for simd private(val) safelen(7) linear(lin: step(-5)) lastprivate(res) simdlen(5) allocate(res) if(res) nontemporal(res,val,lin) order(concurrent)
124 // OMP45-NEXT: #pragma omp for simd private(val) safelen(7) linear(lin: step(-5)) lastprivate(res) simdlen(5) allocate(res)
125 for (T i = 7; i < m_a; ++i) {
126 val = v[i-7] + m_a;
127 res = val;
128 lin -= 5;
130 const T clen = 3;
131 // CHECK: T clen = 3;
132 #pragma omp for simd safelen(clen-1) simdlen(clen-1)
133 // CHECK-NEXT: #pragma omp for simd safelen(clen - 1) simdlen(clen - 1)
134 for(T i = clen+2; i < 20; ++i) {
135 // CHECK-NEXT: for (T i = clen + 2; i < 20; ++i) {
136 v[i] = v[v-clen] + 1;
137 // CHECK-NEXT: v[i] = v[v - clen] + 1;
139 // CHECK-NEXT: }
140 return res;
142 ~S()
144 T m_a;
147 template<int LEN> struct S2 {
148 static void func(int n, float *a, float *b, float *c) {
149 int k1 = 0, k2 = 0;
150 #pragma omp for simd allocate(k1) safelen(LEN) linear(k1,k2:LEN) aligned(a:LEN) simdlen(LEN)
151 for(int i = 0; i < n; i++) {
152 c[i] = a[i] + b[i];
153 c[k1] = a[k1] + b[k1];
154 c[k2] = a[k2] + b[k2];
155 k1 = k1 + LEN;
156 k2 = k2 + LEN;
161 // S2<4>::func is called below in main.
162 // CHECK: template<> struct S2<4> {
163 // CHECK-NEXT: static void func(int n, float *a, float *b, float *c) {
164 // CHECK-NEXT: int k1 = 0, k2 = 0;
165 // CHECK-NEXT: #pragma omp for simd allocate(k1) safelen(4) linear(k1,k2: step(4)) aligned(a: 4) simdlen(4)
166 // CHECK-NEXT: for (int i = 0; i < n; i++) {
167 // CHECK-NEXT: c[i] = a[i] + b[i];
168 // CHECK-NEXT: c[k1] = a[k1] + b[k1];
169 // CHECK-NEXT: c[k2] = a[k2] + b[k2];
170 // CHECK-NEXT: k1 = k1 + 4;
171 // CHECK-NEXT: k2 = k2 + 4;
172 // CHECK-NEXT: }
173 // CHECK-NEXT: }
175 int main (int argc, char **argv) {
176 int b = argc, c, d, e, f, g;
177 int k1=0,k2=0;
178 static int *a;
179 // CHECK: static int *a;
180 #pragma omp for simd ordered
181 // CHECK-NEXT: #pragma omp for simd ordered
182 for (int i=0; i < 2; ++i)*a=2;
183 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
184 // CHECK-NEXT: *a = 2;
185 #pragma omp parallel
186 #pragma omp for simd private(argc, b),lastprivate(d,f) collapse(2) aligned(a : 4) ,firstprivate( g )
187 for (int i = 0; i < 10; ++i)
188 for (int j = 0; j < 10; ++j) {foo(); k1 += 8; k2 += 8;}
189 // CHECK-NEXT: #pragma omp parallel
190 // CHECK-NEXT: #pragma omp for simd private(argc,b) lastprivate(d,f) collapse(2) aligned(a: 4) firstprivate(g)
191 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
192 // CHECK-NEXT: for (int j = 0; j < 10; ++j) {
193 // CHECK-NEXT: foo();
194 // CHECK-NEXT: k1 += 8;
195 // CHECK-NEXT: k2 += 8;
196 // CHECK-NEXT: }
197 for (int i = 0; i < 10; ++i)foo();
198 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
199 // CHECK-NEXT: foo();
200 const int CLEN = 4;
201 // CHECK-NEXT: const int CLEN = 4;
202 #ifdef OMP5
203 #pragma omp for simd aligned(a:CLEN) linear(a:CLEN) safelen(CLEN) collapse( 1 ) simdlen(CLEN) if(simd:a)
204 #else
205 #pragma omp for simd aligned(a:CLEN) linear(a:CLEN) safelen(CLEN) collapse( 1 ) simdlen(CLEN)
206 #endif
207 // OMP52-NEXT: #pragma omp for simd aligned(a: CLEN) linear(a: step(CLEN)) safelen(CLEN) collapse(1) simdlen(CLEN)
208 // OMP51-NEXT: #pragma omp for simd aligned(a: CLEN) linear(a: step(CLEN)) safelen(CLEN) collapse(1) simdlen(CLEN)
209 // OMP50-NEXT: #pragma omp for simd aligned(a: CLEN) linear(a: step(CLEN)) safelen(CLEN) collapse(1) simdlen(CLEN) if(simd: a)
210 // OMP45-NEXT: #pragma omp for simd aligned(a: CLEN) linear(a: step(CLEN)) safelen(CLEN) collapse(1) simdlen(CLEN)
211 for (int i = 0; i < 10; ++i)foo();
212 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
213 // CHECK-NEXT: foo();
215 float arr[16];
216 S2<4>::func(0,arr,arr,arr);
217 return (0);
220 #endif