[OpenACC] Treat 'delete' as a valid clause during parsing in C++ mode
[llvm-project.git] / clang / test / OpenMP / parallel_for_simd_ast_print.cpp
blobb1fe98e17113091aeb9221ab0b8d5f07d759e02a
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 -DOMP5 -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
5 // RUN: %clang_cc1 -fopenmp -DOMP5 -x c++ -std=c++11 -emit-pch -o %t %s
6 // RUN: %clang_cc1 -fopenmp -DOMP5 -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
7 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -DOMP51 -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
8 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -DOMP51 -x c++ -std=c++11 -emit-pch -o %t %s
9 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -DOMP51 -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
11 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
12 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o %t %s
13 // 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
14 // RUN: %clang_cc1 -verify -fopenmp-simd -DOMP5 -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
15 // RUN: %clang_cc1 -fopenmp-simd -DOMP5 -x c++ -std=c++11 -emit-pch -o %t %s
16 // RUN: %clang_cc1 -fopenmp-simd -DOMP5 -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
17 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -DOMP51 -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
18 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -DOMP51 -x c++ -std=c++11 -emit-pch -o %t %s
19 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -DOMP51 -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
20 // expected-no-diagnostics
22 #ifndef HEADER
23 #define HEADER
25 void foo() {}
27 struct S1 {
28 S1() : a(0) {}
29 S1(int v) : a(v) {}
30 int a;
31 typedef int type;
34 template <typename T>
35 class S7 : public T {
36 protected:
37 T a;
38 S7() : a(0) {}
40 public:
41 S7(typename T::type v) : a(v) {
42 #pragma omp parallel for simd private(a) private(this->a) private(T::a)
43 for (int k = 0; k < a.a; ++k)
44 ++this->a.a;
46 S7 &operator=(S7 &s) {
47 #pragma omp parallel for simd private(a) private(this->a)
48 for (int k = 0; k < s.a.a; ++k)
49 ++s.a.a;
50 return *this;
54 // CHECK: #pragma omp parallel for simd private(this->a) private(this->a) private(T::a){{$}}
55 // CHECK: #pragma omp parallel for simd private(this->a) private(this->a)
56 // CHECK: #pragma omp parallel for simd private(this->a) private(this->a) private(this->S1::a)
58 class S8 : public S7<S1> {
59 S8() {}
61 public:
62 S8(int v) : S7<S1>(v){
63 #pragma omp parallel for simd private(a) private(this->a) private(S7 <S1>::a)
64 for (int k = 0; k < a.a; ++k)
65 ++this->a.a;
67 S8 &operator=(S8 &s) {
68 #pragma omp parallel for simd private(a) private(this->a)
69 for (int k = 0; k < s.a.a; ++k)
70 ++s.a.a;
71 return *this;
75 // CHECK: #pragma omp parallel for simd private(this->a) private(this->a) private(this->S7<S1>::a)
76 // CHECK: #pragma omp parallel for simd private(this->a) private(this->a)
78 int g_ind = 1;
79 template<class T, class N> T reduct(T* arr, N num) {
80 N i;
81 N ind;
82 N myind;
83 T sum = (T)0;
84 // CHECK: T sum = (T)0;
85 #pragma omp parallel for simd private(myind, g_ind), linear(ind), aligned(arr) if (parallel :num)
86 // CHECK-NEXT: #pragma omp parallel for simd private(myind,g_ind) linear(ind) aligned(arr) if(parallel: num)
87 for (i = 0; i < num; ++i) {
88 myind = ind;
89 T cur = arr[myind];
90 ind += g_ind;
91 sum += cur;
95 template<class T> struct S {
96 S(const T &a)
97 :m_a(a)
99 T result(T *v) const {
100 T res;
101 T val;
102 T lin = 0;
103 // CHECK: T res;
104 // CHECK: T val;
105 // CHECK: T lin = 0;
106 #pragma omp parallel for simd private(val) safelen(7) linear(lin : -5) lastprivate(res) simdlen(5) if(7) allocate(lin)
107 // CHECK-NEXT: #pragma omp parallel for simd private(val) safelen(7) linear(lin: step(-5)) lastprivate(res) simdlen(5) if(7) allocate(lin)
108 for (T i = 7; i < m_a; ++i) {
109 val = v[i-7] + m_a;
110 res = val;
111 lin -= 5;
113 const T clen = 3;
114 // CHECK: T clen = 3;
115 #pragma omp parallel for simd safelen(clen-1) simdlen(clen-1) ordered
116 // CHECK-NEXT: #pragma omp parallel for simd safelen(clen - 1) simdlen(clen - 1) ordered
117 for(T i = clen+2; i < 20; ++i) {
118 // CHECK-NEXT: for (T i = clen + 2; i < 20; ++i) {
119 v[i] = v[v-clen] + 1;
120 // CHECK-NEXT: v[i] = v[v - clen] + 1;
122 // CHECK-NEXT: }
123 return res;
125 ~S()
127 T m_a;
130 template<int LEN> struct S2 {
131 static void func(int n, float *a, float *b, float *c) {
132 int k1 = 0, k2 = 0;
133 #pragma omp parallel for simd allocate(k1) safelen(LEN) linear(k1,k2:LEN) aligned(a:LEN) simdlen(LEN)
134 for(int i = 0; i < n; i++) {
135 c[i] = a[i] + b[i];
136 c[k1] = a[k1] + b[k1];
137 c[k2] = a[k2] + b[k2];
138 k1 = k1 + LEN;
139 k2 = k2 + LEN;
144 // S2<4>::func is called below in main.
145 // CHECK: template<> struct S2<4> {
146 // CHECK-NEXT: static void func(int n, float *a, float *b, float *c) {
147 // CHECK-NEXT: int k1 = 0, k2 = 0;
148 // CHECK-NEXT: #pragma omp parallel for simd allocate(k1) safelen(4) linear(k1,k2: step(4)) aligned(a: 4) simdlen(4)
149 // CHECK-NEXT: for (int i = 0; i < n; i++) {
150 // CHECK-NEXT: c[i] = a[i] + b[i];
151 // CHECK-NEXT: c[k1] = a[k1] + b[k1];
152 // CHECK-NEXT: c[k2] = a[k2] + b[k2];
153 // CHECK-NEXT: k1 = k1 + 4;
154 // CHECK-NEXT: k2 = k2 + 4;
155 // CHECK-NEXT: }
156 // CHECK-NEXT: }
158 int main (int argc, char **argv) {
159 int b = argc, c, d, e, f, g;
160 int k1=0,k2=0;
161 static int *a;
162 // CHECK: static int *a;
163 #ifdef OMP51
164 #pragma omp parallel for simd if(parallel :b) if(simd: b) nontemporal(argc, c) lastprivate(conditional:d,f) order(unconstrained:concurrent)
165 #elif OMP5
166 #pragma omp parallel for simd if(parallel :b) if(simd: b) nontemporal(argc, c) lastprivate(conditional:d,f) order(concurrent)
167 #else
168 #pragma omp parallel for simd if(parallel :b) ordered
169 #endif // OMP51
170 // OMP51-NEXT: #pragma omp parallel for simd if(parallel: b) if(simd: b) nontemporal(argc,c) lastprivate(conditional: d,f) order(unconstrained: concurrent)
171 // OMP50-NEXT: #pragma omp parallel for simd if(parallel: b) if(simd: b) nontemporal(argc,c) lastprivate(conditional: d,f) order(concurrent)
172 // OMP45-NEXT: #pragma omp parallel for simd if(parallel: b) ordered
173 for (int i=0; i < 2; ++i)*a=2;
174 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
175 // CHECK-NEXT: *a = 2;
176 #pragma omp parallel
177 #pragma omp parallel for simd private(argc, b),lastprivate(d,f) collapse(2) aligned(a : 4) ,firstprivate( g ) if(g)
178 for (int i = 0; i < 10; ++i)
179 for (int j = 0; j < 10; ++j) {foo(); k1 += 8; k2 += 8;}
180 // CHECK-NEXT: #pragma omp parallel
181 // CHECK-NEXT: #pragma omp parallel for simd private(argc,b) lastprivate(d,f) collapse(2) aligned(a: 4) firstprivate(g) if(g)
182 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
183 // CHECK-NEXT: for (int j = 0; j < 10; ++j) {
184 // CHECK-NEXT: foo();
185 // CHECK-NEXT: k1 += 8;
186 // CHECK-NEXT: k2 += 8;
187 // CHECK-NEXT: }
188 for (int i = 0; i < 10; ++i)foo();
189 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
190 // CHECK-NEXT: foo();
191 const int CLEN = 4;
192 // CHECK-NEXT: const int CLEN = 4;
193 #pragma omp parallel for simd aligned(a:CLEN) linear(a:CLEN) safelen(CLEN) collapse( 1 ) simdlen(CLEN)
194 // CHECK-NEXT: #pragma omp parallel for simd aligned(a: CLEN) linear(a: step(CLEN)) safelen(CLEN) collapse(1) simdlen(CLEN)
195 for (int i = 0; i < 10; ++i)foo();
196 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
197 // CHECK-NEXT: foo();
199 float arr[16];
200 S2<4>::func(0,arr,arr,arr);
201 return (0);
204 #endif