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
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
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
));
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));
24 #pragma omp declare simd aligned(hp, hp2:V)
25 #pragma omp declare simd aligned(hp, hp2:V)
26 template <class C
, int V
> void h(C
*hp
, C
*hp2
, C
*hq
, C
*lin
) {
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) {
33 #pragma omp declare simd aligned(hp, hp2)
34 template <class C
> void h(C
*hp
, C
*hp2
, C
*hq
, C
*lin
) {
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) {
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) {
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);
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)
53 void h(int *hp
, int *hp2
, int *hq
, int *lin
)
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
);
62 // CHECK: #pragma omp declare simd uniform(this, a) linear(val(b): a)
63 // CHECK-NEXT: __attribute__((cold)) int add(int a, int b) {
64 // CHECK-NEXT: return a + b;
66 #pragma omp declare simd uniform(this, a) linear(val(b): a)
67 __attribute__((cold
)) int add(int a
, int b
) { return a
+ b
; }
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;
73 #pragma omp declare simd aligned (b: 4) aligned(a) linear(ref(b): 4) linear(this, a)
74 float taddpf(float *a
, float *&b
) { return *a
+ *b
; }
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];
81 #pragma omp declare simd linear(uval(c): 8)
82 #pragma omp declare simd aligned(b : 8)
83 int tadd(int (&b
)[], int &c
) { return x
[b
[0]] + b
[0]; }
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;
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;
102 template <int X
, typename T
>
105 // CHECK: template<> class TVV<16, float> {
106 #pragma omp declare simd simdlen(X)
107 int tadd(int a
, int b
) { return a
+ b
; }
109 // CHECK: #pragma omp declare simd simdlen(16)
110 // CHECK-NEXT: int tadd(int a, int b);
112 #pragma omp declare simd aligned(a : X * 2) aligned(b) linear(ref(b): X)
113 float taddpf(float *a
, T
*&b
) { return *a
+ *b
; }
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;
120 #pragma omp declare simd
121 #pragma omp declare simd uniform(this, b)
122 int tadd(int b
) { return x
[b
] + b
; }
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;
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)
141 void foo(int (&b
)[N
], float *&c
);
143 // CHECK: TVV<16, float> t16;
147 float a
= 1.0f
, b
= 2.0f
;
149 float r
= t16
.taddpf(&a
, p
);
150 int res
= t16
.tadd(b
);