Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_parallel_generic_loop_uses_allocators_codegen.cpp
blob50b38c4855d0adba06148fac817f88f9853d1055
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
2 // Test host codegen.
3 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK
4 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
5 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK
7 // expected-no-diagnostics
8 #ifndef HEADER
9 #define HEADER
11 enum omp_allocator_handle_t {
12 omp_null_allocator = 0,
13 omp_default_mem_alloc = 1,
14 omp_large_cap_mem_alloc = 2,
15 omp_const_mem_alloc = 3,
16 omp_high_bw_mem_alloc = 4,
17 omp_low_lat_mem_alloc = 5,
18 omp_cgroup_mem_alloc = 6,
19 omp_pteam_mem_alloc = 7,
20 omp_thread_mem_alloc = 8,
21 KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
24 typedef enum omp_alloctrait_key_t { omp_atk_sync_hint = 1,
25 omp_atk_alignment = 2,
26 omp_atk_access = 3,
27 omp_atk_pool_size = 4,
28 omp_atk_fallback = 5,
29 omp_atk_fb_data = 6,
30 omp_atk_pinned = 7,
31 omp_atk_partition = 8
32 } omp_alloctrait_key_t;
33 typedef enum omp_alloctrait_value_t {
34 omp_atv_false = 0,
35 omp_atv_true = 1,
36 omp_atv_default = 2,
37 omp_atv_contended = 3,
38 omp_atv_uncontended = 4,
39 omp_atv_sequential = 5,
40 omp_atv_private = 6,
41 omp_atv_all = 7,
42 omp_atv_thread = 8,
43 omp_atv_pteam = 9,
44 omp_atv_cgroup = 10,
45 omp_atv_default_mem_fb = 11,
46 omp_atv_null_fb = 12,
47 omp_atv_abort_fb = 13,
48 omp_atv_allocator_fb = 14,
49 omp_atv_environment = 15,
50 omp_atv_nearest = 16,
51 omp_atv_blocked = 17,
52 omp_atv_interleaved = 18
53 } omp_alloctrait_value_t;
55 typedef struct omp_alloctrait_t {
56 omp_alloctrait_key_t key;
57 __UINTPTR_TYPE__ value;
58 } omp_alloctrait_t;
60 // Just map the traits variable as a firstprivate variable.
62 void foo() {
63 omp_alloctrait_t traits[10];
64 omp_allocator_handle_t my_allocator;
66 #pragma omp target parallel loop uses_allocators(omp_null_allocator, omp_thread_mem_alloc, my_allocator(traits))
67 for (int i = 0; i < 10; ++i)
72 // Destroy allocator upon exit from the region.
74 #endif
75 // CHECK-LABEL: define {{[^@]+}}@_Z3foov
76 // CHECK-SAME: () #[[ATTR0:[0-9]+]] {
77 // CHECK-NEXT: entry:
78 // CHECK-NEXT: [[TRAITS:%.*]] = alloca [10 x %struct.omp_alloctrait_t], align 8
79 // CHECK-NEXT: [[MY_ALLOCATOR:%.*]] = alloca i64, align 8
80 // CHECK-NEXT: [[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [1 x ptr], align 8
81 // CHECK-NEXT: [[DOTOFFLOAD_PTRS:%.*]] = alloca [1 x ptr], align 8
82 // CHECK-NEXT: [[DOTOFFLOAD_MAPPERS:%.*]] = alloca [1 x ptr], align 8
83 // CHECK-NEXT: [[KERNEL_ARGS:%.*]] = alloca [[STRUCT___TGT_KERNEL_ARGUMENTS:%.*]], align 8
84 // CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds [1 x ptr], ptr [[DOTOFFLOAD_BASEPTRS]], i32 0, i32 0
85 // CHECK-NEXT: store ptr [[TRAITS]], ptr [[TMP0]], align 8
86 // CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [1 x ptr], ptr [[DOTOFFLOAD_PTRS]], i32 0, i32 0
87 // CHECK-NEXT: store ptr [[TRAITS]], ptr [[TMP1]], align 8
88 // CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [1 x ptr], ptr [[DOTOFFLOAD_MAPPERS]], i64 0, i64 0
89 // CHECK-NEXT: store ptr null, ptr [[TMP2]], align 8
90 // CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [1 x ptr], ptr [[DOTOFFLOAD_BASEPTRS]], i32 0, i32 0
91 // CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds [1 x ptr], ptr [[DOTOFFLOAD_PTRS]], i32 0, i32 0
92 // CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 0
93 // CHECK-NEXT: store i32 2, ptr [[TMP5]], align 4
94 // CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 1
95 // CHECK-NEXT: store i32 1, ptr [[TMP6]], align 4
96 // CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 2
97 // CHECK-NEXT: store ptr [[TMP3]], ptr [[TMP7]], align 8
98 // CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 3
99 // CHECK-NEXT: store ptr [[TMP4]], ptr [[TMP8]], align 8
100 // CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 4
101 // CHECK-NEXT: store ptr @.offload_sizes, ptr [[TMP9]], align 8
102 // CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 5
103 // CHECK-NEXT: store ptr @.offload_maptypes, ptr [[TMP10]], align 8
104 // CHECK-NEXT: [[TMP11:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 6
105 // CHECK-NEXT: store ptr null, ptr [[TMP11]], align 8
106 // CHECK-NEXT: [[TMP12:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 7
107 // CHECK-NEXT: store ptr null, ptr [[TMP12]], align 8
108 // CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 8
109 // CHECK-NEXT: store i64 0, ptr [[TMP13]], align 8
110 // CHECK-NEXT: [[TMP14:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 9
111 // CHECK-NEXT: store i64 0, ptr [[TMP14]], align 8
112 // CHECK-NEXT: [[TMP15:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 10
113 // CHECK-NEXT: store [3 x i32] [i32 1, i32 0, i32 0], ptr [[TMP15]], align 4
114 // CHECK-NEXT: [[TMP16:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 11
115 // CHECK-NEXT: store [3 x i32] zeroinitializer, ptr [[TMP16]], align 4
116 // CHECK-NEXT: [[TMP17:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 12
117 // CHECK-NEXT: store i32 0, ptr [[TMP17]], align 4
118 // CHECK-NEXT: [[TMP18:%.*]] = call i32 @__tgt_target_kernel(ptr @[[GLOB1:[0-9]+]], i64 -1, i32 1, i32 0, ptr @.{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z3foov_l66.region_id, ptr [[KERNEL_ARGS]])
119 // CHECK-NEXT: [[TMP19:%.*]] = icmp ne i32 [[TMP18]], 0
120 // CHECK-NEXT: br i1 [[TMP19]], label [[OMP_OFFLOAD_FAILED:%.*]], label [[OMP_OFFLOAD_CONT:%.*]]
121 // CHECK: omp_offload.failed:
122 // CHECK-NEXT: call void @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z3foov_l66(ptr [[TRAITS]]) #[[ATTR2:[0-9]+]]
123 // CHECK-NEXT: br label [[OMP_OFFLOAD_CONT]]
124 // CHECK: omp_offload.cont:
125 // CHECK-NEXT: ret void
128 // CHECK-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z3foov_l66
129 // CHECK-SAME: (ptr noundef nonnull align 8 dereferenceable(160) [[TRAITS:%.*]]) #[[ATTR1:[0-9]+]] {
130 // CHECK-NEXT: entry:
131 // CHECK-NEXT: [[TRAITS_ADDR:%.*]] = alloca ptr, align 8
132 // CHECK-NEXT: [[MY_ALLOCATOR:%.*]] = alloca i64, align 8
133 // CHECK-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1]])
134 // CHECK-NEXT: store ptr [[TRAITS]], ptr [[TRAITS_ADDR]], align 8
135 // CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[TRAITS_ADDR]], align 8
136 // CHECK-NEXT: [[TMP2:%.*]] = call ptr @__kmpc_init_allocator(i32 [[TMP0]], ptr null, i32 10, ptr [[TMP1]])
137 // CHECK-NEXT: [[CONV:%.*]] = ptrtoint ptr [[TMP2]] to i64
138 // CHECK-NEXT: store i64 [[CONV]], ptr [[MY_ALLOCATOR]], align 8
139 // CHECK-NEXT: call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB1]], i32 0, ptr @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z3foov_l66.omp_outlined)
140 // CHECK-NEXT: [[TMP3:%.*]] = load i64, ptr [[MY_ALLOCATOR]], align 8
141 // CHECK-NEXT: [[CONV1:%.*]] = inttoptr i64 [[TMP3]] to ptr
142 // CHECK-NEXT: call void @__kmpc_destroy_allocator(i32 [[TMP0]], ptr [[CONV1]])
143 // CHECK-NEXT: ret void
146 // CHECK-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z3foov_l66.omp_outlined
147 // CHECK-SAME: (ptr noalias noundef [[DOTGLOBAL_TID_:%.*]], ptr noalias noundef [[DOTBOUND_TID_:%.*]]) #[[ATTR1]] {
148 // CHECK-NEXT: entry:
149 // CHECK-NEXT: [[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
150 // CHECK-NEXT: [[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
151 // CHECK-NEXT: [[DOTOMP_IV:%.*]] = alloca i32, align 4
152 // CHECK-NEXT: [[TMP:%.*]] = alloca i32, align 4
153 // CHECK-NEXT: [[DOTOMP_LB:%.*]] = alloca i32, align 4
154 // CHECK-NEXT: [[DOTOMP_UB:%.*]] = alloca i32, align 4
155 // CHECK-NEXT: [[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
156 // CHECK-NEXT: [[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
157 // CHECK-NEXT: [[I:%.*]] = alloca i32, align 4
158 // CHECK-NEXT: store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
159 // CHECK-NEXT: store ptr [[DOTBOUND_TID_]], ptr [[DOTBOUND_TID__ADDR]], align 8
160 // CHECK-NEXT: store i32 0, ptr [[DOTOMP_LB]], align 4
161 // CHECK-NEXT: store i32 9, ptr [[DOTOMP_UB]], align 4
162 // CHECK-NEXT: store i32 1, ptr [[DOTOMP_STRIDE]], align 4
163 // CHECK-NEXT: store i32 0, ptr [[DOTOMP_IS_LAST]], align 4
164 // CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
165 // CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
166 // CHECK-NEXT: call void @__kmpc_for_static_init_4(ptr @[[GLOB2:[0-9]+]], i32 [[TMP1]], i32 34, ptr [[DOTOMP_IS_LAST]], ptr [[DOTOMP_LB]], ptr [[DOTOMP_UB]], ptr [[DOTOMP_STRIDE]], i32 1, i32 1)
167 // CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
168 // CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[TMP2]], 9
169 // CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
170 // CHECK: cond.true:
171 // CHECK-NEXT: br label [[COND_END:%.*]]
172 // CHECK: cond.false:
173 // CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
174 // CHECK-NEXT: br label [[COND_END]]
175 // CHECK: cond.end:
176 // CHECK-NEXT: [[COND:%.*]] = phi i32 [ 9, [[COND_TRUE]] ], [ [[TMP3]], [[COND_FALSE]] ]
177 // CHECK-NEXT: store i32 [[COND]], ptr [[DOTOMP_UB]], align 4
178 // CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr [[DOTOMP_LB]], align 4
179 // CHECK-NEXT: store i32 [[TMP4]], ptr [[DOTOMP_IV]], align 4
180 // CHECK-NEXT: br label [[OMP_INNER_FOR_COND:%.*]]
181 // CHECK: omp.inner.for.cond:
182 // CHECK-NEXT: [[TMP5:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
183 // CHECK-NEXT: [[TMP6:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
184 // CHECK-NEXT: [[CMP1:%.*]] = icmp sle i32 [[TMP5]], [[TMP6]]
185 // CHECK-NEXT: br i1 [[CMP1]], label [[OMP_INNER_FOR_BODY:%.*]], label [[OMP_INNER_FOR_END:%.*]]
186 // CHECK: omp.inner.for.body:
187 // CHECK-NEXT: [[TMP7:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
188 // CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[TMP7]], 1
189 // CHECK-NEXT: [[ADD:%.*]] = add nsw i32 0, [[MUL]]
190 // CHECK-NEXT: store i32 [[ADD]], ptr [[I]], align 4
191 // CHECK-NEXT: br label [[OMP_BODY_CONTINUE:%.*]]
192 // CHECK: omp.body.continue:
193 // CHECK-NEXT: br label [[OMP_INNER_FOR_INC:%.*]]
194 // CHECK: omp.inner.for.inc:
195 // CHECK-NEXT: [[TMP8:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
196 // CHECK-NEXT: [[ADD2:%.*]] = add nsw i32 [[TMP8]], 1
197 // CHECK-NEXT: store i32 [[ADD2]], ptr [[DOTOMP_IV]], align 4
198 // CHECK-NEXT: br label [[OMP_INNER_FOR_COND]]
199 // CHECK: omp.inner.for.end:
200 // CHECK-NEXT: br label [[OMP_LOOP_EXIT:%.*]]
201 // CHECK: omp.loop.exit:
202 // CHECK-NEXT: call void @__kmpc_for_static_fini(ptr @[[GLOB2]], i32 [[TMP1]])
203 // CHECK-NEXT: ret void
206 // CHECK-LABEL: define {{[^@]+}}@.omp_offloading.requires_reg
207 // CHECK-SAME: () #[[ATTR3:[0-9]+]] {
208 // CHECK-NEXT: entry:
209 // CHECK-NEXT: call void @__tgt_register_requires(i64 1)
210 // CHECK-NEXT: ret void