1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
2 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
4 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
5 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
6 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
7
8 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -ast-print %s -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
9 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -emit-pch -o %t %s
10 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s --check-prefix=CHECK --check-prefix=OMP45
11 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
12 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s -DOMP5
13 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
14 // expected-no-diagnostics
15
16 #ifndef HEADER
17 #define HEADER
18
19 struct S {
SS20 S(): a(0) {}
SS21 S(int v) : a(v) {}
22 int a;
23 typedef int type;
24 };
25
26 template <typename T>
27 class S7 : public T {
28 protected:
29 T a;
S7()30 S7() : a(0) {}
31
32 public:
S7(typename T::type v)33 S7(typename T::type v) : a(v) {
34 #pragma omp target
35 #pragma omp teams
36 #pragma omp distribute simd private(a) private(this->a) private(T::a) allocate(T::a)
37 for (int k = 0; k < a.a; ++k)
38 ++this->a.a;
39 }
operator =(S7 & s)40 S7 &operator=(S7 &s) {
41 #pragma omp target
42 #pragma omp teams
43 #pragma omp distribute simd allocate(a) private(a) private(this->a)
44 for (int k = 0; k < s.a.a; ++k)
45 ++s.a.a;
46 return *this;
47 }
48 };
49
50 // CHECK: #pragma omp distribute simd private(this->a) private(this->a) private(T::a) allocate(T::a){{$}}
51 // CHECK: #pragma omp distribute simd allocate(this->a) private(this->a) private(this->a)
52 // CHECK: #pragma omp distribute simd private(this->a) private(this->a) private(this->S::a) allocate(this->S::a)
53
54 class S8 : public S7<S> {
S8()55 S8() {}
56
57 public:
S8(int v)58 S8(int v) : S7<S>(v){
59 #pragma omp target
60 #pragma omp teams
61 #pragma omp distribute simd private(a) private(this->a) private(S7<S>::a)
62 for (int k = 0; k < a.a; ++k)
63 ++this->a.a;
64 }
operator =(S8 & s)65 S8 &operator=(S8 &s) {
66 #pragma omp target
67 #pragma omp teams
68 #pragma omp distribute simd private(a) private(this->a)
69 for (int k = 0; k < s.a.a; ++k)
70 ++s.a.a;
71 return *this;
72 }
73 };
74
75 // CHECK: #pragma omp distribute simd private(this->a) private(this->a) private(this->S7<S>::a)
76 // CHECK: #pragma omp distribute simd private(this->a) private(this->a)
77
78 template <class T, int N>
79 T tmain(T argc) {
80 T b = argc, c, d, e, f, h;
81 static T a;
82 // CHECK: static T a;
83 static T g;
84 #pragma omp threadprivate(g)
85
86 #pragma omp target
87 #pragma omp teams
88 #pragma omp distribute simd dist_schedule(static, a) firstprivate(a)
89 for (int i = 0; i < 2; ++i)
90 a = 2;
91 // CHECK: #pragma omp distribute simd dist_schedule(static, a) firstprivate(a)
92 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
93 // CHECK-NEXT: a = 2;
94
95 #pragma omp target
96 #pragma omp teams
97 #pragma omp distribute simd private(argc, b), firstprivate(c, d), lastprivate(f) collapse(N) reduction(+ : h) dist_schedule(static,N)
98 for (int i = 0; i < 2; ++i)
99 for (int j = 0; j < 2; ++j)
100 for (int k = 0; k < 10; ++k)
101 for (int m = 0; m < 10; ++m)
102 for (int n = 0; n < 10; ++n)
103 a++;
104 // CHECK: #pragma omp distribute simd private(argc,b) firstprivate(c,d) lastprivate(f) collapse(N) reduction(+: h) dist_schedule(static, N)
105 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
106 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
107 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
108 // CHECK-NEXT: for (int m = 0; m < 10; ++m)
109 // CHECK-NEXT: for (int n = 0; n < 10; ++n)
110 // CHECK-NEXT: a++;
111 return T();
112 }
113
main(int argc,char ** argv)114 int main(int argc, char **argv) {
115 int b = argc, c, d, e, f, h;
116 int x[200];
117 static int a;
118 // CHECK: static int a;
119 static float g;
120 #pragma omp threadprivate(g)
121
122 #pragma omp target
123 #pragma omp teams
124 #pragma omp distribute simd dist_schedule(static, a) private(a)
125 for (int i = 0; i < 2; ++i)
126 a = 2;
127 // CHECK: #pragma omp distribute simd dist_schedule(static, a) private(a)
128 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
129 // CHECK-NEXT: a = 2;
130
131 #pragma omp target
132 #pragma omp teams
133 #ifdef OMP5
134 #pragma omp distribute simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) reduction(+ : h) dist_schedule(static, b) if(simd:argc)
135 #else
136 #pragma omp distribute simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) reduction(+ : h) dist_schedule(static, b)
137 #endif // OMP5
138 for (int i = 0; i < 10; ++i)
139 for (int j = 0; j < 10; ++j)
140 a++;
141 // OMP45: #pragma omp distribute simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) reduction(+: h) dist_schedule(static, b)
142 // OMP50: #pragma omp distribute simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) reduction(+: h) dist_schedule(static, b) if(simd: argc)
143 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
144 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
145 // CHECK-NEXT: a++;
146
147 int i;
148 #pragma omp target
149 #pragma omp teams
150 #ifdef OMP5
151 #pragma omp distribute simd aligned(x:8) linear(i:2) safelen(8) simdlen(8) if(argc) nontemporal(argc, c, d) order(concurrent)
152 #else
153 #pragma omp distribute simd aligned(x:8) linear(i:2) safelen(8) simdlen(8)
154 #endif // OMP5
155 for (i = 0; i < 100; i++)
156 for (int j = 0; j < 200; j++)
157 a += h + x[j];
158 // OMP45: #pragma omp distribute simd aligned(x: 8) linear(i: 2) safelen(8) simdlen(8)
159 // OMP50: #pragma omp distribute simd aligned(x: 8) linear(i: 2) safelen(8) simdlen(8) if(argc) nontemporal(argc,c,d) order(concurrent)
160 // CHECK-NEXT: for (i = 0; i < 100; i++)
161 // CHECK-NEXT: for (int j = 0; j < 200; j++)
162 // CHECK-NEXT: a += h + x[j];
163
164 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
165 }
166
167 #endif
168