blob: 632e038e221dd7d9dc9e4eeb28fe96c37cc46079 [file] [log] [blame]
Alexey Bataev587e1de2016-03-30 10:43:55 +00001// 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
Alexey Bataevecba70f2016-04-12 11:02:11 +00009#pragma omp declare simd linear(d: 8)
Alexey Bataev2af33e32016-04-07 12:45:37 +000010#pragma omp declare simd inbranch simdlen(32)
Alexey Bataev20dfd772016-04-04 10:12:15 +000011#pragma omp declare simd notinbranch
Alexey Bataev587e1de2016-03-30 10:43:55 +000012void add_1(float *d) __attribute__((cold));
13
Alexey Bataev20dfd772016-04-04 10:12:15 +000014// CHECK: #pragma omp declare simd notinbranch
Alexey Bataev2af33e32016-04-07 12:45:37 +000015// CHECK-NEXT: #pragma omp declare simd inbranch simdlen(32)
Alexey Bataevecba70f2016-04-12 11:02:11 +000016// CHECK-NEXT: #pragma omp declare simd linear(val(d): 8)
Alexey Bataev587e1de2016-03-30 10:43:55 +000017// CHECK-NEXT: void add_1(float *d) __attribute__((cold));
18//
19
Alexey Bataevd93d3762016-04-12 09:35:56 +000020#pragma omp declare simd aligned(hp, hp2)
Alexey Bataev587e1de2016-03-30 10:43:55 +000021template <class C> void h(C *hp, C *hp2, C *hq, C *lin) {
22}
23
Alexey Bataevd93d3762016-04-12 09:35:56 +000024// CHECK: #pragma omp declare simd aligned(hp) aligned(hp2)
Serge Pavlova67a4d22016-11-10 08:49:37 +000025// CHECK-NEXT: template <class C> void h(C *hp, C *hp2, C *hq, C *lin) {
Alexey Bataev587e1de2016-03-30 10:43:55 +000026// CHECK-NEXT: }
27
Alexey Bataevd93d3762016-04-12 09:35:56 +000028// CHECK: #pragma omp declare simd aligned(hp) aligned(hp2)
Serge Pavlova67a4d22016-11-10 08:49:37 +000029// CHECK-NEXT: template<> void h<float>(float *hp, float *hp2, float *hq, float *lin) {
Alexey Bataev587e1de2016-03-30 10:43:55 +000030// CHECK-NEXT: }
Serge Pavlova67a4d22016-11-10 08:49:37 +000031
32// CHECK-NEXT: template<> void h<int>(int *hp, int *hp2, int *hq, int *lin) {
33// CHECK-NEXT: h((float *)hp, (float *)hp2, (float *)hq, (float *)lin);
34// CHECK-NEXT: }
Alexey Bataev587e1de2016-03-30 10:43:55 +000035
36// Explicit specialization with <C=int>.
37// Pragmas need to be same, otherwise standard says that's undefined behavior.
Alexey Bataevd93d3762016-04-12 09:35:56 +000038#pragma omp declare simd aligned(hp, hp2)
Alexey Bataev587e1de2016-03-30 10:43:55 +000039template <>
40void h(int *hp, int *hp2, int *hq, int *lin)
41{
42 // Implicit specialization with <C=float>.
43 // This is special case where the directive is stored by Sema and is
44 // generated together with the (pending) function instatiation.
45 h((float*) hp, (float*) hp2, (float*) hq, (float*) lin);
46}
47
48class VV {
Alexey Bataevecba70f2016-04-12 11:02:11 +000049 // CHECK: #pragma omp declare simd uniform(this, a) linear(val(b): a)
Alexey Bataev587e1de2016-03-30 10:43:55 +000050 // CHECK-NEXT: int add(int a, int b) __attribute__((cold)) {
51 // CHECK-NEXT: return a + b;
52 // CHECK-NEXT: }
Alexey Bataevecba70f2016-04-12 11:02:11 +000053 #pragma omp declare simd uniform(this, a) linear(val(b): a)
Alexey Bataev587e1de2016-03-30 10:43:55 +000054 int add(int a, int b) __attribute__((cold)) { return a + b; }
55
Alexey Bataevecba70f2016-04-12 11:02:11 +000056 // CHECK: #pragma omp declare simd aligned(b: 4) aligned(a) linear(ref(b): 4) linear(val(this)) linear(val(a))
Alexey Bataevd93d3762016-04-12 09:35:56 +000057 // CHECK-NEXT: float taddpf(float *a, float *&b) {
Alexey Bataev587e1de2016-03-30 10:43:55 +000058 // CHECK-NEXT: return *a + *b;
59 // CHECK-NEXT: }
Alexey Bataevecba70f2016-04-12 11:02:11 +000060 #pragma omp declare simd aligned (b: 4) aligned(a) linear(ref(b): 4) linear(this, a)
Alexey Bataevd93d3762016-04-12 09:35:56 +000061 float taddpf(float *a, float *&b) { return *a + *b; }
Alexey Bataev587e1de2016-03-30 10:43:55 +000062
Alexey Bataevd93d3762016-04-12 09:35:56 +000063// CHECK: #pragma omp declare simd aligned(b: 8)
Alexey Bataevecba70f2016-04-12 11:02:11 +000064// CHECK-NEXT: #pragma omp declare simd linear(uval(c): 8)
65// CHECK-NEXT: int tadd(int (&b)[], int &c) {
Alexey Bataevd93d3762016-04-12 09:35:56 +000066// CHECK-NEXT: return this->x[b[0]] + b[0];
Alexey Bataev587e1de2016-03-30 10:43:55 +000067// CHECK-NEXT: }
Alexey Bataevecba70f2016-04-12 11:02:11 +000068 #pragma omp declare simd linear(uval(c): 8)
Alexey Bataevd93d3762016-04-12 09:35:56 +000069 #pragma omp declare simd aligned(b : 8)
Alexey Bataevecba70f2016-04-12 11:02:11 +000070 int tadd(int (&b)[], int &c) { return x[b[0]] + b[0]; }
Alexey Bataev587e1de2016-03-30 10:43:55 +000071
72private:
73 int x[10];
74};
75
Serge Pavlova67a4d22016-11-10 08:49:37 +000076// CHECK: template <int X, typename T> class TVV {
77// CHECK: #pragma omp declare simd simdlen(X)
78// CHECK-NEXT: int tadd(int a, int b) {
79// CHECK: #pragma omp declare simd aligned(a: X * 2) aligned(b) linear(ref(b): X)
80// CHECK-NEXT: float taddpf(float *a, T *&b) {
Alexey Bataev587e1de2016-03-30 10:43:55 +000081// CHECK-NEXT: return *a + *b;
82// CHECK-NEXT: }
83// CHECK: #pragma omp declare simd
84// CHECK-NEXT: #pragma omp declare simd
85// CHECK-NEXT: int tadd(int b) {
86// CHECK-NEXT: return this->x[b] + b;
87// CHECK-NEXT: }
88// CHECK: }
Alexey Bataevd93d3762016-04-12 09:35:56 +000089template <int X, typename T>
Alexey Bataev587e1de2016-03-30 10:43:55 +000090class TVV {
91public:
Serge Pavlova67a4d22016-11-10 08:49:37 +000092// CHECK: template<> class TVV<16, float> {
Alexey Bataev2af33e32016-04-07 12:45:37 +000093 #pragma omp declare simd simdlen(X)
Alexey Bataev587e1de2016-03-30 10:43:55 +000094 int tadd(int a, int b) { return a + b; }
95
Serge Pavlova67a4d22016-11-10 08:49:37 +000096// CHECK: #pragma omp declare simd simdlen(16)
97// CHECK-NEXT: int tadd(int a, int b);
Alexey Bataev587e1de2016-03-30 10:43:55 +000098
Alexey Bataevecba70f2016-04-12 11:02:11 +000099 #pragma omp declare simd aligned(a : X * 2) aligned(b) linear(ref(b): X)
Alexey Bataevd93d3762016-04-12 09:35:56 +0000100 float taddpf(float *a, T *&b) { return *a + *b; }
Alexey Bataev587e1de2016-03-30 10:43:55 +0000101
Serge Pavlova67a4d22016-11-10 08:49:37 +0000102// CHECK: #pragma omp declare simd aligned(a: 16 * 2) aligned(b) linear(ref(b): 16)
103// CHECK-NEXT: float taddpf(float *a, float *&b) {
Alexey Bataev587e1de2016-03-30 10:43:55 +0000104// CHECK-NEXT: return *a + *b;
105// CHECK-NEXT: }
106
107 #pragma omp declare simd
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000108 #pragma omp declare simd uniform(this, b)
Alexey Bataev587e1de2016-03-30 10:43:55 +0000109 int tadd(int b) { return x[b] + b; }
110
Alexey Bataeve48a5fc2016-04-12 05:28:34 +0000111// CHECK: #pragma omp declare simd uniform(this, b)
Alexey Bataev587e1de2016-03-30 10:43:55 +0000112// CHECK-NEXT: #pragma omp declare simd
113// CHECK-NEXT: int tadd(int b) {
114// CHECK-NEXT: return this->x[b] + b;
115// CHECK-NEXT: }
116
117private:
118 int x[X];
119};
120// CHECK: };
121
Alexey Bataevecba70f2016-04-12 11:02:11 +0000122// CHECK: #pragma omp declare simd simdlen(N) aligned(b: N * 2) linear(uval(c): N)
123// CHECK: template <int N> void foo(int (&b)[N], float *&c)
Serge Pavlova67a4d22016-11-10 08:49:37 +0000124// CHECK: #pragma omp declare simd simdlen(64) aligned(b: 64 * 2) linear(uval(c): 64)
125// CHECK: template<> void foo<64>(int (&b)[64], float *&c)
Alexey Bataevecba70f2016-04-12 11:02:11 +0000126#pragma omp declare simd simdlen(N) aligned(b : N * 2) linear(uval(c): N)
Alexey Bataev2af33e32016-04-07 12:45:37 +0000127template <int N>
Alexey Bataevecba70f2016-04-12 11:02:11 +0000128void foo(int (&b)[N], float *&c);
Alexey Bataev2af33e32016-04-07 12:45:37 +0000129
Alexey Bataevd93d3762016-04-12 09:35:56 +0000130// CHECK: TVV<16, float> t16;
131TVV<16, float> t16;
Alexey Bataev587e1de2016-03-30 10:43:55 +0000132
133void f() {
134 float a = 1.0f, b = 2.0f;
Alexey Bataevd93d3762016-04-12 09:35:56 +0000135 float *p = &b;
136 float r = t16.taddpf(&a, p);
Alexey Bataev587e1de2016-03-30 10:43:55 +0000137 int res = t16.tadd(b);
Alexey Bataev2af33e32016-04-07 12:45:37 +0000138 int c[64];
Alexey Bataevecba70f2016-04-12 11:02:11 +0000139 foo(c, p);
Alexey Bataev587e1de2016-03-30 10:43:55 +0000140}
141
142#endif