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