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