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