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