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