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