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 parallel for simd private(a) private(this->a) private(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 int k;
42 #pragma omp target
43 #pragma omp teams
44 #pragma omp distribute parallel for simd private(a) private(this->a) linear(k)
45 for (k = 0; k < s.a.a; ++k)
46 ++s.a.a;
47 return *this;
48 }
49 };
50
51 // CHECK: #pragma omp distribute parallel for simd private(this->a) private(this->a) private(T::a){{$}}
52 // CHECK: #pragma omp distribute parallel for simd private(this->a) private(this->a) linear(k)
53 // CHECK: #pragma omp distribute parallel for simd private(this->a) private(this->a) private(this->S::a)
54
55 class S8 : public S7<S> {
S8()56 S8() {}
57
58 public:
S8(int v)59 S8(int v) : S7<S>(v){
60 #pragma omp target
61 #pragma omp teams
62 #pragma omp distribute parallel for simd private(a) private(this->a) private(S7<S>::a)
63 for (int k = 0; k < a.a; ++k)
64 ++this->a.a;
65 }
operator =(S8 & s)66 S8 &operator=(S8 &s) {
67 #pragma omp target
68 #pragma omp teams
69 #pragma omp distribute parallel for simd private(a) private(this->a)
70 for (int k = 0; k < s.a.a; ++k)
71 ++s.a.a;
72 return *this;
73 }
74 };
75
76 // CHECK: #pragma omp distribute parallel for simd private(this->a) private(this->a) private(this->S7<S>::a)
77 // CHECK: #pragma omp distribute parallel for simd private(this->a) private(this->a)
78
79 template <class T, int N>
80 T tmain(T argc) {
81 T b = argc, c, d, e, f, h;
82 static T a;
83 // CHECK: static T a;
84 static T g;
85 #pragma omp threadprivate(g)
86 #pragma omp target
87 #pragma omp teams
88 #pragma omp distribute parallel for simd dist_schedule(static, a) schedule(dynamic) default(none) copyin(g) firstprivate(a) allocate(a)
89 // CHECK: #pragma omp distribute parallel for simd dist_schedule(static, a) schedule(dynamic) default(none) copyin(g) firstprivate(a) allocate(a)
90 for (int i = 0; i < 2; ++i)
91 a = 2;
92 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
93 // CHECK-NEXT: a = 2;
94 #pragma omp target
95 #pragma omp teams
96 #pragma omp distribute parallel for simd allocate(argc) private(argc, b), firstprivate(c, d), lastprivate(f) collapse(N) schedule(static, N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h) dist_schedule(static,N)
97 for (int i = 0; i < 2; ++i)
98 for (int j = 0; j < 2; ++j)
99 for (int j = 0; j < 2; ++j)
100 for (int j = 0; j < 2; ++j)
101 for (int j = 0; j < 2; ++j)
102 for (int i = 0; i < 2; ++i)
103 for (int j = 0; j < 2; ++j)
104 for (int j = 0; j < 2; ++j)
105 for (int j = 0; j < 2; ++j)
106 for (int j = 0; j < 2; ++j)
107 a++;
108 // CHECK: #pragma omp distribute parallel for simd allocate(argc) private(argc,b) firstprivate(c,d) lastprivate(f) collapse(N) schedule(static, N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h) dist_schedule(static, N)
109 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
110 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
111 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
112 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
113 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
114 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
115 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
116 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
117 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
118 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
119 // CHECK-NEXT: a++;
120 return T();
121 }
122
main(int argc,char ** argv)123 int main(int argc, char **argv) {
124 int b = argc, c, d, e, f, h;
125 int x[200];
126 static int a;
127 // CHECK: static int a;
128 static float g;
129 #pragma omp threadprivate(g)
130 #pragma omp target
131 #pragma omp teams
132 #pragma omp distribute parallel for simd schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc)
133 // CHECK: #pragma omp distribute parallel for simd schedule(guided, argc) default(none) copyin(g) dist_schedule(static, a) private(a) shared(argc)
134 for (int i = 0; i < 2; ++i)
135 a = 2;
136 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
137 // CHECK-NEXT: a = 2;
138 #pragma omp target
139 #pragma omp teams
140 #pragma omp distribute parallel for simd private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) if (argc) num_threads(a) default(shared) shared(e) reduction(+ : h) dist_schedule(static, b)
141 for (int i = 0; i < 10; ++i)
142 for (int j = 0; j < 10; ++j)
143 a++;
144 // CHECK: #pragma omp distribute parallel for simd private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) if(argc) num_threads(a) default(shared) shared(e) reduction(+: h) dist_schedule(static, b)
145 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
146 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
147 // CHECK-NEXT: a++;
148
149 int i;
150 #pragma omp target
151 #pragma omp teams
152 #ifdef OMP5
153 #pragma omp distribute parallel for simd aligned(x:8) linear(i:2) safelen(8) simdlen(8) if(simd: argc) nontemporal(argc, c, d) order(concurrent)
154 #else
155 #pragma omp distribute parallel for simd aligned(x:8) linear(i:2) safelen(8) simdlen(8)
156 #endif // OMP5
157 for (i = 0; i < 100; i++)
158 for (int j = 0; j < 200; j++)
159 a += h + x[j];
160 // OMP45: #pragma omp distribute parallel for simd aligned(x: 8) linear(i: 2) safelen(8) simdlen(8)
161 // OMP50: #pragma omp distribute parallel for simd aligned(x: 8) linear(i: 2) safelen(8) simdlen(8) if(simd: argc) nontemporal(argc,c,d) order(concurrent)
162 // CHECK-NEXT: for (i = 0; i < 100; i++)
163 // CHECK-NEXT: for (int j = 0; j < 200; j++)
164 // CHECK-NEXT: a += h + x[j];
165
166 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
167 }
168
169 #endif
170