Clang Project

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