[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / target_teams_ast_print.cpp
blob8338f2a68f9228df0ddc5a0edd7ebe58f38a74fe
1 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s | 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 -verify %s -ast-print | FileCheck %s
5 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | 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 -verify %s -ast-print | FileCheck %s
8 // expected-no-diagnostics
10 #ifndef HEADER
11 #define HEADER
13 struct omp_alloctrait_t {};
15 typedef void **omp_allocator_handle_t;
16 extern const omp_allocator_handle_t omp_null_allocator;
17 extern const omp_allocator_handle_t omp_default_mem_alloc;
18 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
19 extern const omp_allocator_handle_t omp_const_mem_alloc;
20 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
21 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
22 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
23 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
24 extern const omp_allocator_handle_t omp_thread_mem_alloc;
26 void foo() {}
28 template <class T>
29 struct S {
30 operator T() {return T();}
31 static T TS;
32 #pragma omp threadprivate(TS)
35 // CHECK: template <class T> struct S {
36 // CHECK: static T TS;
37 // CHECK-NEXT: #pragma omp threadprivate(S::TS)
38 // CHECK: };
39 // CHECK: template<> struct S<int> {
40 // CHECK: static int TS;
41 // CHECK-NEXT: #pragma omp threadprivate(S<int>::TS)
42 // CHECK-NEXT: }
43 // CHECK: template<> struct S<long> {
44 // CHECK: static long TS;
45 // CHECK-NEXT: #pragma omp threadprivate(S<long>::TS)
46 // CHECK-NEXT: }
48 template <typename T, int C>
49 T tmain(T argc, T *argv) {
50 T b = argc, c, d, e, f, g;
51 static T a;
52 S<T> s;
53 omp_alloctrait_t traits[10];
54 omp_allocator_handle_t my_allocator;
55 #pragma omp target teams
56 a=2;
57 #pragma omp target teams default(none), private(argc,b) firstprivate(argv) shared (d) reduction(+:c) reduction(max:e) num_teams(C) thread_limit(d*C) allocate(argv)
58 foo();
59 #pragma omp target teams allocate(my_allocator:f) reduction(^:e, f) reduction(&& : g) uses_allocators(my_allocator(traits))
60 foo();
61 #pragma omp target teams ompx_bare num_teams(C, C, C) thread_limit(d*C, d*C, d*C)
62 foo();
63 return 0;
66 // CHECK: template <typename T, int C> T tmain(T argc, T *argv) {
67 // CHECK-NEXT: T b = argc, c, d, e, f, g;
68 // CHECK-NEXT: static T a;
69 // CHECK-NEXT: S<T> s;
70 // CHECK-NEXT: omp_alloctrait_t traits[10];
71 // CHECK-NEXT: omp_allocator_handle_t my_allocator;
72 // CHECK-NEXT: #pragma omp target teams{{$}}
73 // CHECK-NEXT: a = 2;
74 // CHECK-NEXT: #pragma omp target teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(C) thread_limit(d * C) allocate(argv)
75 // CHECK-NEXT: foo()
76 // CHECK-NEXT: #pragma omp target teams allocate(my_allocator: f) reduction(^: e,f) reduction(&&: g) uses_allocators(my_allocator(traits))
77 // CHECK-NEXT: foo()
78 // CHECK: template<> int tmain<int, 5>(int argc, int *argv) {
79 // CHECK-NEXT: int b = argc, c, d, e, f, g;
80 // CHECK-NEXT: static int a;
81 // CHECK-NEXT: S<int> s;
82 // CHECK-NEXT: omp_alloctrait_t traits[10];
83 // CHECK-NEXT: omp_allocator_handle_t my_allocator;
84 // CHECK-NEXT: #pragma omp target teams
85 // CHECK-NEXT: a = 2;
86 // CHECK-NEXT: #pragma omp target teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(5) thread_limit(d * 5) allocate(argv)
87 // CHECK-NEXT: foo()
88 // CHECK-NEXT: #pragma omp target teams allocate(my_allocator: f) reduction(^: e,f) reduction(&&: g) uses_allocators(my_allocator(traits))
89 // CHECK-NEXT: foo()
90 // CHECK: template<> long tmain<long, 1>(long argc, long *argv) {
91 // CHECK-NEXT: long b = argc, c, d, e, f, g;
92 // CHECK-NEXT: static long a;
93 // CHECK-NEXT: S<long> s;
94 // CHECK-NEXT: omp_alloctrait_t traits[10];
95 // CHECK-NEXT: omp_allocator_handle_t my_allocator;
96 // CHECK-NEXT: #pragma omp target teams
97 // CHECK-NEXT: a = 2;
98 // CHECK-NEXT: #pragma omp target teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) num_teams(1) thread_limit(d * 1) allocate(argv)
99 // CHECK-NEXT: foo()
100 // CHECK-NEXT: #pragma omp target teams allocate(my_allocator: f) reduction(^: e,f) reduction(&&: g) uses_allocators(my_allocator(traits))
101 // CHECK-NEXT: foo()
102 // CHECK-NEXT: #pragma omp target teams ompx_bare num_teams(1,1,1) thread_limit(d * 1,d * 1,d * 1)
103 // CHECK-NEXT: foo();
105 enum Enum { };
107 int main (int argc, char **argv) {
108 long x;
109 int b = argc, c, d, e, f, g;
110 static int a;
111 #pragma omp threadprivate(a)
112 Enum ee;
113 // CHECK: Enum ee;
114 #pragma omp target teams
115 // CHECK-NEXT: #pragma omp target teams
116 a=2;
117 // CHECK-NEXT: a = 2;
118 #pragma omp target teams ompx_bare num_teams(1) thread_limit(32)
119 // CHECK-NEXT: #pragma omp target teams ompx_bare num_teams(1) thread_limit(32)
120 a=3;
121 // CHECK-NEXT: a = 3;
122 #pragma omp target teams ompx_bare num_teams(1, 2, 3) thread_limit(2, 4, 6)
123 // CHECK-NEXT: #pragma omp target teams ompx_bare num_teams(1,2,3) thread_limit(2,4,6)
124 a=4;
125 // CHECK-NEXT: a = 4;
126 #pragma omp target teams default(none), private(argc,b) num_teams(f) firstprivate(argv) reduction(| : c, d) reduction(* : e) thread_limit(f+g)
127 // CHECK-NEXT: #pragma omp target teams default(none) private(argc,b) num_teams(f) firstprivate(argv) reduction(|: c,d) reduction(*: e) thread_limit(f + g)
128 foo();
129 // CHECK-NEXT: foo();
130 return tmain<int, 5>(b, &b) + tmain<long, 1>(x, &x);
133 extern template int S<int>::TS;
134 extern template long S<long>::TS;
135 #endif