• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -std=c++11 -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 -x c++ -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
4 
5 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -std=c++11 -ast-print %s | FileCheck %s
6 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
8 // expected-no-diagnostics
9 
10 #ifndef HEADER
11 #define HEADER
12 
13 #pragma omp declare simd linear(d: 8)
14 #pragma omp declare simd inbranch simdlen(32)
15 #pragma omp declare simd notinbranch
16 void add_1(float *d) __attribute__((cold));
17 
18 // CHECK: #pragma omp declare simd notinbranch
19 // CHECK-NEXT: #pragma omp declare simd inbranch simdlen(32)
20 // CHECK-NEXT: #pragma omp declare simd linear(val(d): 8)
21 // CHECK-NEXT: void add_1(float *d) __attribute__((cold));
22 //
23 
24 #pragma omp declare simd aligned(hp, hp2:V)
25 #pragma omp declare simd aligned(hp, hp2:V)
h(C * hp,C * hp2,C * hq,C * lin)26 template <class C, int V> void h(C *hp, C *hp2, C *hq, C *lin) {
27 }
28 // CHECK-NEXT: #pragma omp declare simd aligned(hp: V) aligned(hp2: V)
29 // CHECK-NEXT: #pragma omp declare simd aligned(hp: V) aligned(hp2: V)
30 // CHECK-NEXT: template <class C, int V> void h(C *hp, C *hp2, C *hq, C *lin) {
31 // CHECK-NEXT: }
32 
33 #pragma omp declare simd aligned(hp, hp2)
h(C * hp,C * hp2,C * hq,C * lin)34 template <class C> void h(C *hp, C *hp2, C *hq, C *lin) {
35 }
36 
37 // CHECK: #pragma omp declare simd aligned(hp) aligned(hp2)
38 // CHECK-NEXT: template <class C> void h(C *hp, C *hp2, C *hq, C *lin) {
39 // CHECK-NEXT: }
40 
41 // CHECK: #pragma omp declare simd aligned(hp) aligned(hp2)
42 // CHECK-NEXT: template<> void h<float>(float *hp, float *hp2, float *hq, float *lin) {
43 // CHECK-NEXT: }
44 
45 // CHECK-NEXT: template<> void h<int>(int *hp, int *hp2, int *hq, int *lin) {
46 // CHECK-NEXT: h((float *)hp, (float *)hp2, (float *)hq, (float *)lin);
47 // CHECK-NEXT: }
48 
49 // Explicit specialization with <C=int>.
50 // Pragmas need to be same, otherwise standard says that's undefined behavior.
51 #pragma omp declare simd aligned(hp, hp2)
52 template <>
h(int * hp,int * hp2,int * hq,int * lin)53 void h(int *hp, int *hp2, int *hq, int *lin)
54 {
55   // Implicit specialization with <C=float>.
56   // This is special case where the directive is stored by Sema and is
57   // generated together with the (pending) function instatiation.
58   h((float*) hp, (float*) hp2, (float*) hq, (float*) lin);
59 }
60 
61 class VV {
62   // CHECK: #pragma omp declare simd uniform(this, a) linear(val(b): a)
63   // CHECK-NEXT: int add(int a, int b) __attribute__((cold))    {
64   // CHECK-NEXT: return a + b;
65   // CHECK-NEXT: }
66   #pragma omp declare simd uniform(this, a) linear(val(b): a)
add(int a,int b)67   int add(int a, int b) __attribute__((cold)) { return a + b; }
68 
69   // CHECK: #pragma omp declare simd aligned(b: 4) aligned(a) linear(ref(b): 4) linear(val(this)) linear(val(a))
70   // CHECK-NEXT: float taddpf(float *a, float *&b)     {
71   // CHECK-NEXT: return *a + *b;
72   // CHECK-NEXT: }
73   #pragma omp declare simd aligned (b: 4) aligned(a) linear(ref(b): 4) linear(this, a)
taddpf(float * a,float * & b)74   float taddpf(float *a, float *&b) { return *a + *b; }
75 
76 // CHECK: #pragma omp declare simd aligned(b: 8)
77 // CHECK-NEXT: #pragma omp declare simd linear(uval(c): 8)
78 // CHECK-NEXT: int tadd(int (&b)[], int &c) {
79 // CHECK-NEXT: return this->x[b[0]] + b[0];
80 // CHECK-NEXT: }
81   #pragma omp declare simd linear(uval(c): 8)
82   #pragma omp declare simd aligned(b : 8)
tadd(int (& b)[],int & c)83   int tadd(int (&b)[], int &c) { return x[b[0]] + b[0]; }
84 
85 private:
86   int x[10];
87 };
88 
89 // CHECK: template <int X, typename T> class TVV {
90 // CHECK: #pragma omp declare simd simdlen(X)
91 // CHECK-NEXT: int tadd(int a, int b) {
92 // CHECK: #pragma omp declare simd aligned(a: X * 2) aligned(b) linear(ref(b): X)
93 // CHECK-NEXT: float taddpf(float *a, T *&b) {
94 // CHECK-NEXT: return *a + *b;
95 // CHECK-NEXT: }
96 // CHECK: #pragma omp declare simd uniform(this, b)
97 // CHECK-NEXT: #pragma omp declare simd{{$}}
98 // CHECK-NEXT: int tadd(int b) {
99 // CHECK-NEXT: return this->x[b] + b;
100 // CHECK-NEXT: }
101 // CHECK: }
102 template <int X, typename T>
103 class TVV {
104 public:
105 // CHECK: template<> class TVV<16, float> {
106   #pragma omp declare simd simdlen(X)
tadd(int a,int b)107   int tadd(int a, int b) { return a + b; }
108 
109 // CHECK: #pragma omp declare simd simdlen(16)
110 // CHECK-NEXT: int tadd(int a, int b);
111 
112   #pragma omp declare simd aligned(a : X * 2) aligned(b) linear(ref(b): X)
taddpf(float * a,T * & b)113   float taddpf(float *a, T *&b) { return *a + *b; }
114 
115 // CHECK: #pragma omp declare simd aligned(a: 16 * 2) aligned(b) linear(ref(b): 16)
116 // CHECK-NEXT: float taddpf(float *a, float *&b) {
117 // CHECK-NEXT: return *a + *b;
118 // CHECK-NEXT: }
119 
120   #pragma omp declare simd
121   #pragma omp declare simd uniform(this, b)
tadd(int b)122   int tadd(int b) { return x[b] + b; }
123 
124 // CHECK: #pragma omp declare simd uniform(this, b)
125 // CHECK-NEXT: #pragma omp declare simd
126 // CHECK-NEXT: int tadd(int b) {
127 // CHECK-NEXT: return this->x[b] + b;
128 // CHECK-NEXT: }
129 
130 private:
131   int x[X];
132 };
133 // CHECK: };
134 
135 // CHECK: #pragma omp declare simd simdlen(N) aligned(b: N * 2) linear(uval(c): N)
136 // CHECK: template <int N> void foo(int (&b)[N], float *&c)
137 // CHECK: #pragma omp declare simd simdlen(64) aligned(b: 64 * 2) linear(uval(c): 64)
138 // CHECK: template<> void foo<64>(int (&b)[64], float *&c)
139 #pragma omp declare simd simdlen(N) aligned(b : N * 2) linear(uval(c): N)
140 template <int N>
141 void foo(int (&b)[N], float *&c);
142 
143 // CHECK: TVV<16, float> t16;
144 TVV<16, float> t16;
145 
f()146 void f() {
147   float a = 1.0f, b = 2.0f;
148   float *p = &b;
149   float r = t16.taddpf(&a, p);
150   int res = t16.tadd(b);
151   int c[64];
152   foo(c, p);
153 }
154 
155 #endif
156