[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / target_teams_distribute_ast_print.cpp
blobcfe602541e1b6258af9a0cb7184cf39db12ae42d
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 -Wno-openmp-mapping
3 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s
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 -Wno-openmp-mapping
7 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify %s -ast-print -Wno-openmp-mapping | FileCheck %s
8 // expected-no-diagnostics
10 #ifndef HEADER
11 #define HEADER
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;
24 void foo() {}
26 struct S {
27 S(): a(0) {}
28 S(int v) : a(v) {}
29 int a;
30 typedef int type;
33 template <typename T>
34 class S7 : public T {
35 protected:
36 T a;
37 S7() : a(0) {}
39 public:
40 S7(typename T::type v) : a(v) {
41 #pragma omp target teams distribute private(a) private(this->a) private(T::a)
42 for (int k = 0; k < a.a; ++k)
43 ++this->a.a;
45 S7 &operator=(S7 &s) {
46 #pragma omp target teams distribute private(a) private(this->a)
47 for (int k = 0; k < s.a.a; ++k)
48 ++s.a.a;
49 return *this;
52 void foo() {
53 int b, argv, d, c, e, f;
54 #pragma omp target teams distribute default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d) allocate(omp_low_lat_mem_alloc:b) uses_allocators(omp_low_lat_mem_alloc)
55 for (int k = 0; k < a.a; ++k)
56 ++a.a;
59 // CHECK: #pragma omp target teams distribute private(this->a) private(this->a) private(T::a)
60 // CHECK: #pragma omp target teams distribute private(this->a) private(this->a)
61 // CHECK: #pragma omp target teams distribute default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d) allocate(omp_low_lat_mem_alloc: b) uses_allocators(omp_low_lat_mem_alloc)
62 // CHECK: #pragma omp target teams distribute private(this->a) private(this->a) private(this->S::a)
64 class S8 : public S7<S> {
65 S8() {}
67 public:
68 S8(int v) : S7<S>(v){
69 #pragma omp target teams distribute private(a) private(this->a) private(S7<S>::a)
70 for (int k = 0; k < a.a; ++k)
71 ++this->a.a;
73 S8 &operator=(S8 &s) {
74 #pragma omp target teams distribute private(a) private(this->a)
75 for (int k = 0; k < s.a.a; ++k)
76 ++s.a.a;
77 return *this;
80 void bar() {
81 int b, argv, d, c, e, f;
82 #pragma omp target teams distribute allocate(argv) default(none), private(b) firstprivate(argv) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d) allocate(e)
83 for (int k = 0; k < a.a; ++k)
84 ++a.a;
87 // CHECK: #pragma omp target teams distribute private(this->a) private(this->a) private(this->S7<S>::a)
88 // CHECK: #pragma omp target teams distribute private(this->a) private(this->a)
89 // CHECK: #pragma omp target teams distribute allocate(argv) default(none) private(b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d) allocate(e)
91 template <class T, int N>
92 T tmain(T argc) {
93 T b = argc, c, d, e, f, g;
94 static T a;
95 // CHECK: static T a;
96 #pragma omp target teams distribute
97 for (int i=0; i < 2; ++i)
98 a = 2;
99 // CHECK: #pragma omp target teams distribute{{$}}
100 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
101 // CHECK-NEXT: a = 2;
102 #pragma omp target teams distribute private(argc, b), firstprivate(c, d), collapse(2)
103 for (int i = 0; i < 10; ++i)
104 for (int j = 0; j < 10; ++j)
105 foo();
106 // CHECK: #pragma omp target teams distribute private(argc,b) firstprivate(c,d) collapse(2)
107 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
108 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
109 // CHECK-NEXT: foo();
110 for (int i = 0; i < 10; ++i)
111 foo();
112 // CHECK: for (int i = 0; i < 10; ++i)
113 // CHECK-NEXT: foo();
114 #pragma omp target teams distribute
115 for (int i = 0; i < 10; ++i)
116 foo();
117 // CHECK: #pragma omp target teams distribute
118 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
119 // CHECK-NEXT: foo();
120 #pragma omp target teams distribute default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
121 for (int k = 0; k < 10; ++k)
122 e += d + argc;
123 // CHECK: #pragma omp target teams distribute default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
124 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
125 // CHECK-NEXT: e += d + argc;
126 return T();
129 int main (int argc, char **argv) {
130 int b = argc, c, d, e, f, g;
131 static int a;
132 // CHECK: static int a;
133 #pragma omp target teams distribute
134 for (int i=0; i < 2; ++i)
135 a = 2;
136 // CHECK: #pragma omp target teams distribute
137 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
138 // CHECK-NEXT: a = 2;
139 #pragma omp target teams distribute private(argc,b),firstprivate(argv, c), collapse(2)
140 for (int i = 0; i < 10; ++i)
141 for (int j = 0; j < 10; ++j)
142 foo();
143 // CHECK: #pragma omp target teams distribute private(argc,b) firstprivate(argv,c) collapse(2)
144 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
145 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
146 // CHECK-NEXT: foo();
147 for (int i = 0; i < 10; ++i)
148 foo();
149 // CHECK: for (int i = 0; i < 10; ++i)
150 // CHECK-NEXT: foo();
151 #pragma omp target teams distribute
152 for (int i = 0; i < 10; ++i)foo();
153 // CHECK: #pragma omp target teams distribute
154 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
155 // CHECK-NEXT: foo();
156 #pragma omp target teams distribute default(none), private(b) firstprivate(argc) shared(d) reduction(+:c) reduction(max:e) num_teams(f) thread_limit(d)
157 for (int k = 0; k < 10; ++k)
158 e += d + argc;
159 // CHECK: #pragma omp target teams distribute default(none) private(b) firstprivate(argc) shared(d) reduction(+: c) reduction(max: e) num_teams(f) thread_limit(d)
160 // CHECK-NEXT: for (int k = 0; k < 10; ++k)
161 // CHECK-NEXT: e += d + argc;
162 return (0);
165 #endif