1 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s -Wno-openmp-mapping | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s
4 
5 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -Wno-openmp-mapping | FileCheck %s
6 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s
8 // expected-no-diagnostics
9 
10 #ifndef HEADER
11 #define HEADER
12 
13 typedef void **omp_allocator_handle_t;
14 extern const omp_allocator_handle_t omp_null_allocator;
15 extern const omp_allocator_handle_t omp_default_mem_alloc;
16 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
17 extern const omp_allocator_handle_t omp_const_mem_alloc;
18 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
19 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
20 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
21 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
22 extern const omp_allocator_handle_t omp_thread_mem_alloc;
23 
foo()24 void foo() {}
25 
26 struct S {
SS27   S(): a(0) {}
SS28   S(int v) : a(v) {}
29   int a;
30   typedef int type;
31 };
32 
33 template <typename T>
34 class S7 : public T {
35 protected:
36   T a;
S7()37   S7() : a(0) {}
38 
39 public:
S7(typename T::type v)40   S7(typename T::type v) : a(v) {
41 #pragma omp target
42 #pragma omp teams distribute private(a) private(this->a) private(T::a)
43     for (int k = 0; k < a.a; ++k)
44       ++this->a.a;
45   }
operator =(S7 & s)46   S7 &operator=(S7 &s) {
47 #pragma omp target
48 #pragma omp teams distribute private(a) private(this->a)
49     for (int k = 0; k < s.a.a; ++k)
50       ++s.a.a;
51     return *this;
52   }
53 
foo()54   void foo() {
55     int b, argv, d, c, e, f;
56 #pragma omp target
57 #pragma omp teams distribute default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
58     for (int k = 0; k < a.a; ++k)
59       ++a.a;
60   }
61 };
62 // CHECK: #pragma omp target
63 // CHECK-NEXT: #pragma omp teams distribute private(this->a) private(this->a) private(T::a)
64 // CHECK: #pragma omp target
65 // CHECK-NEXT: #pragma omp teams distribute private(this->a) private(this->a)
66 // CHECK: #pragma omp target
67 // CHECK-NEXT: #pragma omp teams distribute default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
68 // CHECK: #pragma omp target
69 // CHECK-NEXT: #pragma omp teams distribute private(this->a) private(this->a) private(this->S::a)
70 
71 class S8 : public S7<S> {
S8()72   S8() {}
73 
74 public:
S8(int v)75   S8(int v) : S7<S>(v){
76 #pragma omp target
77 #pragma omp teams distribute private(a) private(this->a) private(S7<S>::a)
78     for (int k = 0; k < a.a; ++k)
79       ++this->a.a;
80   }
operator =(S8 & s)81   S8 &operator=(S8 &s) {
82 #pragma omp target
83 #pragma omp teams distribute private(a) private(this->a)
84     for (int k = 0; k < s.a.a; ++k)
85       ++s.a.a;
86     return *this;
87   }
88 
bar()89   void bar() {
90     int b, argv, d, c, e, f;
91 #pragma omp target
92 #pragma omp teams distribute allocate(omp_thread_mem_alloc:argv) default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d) allocate(omp_default_mem_alloc:c) shared(omp_default_mem_alloc, omp_thread_mem_alloc)
93     for (int k = 0; k < a.a; ++k)
94       ++a.a;
95   }
96 };
97 // CHECK: #pragma omp target
98 // CHECK-NEXT: #pragma omp teams distribute private(this->a) private(this->a) private(this->S7<S>::a)
99 // CHECK: #pragma omp target
100 // CHECK-NEXT: #pragma omp teams distribute private(this->a) private(this->a)
101 // CHECK: #pragma omp target
102 // CHECK-NEXT: #pragma omp teams distribute allocate(omp_thread_mem_alloc: argv) default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d) allocate(omp_default_mem_alloc: c) shared(omp_default_mem_alloc,omp_thread_mem_alloc)
103 
104 template <class T, int N>
105 T tmain(T argc) {
106   T b = argc, c, d, e, f, g;
107   static T a;
108 // CHECK: static T a;
109 #pragma omp target
110 #pragma omp teams distribute
111   for (int i=0; i < 2; ++i)
112     a = 2;
113 // CHECK: #pragma omp target
114 // CHECK-NEXT: #pragma omp teams distribute{{$}}
115 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
116 // CHECK-NEXT: a = 2;
117 #pragma omp target
118 #pragma omp teams distribute private(argc, b), firstprivate(c, d), collapse(2)
119   for (int i = 0; i < 10; ++i)
120     for (int j = 0; j < 10; ++j)
121       foo();
122 // CHECK: #pragma omp target
123 // CHECK-NEXT: #pragma omp teams distribute private(argc,b) firstprivate(c,d) collapse(2)
124 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
125 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
126 // CHECK-NEXT: foo();
127   for (int i = 0; i < 10; ++i)
128     foo();
129 // CHECK: for (int i = 0; i < 10; ++i)
130 // CHECK-NEXT: foo();
131 #pragma omp target
132 #pragma omp teams distribute
133   for (int i = 0; i < 10; ++i)
134     foo();
135 // CHECK: #pragma omp target
136 // CHECK-NEXT: #pragma omp teams distribute
137 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
138 // CHECK-NEXT: foo();
139 #pragma omp target
140 #pragma omp teams distribute default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
141     for (int k = 0; k < 10; ++k)
142       e += d + argc;
143 // CHECK: #pragma omp target
144 // CHECK-NEXT: #pragma omp teams distribute default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
145 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
146 // CHECK-NEXT: e += d + argc;
147   return T();
148 }
149 
main(int argc,char ** argv)150 int main (int argc, char **argv) {
151   int b = argc, c, d, e, f, g;
152   static int a;
153 // CHECK: static int a;
154 #pragma omp target
155 #pragma omp teams distribute
156   for (int i=0; i < 2; ++i)
157     a = 2;
158 // CHECK: #pragma omp target
159 // CHECK-NEXT: #pragma omp teams distribute
160 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
161 // CHECK-NEXT: a = 2;
162 #pragma omp target
163 #pragma omp teams distribute private(argc,b),firstprivate(argv, c), collapse(2)
164   for (int i = 0; i < 10; ++i)
165     for (int j = 0; j < 10; ++j)
166       foo();
167 // CHECK: #pragma omp target
168 // CHECK-NEXT: #pragma omp teams distribute private(argc,b) firstprivate(argv,c) collapse(2)
169 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
170 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
171 // CHECK-NEXT: foo();
172   for (int i = 0; i < 10; ++i)
173     foo();
174 // CHECK: for (int i = 0; i < 10; ++i)
175 // CHECK-NEXT: foo();
176 #pragma omp target
177 #pragma omp teams distribute
178   for (int i = 0; i < 10; ++i)foo();
179 // CHECK: #pragma omp target
180 // CHECK-NEXT: #pragma omp teams distribute
181 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
182 // CHECK-NEXT: foo();
183 #pragma omp target
184 #pragma omp teams distribute default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
185   for (int k = 0; k < 10; ++k)
186     e += d + argc;
187 // CHECK: #pragma omp target
188 // CHECK-NEXT: #pragma omp teams distribute default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
189 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
190 // CHECK-NEXT: e += d + argc;
191   return (0);
192 }
193 
194 #endif
195