1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ast-print %s | FileCheck %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -emit-pch -o %t %s
3*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fopenmp=libiomp5 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
4*0a6a1f1dSLionel Sambuc // expected-no-diagnostics
5*0a6a1f1dSLionel Sambuc
6*0a6a1f1dSLionel Sambuc #ifndef HEADER
7*0a6a1f1dSLionel Sambuc #define HEADER
8*0a6a1f1dSLionel Sambuc
foo()9*0a6a1f1dSLionel Sambuc void foo() {}
10*0a6a1f1dSLionel Sambuc int g_ind = 1;
reduct(T * arr,N num)11*0a6a1f1dSLionel Sambuc template<class T, class N> T reduct(T* arr, N num) {
12*0a6a1f1dSLionel Sambuc N i;
13*0a6a1f1dSLionel Sambuc N ind;
14*0a6a1f1dSLionel Sambuc N myind;
15*0a6a1f1dSLionel Sambuc T sum = (T)0;
16*0a6a1f1dSLionel Sambuc // CHECK: T sum = (T)0;
17*0a6a1f1dSLionel Sambuc #pragma omp simd private(myind, g_ind), linear(ind), aligned(arr)
18*0a6a1f1dSLionel Sambuc // CHECK-NEXT: #pragma omp simd private(myind,g_ind) linear(ind) aligned(arr)
19*0a6a1f1dSLionel Sambuc for (i = 0; i < num; ++i) {
20*0a6a1f1dSLionel Sambuc myind = ind;
21*0a6a1f1dSLionel Sambuc T cur = arr[myind];
22*0a6a1f1dSLionel Sambuc ind += g_ind;
23*0a6a1f1dSLionel Sambuc sum += cur;
24*0a6a1f1dSLionel Sambuc }
25*0a6a1f1dSLionel Sambuc }
26*0a6a1f1dSLionel Sambuc
27*0a6a1f1dSLionel Sambuc template<class T> struct S {
SS28*0a6a1f1dSLionel Sambuc S(const T &a)
29*0a6a1f1dSLionel Sambuc :m_a(a)
30*0a6a1f1dSLionel Sambuc {}
resultS31*0a6a1f1dSLionel Sambuc T result(T *v) const {
32*0a6a1f1dSLionel Sambuc T res;
33*0a6a1f1dSLionel Sambuc T val;
34*0a6a1f1dSLionel Sambuc T lin = 0;
35*0a6a1f1dSLionel Sambuc // CHECK: T res;
36*0a6a1f1dSLionel Sambuc // CHECK: T val;
37*0a6a1f1dSLionel Sambuc // CHECK: T lin = 0;
38*0a6a1f1dSLionel Sambuc #pragma omp simd private(val) safelen(7) linear(lin : -5) lastprivate(res)
39*0a6a1f1dSLionel Sambuc // CHECK-NEXT: #pragma omp simd private(val) safelen(7) linear(lin: -5) lastprivate(res)
40*0a6a1f1dSLionel Sambuc for (T i = 7; i < m_a; ++i) {
41*0a6a1f1dSLionel Sambuc val = v[i-7] + m_a;
42*0a6a1f1dSLionel Sambuc res = val;
43*0a6a1f1dSLionel Sambuc lin -= 5;
44*0a6a1f1dSLionel Sambuc }
45*0a6a1f1dSLionel Sambuc const T clen = 3;
46*0a6a1f1dSLionel Sambuc // CHECK: T clen = 3;
47*0a6a1f1dSLionel Sambuc #pragma omp simd safelen(clen-1)
48*0a6a1f1dSLionel Sambuc // CHECK-NEXT: #pragma omp simd safelen(clen - 1)
49*0a6a1f1dSLionel Sambuc for(T i = clen+2; i < 20; ++i) {
50*0a6a1f1dSLionel Sambuc // CHECK-NEXT: for (T i = clen + 2; i < 20; ++i) {
51*0a6a1f1dSLionel Sambuc v[i] = v[v-clen] + 1;
52*0a6a1f1dSLionel Sambuc // CHECK-NEXT: v[i] = v[v - clen] + 1;
53*0a6a1f1dSLionel Sambuc }
54*0a6a1f1dSLionel Sambuc // CHECK-NEXT: }
55*0a6a1f1dSLionel Sambuc return res;
56*0a6a1f1dSLionel Sambuc }
~SS57*0a6a1f1dSLionel Sambuc ~S()
58*0a6a1f1dSLionel Sambuc {}
59*0a6a1f1dSLionel Sambuc T m_a;
60*0a6a1f1dSLionel Sambuc };
61*0a6a1f1dSLionel Sambuc
62*0a6a1f1dSLionel Sambuc template<int LEN> struct S2 {
funcS263*0a6a1f1dSLionel Sambuc static void func(int n, float *a, float *b, float *c) {
64*0a6a1f1dSLionel Sambuc int k1 = 0, k2 = 0;
65*0a6a1f1dSLionel Sambuc #pragma omp simd safelen(LEN) linear(k1,k2:LEN) aligned(a:LEN)
66*0a6a1f1dSLionel Sambuc for(int i = 0; i < n; i++) {
67*0a6a1f1dSLionel Sambuc c[i] = a[i] + b[i];
68*0a6a1f1dSLionel Sambuc c[k1] = a[k1] + b[k1];
69*0a6a1f1dSLionel Sambuc c[k2] = a[k2] + b[k2];
70*0a6a1f1dSLionel Sambuc k1 = k1 + LEN;
71*0a6a1f1dSLionel Sambuc k2 = k2 + LEN;
72*0a6a1f1dSLionel Sambuc }
73*0a6a1f1dSLionel Sambuc }
74*0a6a1f1dSLionel Sambuc };
75*0a6a1f1dSLionel Sambuc
76*0a6a1f1dSLionel Sambuc // S2<4>::func is called below in main.
77*0a6a1f1dSLionel Sambuc // CHECK: template <int LEN = 4> struct S2 {
78*0a6a1f1dSLionel Sambuc // CHECK-NEXT: static void func(int n, float *a, float *b, float *c) {
79*0a6a1f1dSLionel Sambuc // CHECK-NEXT: int k1 = 0, k2 = 0;
80*0a6a1f1dSLionel Sambuc // CHECK-NEXT: #pragma omp simd safelen(4) linear(k1,k2: 4) aligned(a: 4)
81*0a6a1f1dSLionel Sambuc // CHECK-NEXT: for (int i = 0; i < n; i++) {
82*0a6a1f1dSLionel Sambuc // CHECK-NEXT: c[i] = a[i] + b[i];
83*0a6a1f1dSLionel Sambuc // CHECK-NEXT: c[k1] = a[k1] + b[k1];
84*0a6a1f1dSLionel Sambuc // CHECK-NEXT: c[k2] = a[k2] + b[k2];
85*0a6a1f1dSLionel Sambuc // CHECK-NEXT: k1 = k1 + 4;
86*0a6a1f1dSLionel Sambuc // CHECK-NEXT: k2 = k2 + 4;
87*0a6a1f1dSLionel Sambuc // CHECK-NEXT: }
88*0a6a1f1dSLionel Sambuc // CHECK-NEXT: }
89*0a6a1f1dSLionel Sambuc
main(int argc,char ** argv)90*0a6a1f1dSLionel Sambuc int main (int argc, char **argv) {
91*0a6a1f1dSLionel Sambuc int b = argc, c, d, e, f, g;
92*0a6a1f1dSLionel Sambuc int k1=0,k2=0;
93*0a6a1f1dSLionel Sambuc static int *a;
94*0a6a1f1dSLionel Sambuc // CHECK: static int *a;
95*0a6a1f1dSLionel Sambuc #pragma omp simd
96*0a6a1f1dSLionel Sambuc // CHECK-NEXT: #pragma omp simd
97*0a6a1f1dSLionel Sambuc for (int i=0; i < 2; ++i)*a=2;
98*0a6a1f1dSLionel Sambuc // CHECK-NEXT: for (int i = 0; i < 2; ++i)
99*0a6a1f1dSLionel Sambuc // CHECK-NEXT: *a = 2;
100*0a6a1f1dSLionel Sambuc #pragma omp simd private(argc, b),lastprivate(d,f) collapse(2) aligned(a : 4)
101*0a6a1f1dSLionel Sambuc for (int i = 0; i < 10; ++i)
102*0a6a1f1dSLionel Sambuc for (int j = 0; j < 10; ++j) {foo(); k1 += 8; k2 += 8;}
103*0a6a1f1dSLionel Sambuc // CHECK-NEXT: #pragma omp simd private(argc,b) lastprivate(d,f) collapse(2) aligned(a: 4)
104*0a6a1f1dSLionel Sambuc // CHECK-NEXT: for (int i = 0; i < 10; ++i)
105*0a6a1f1dSLionel Sambuc // CHECK-NEXT: for (int j = 0; j < 10; ++j) {
106*0a6a1f1dSLionel Sambuc // CHECK-NEXT: foo();
107*0a6a1f1dSLionel Sambuc // CHECK-NEXT: k1 += 8;
108*0a6a1f1dSLionel Sambuc // CHECK-NEXT: k2 += 8;
109*0a6a1f1dSLionel Sambuc // CHECK-NEXT: }
110*0a6a1f1dSLionel Sambuc for (int i = 0; i < 10; ++i)foo();
111*0a6a1f1dSLionel Sambuc // CHECK-NEXT: for (int i = 0; i < 10; ++i)
112*0a6a1f1dSLionel Sambuc // CHECK-NEXT: foo();
113*0a6a1f1dSLionel Sambuc const int CLEN = 4;
114*0a6a1f1dSLionel Sambuc // CHECK-NEXT: const int CLEN = 4;
115*0a6a1f1dSLionel Sambuc #pragma omp simd aligned(a:CLEN) linear(a:CLEN) safelen(CLEN) collapse( 1 )
116*0a6a1f1dSLionel Sambuc // CHECK-NEXT: #pragma omp simd aligned(a: CLEN) linear(a: CLEN) safelen(CLEN) collapse(1)
117*0a6a1f1dSLionel Sambuc for (int i = 0; i < 10; ++i)foo();
118*0a6a1f1dSLionel Sambuc // CHECK-NEXT: for (int i = 0; i < 10; ++i)
119*0a6a1f1dSLionel Sambuc // CHECK-NEXT: foo();
120*0a6a1f1dSLionel Sambuc
121*0a6a1f1dSLionel Sambuc float arr[16];
122*0a6a1f1dSLionel Sambuc S2<4>::func(0,arr,arr,arr);
123*0a6a1f1dSLionel Sambuc return (0);
124*0a6a1f1dSLionel Sambuc }
125*0a6a1f1dSLionel Sambuc
126*0a6a1f1dSLionel Sambuc #endif
127