1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals
2 ; RUN: opt -S -passes=openmp-opt < %s | FileCheck %s
3 ; RUN: opt -S -passes=openmp-opt -openmp-opt-disable-spmdization < %s | FileCheck %s
11 ; void spmd_helper() {
13 ; #pragma omp parallel
21 ; void generic_helper() {
29 target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
30 target triple = "nvptx64"
32 %struct.ident_t = type { i32, i32, i32, i32, i8* }
34 @0 = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00", align 1
35 @1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @0, i32 0, i32 0) }, align 8
36 @__omp_offloading_2b_10393b5_spmd_l12_exec_mode = weak constant i8 1
37 @__omp_offloading_2b_10393b5_generic_l20_exec_mode = weak constant i8 1
38 @2 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 2, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @0, i32 0, i32 0) }, align 8
39 @G = external global i32, align 4
40 @llvm.compiler.used = appending global [2 x i8*] [i8* @__omp_offloading_2b_10393b5_spmd_l12_exec_mode, i8* @__omp_offloading_2b_10393b5_generic_l20_exec_mode], section "llvm.metadata"
43 ; CHECK: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [23 x i8] c"
44 ; CHECK: @[[GLOB1:[0-9]+]] = private unnamed_addr constant [[STRUCT_IDENT_T:%.*]] { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @[[GLOB0]], i32 0, i32 0) }, align 8
45 ; CHECK: @[[__OMP_OFFLOADING_2B_10393B5_SPMD_L12_EXEC_MODE:[a-zA-Z0-9_$"\\.-]+]] = weak constant i8 1
46 ; CHECK: @[[__OMP_OFFLOADING_2B_10393B5_GENERIC_L20_EXEC_MODE:[a-zA-Z0-9_$"\\.-]+]] = weak constant i8 1
47 ; CHECK: @[[GLOB2:[0-9]+]] = private unnamed_addr constant [[STRUCT_IDENT_T:%.*]] { i32 0, i32 2, i32 2, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @[[GLOB0]], i32 0, i32 0) }, align 8
48 ; CHECK: @[[G:[a-zA-Z0-9_$"\\.-]+]] = external global i32, align 4
49 ; CHECK: @[[LLVM_COMPILER_USED:[a-zA-Z0-9_$"\\.-]+]] = appending global [2 x i8*] [i8* @__omp_offloading_2b_10393b5_spmd_l12_exec_mode, i8* @__omp_offloading_2b_10393b5_generic_l20_exec_mode], section "llvm.metadata"
50 ; CHECK: @[[__OMP_OUTLINED___WRAPPER_ID:[a-zA-Z0-9_$"\\.-]+]] = private constant i8 undef
52 define weak void @__omp_offloading_2b_10393b5_spmd_l12() #0 {
53 ; CHECK-LABEL: define {{[^@]+}}@__omp_offloading_2b_10393b5_spmd_l12
54 ; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
56 ; CHECK-NEXT: [[WORKER_WORK_FN_ADDR:%.*]] = alloca i8*, align 8
57 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* @[[GLOB1]], i8 1, i1 false, i1 true)
58 ; CHECK-NEXT: [[THREAD_IS_WORKER:%.*]] = icmp ne i32 [[TMP0]], -1
59 ; CHECK-NEXT: br i1 [[THREAD_IS_WORKER]], label [[IS_WORKER_CHECK:%.*]], label [[THREAD_USER_CODE_CHECK:%.*]]
60 ; CHECK: is_worker_check:
61 ; CHECK-NEXT: [[BLOCK_HW_SIZE:%.*]] = call i32 @__kmpc_get_hardware_num_threads_in_block()
62 ; CHECK-NEXT: [[WARP_SIZE:%.*]] = call i32 @__kmpc_get_warp_size()
63 ; CHECK-NEXT: [[BLOCK_SIZE:%.*]] = sub i32 [[BLOCK_HW_SIZE]], [[WARP_SIZE]]
64 ; CHECK-NEXT: [[THREAD_IS_MAIN_OR_WORKER:%.*]] = icmp slt i32 [[TMP0]], [[BLOCK_SIZE]]
65 ; CHECK-NEXT: br i1 [[THREAD_IS_MAIN_OR_WORKER]], label [[WORKER_STATE_MACHINE_BEGIN:%.*]], label [[WORKER_STATE_MACHINE_FINISHED:%.*]]
66 ; CHECK: worker_state_machine.begin:
67 ; CHECK-NEXT: call void @__kmpc_barrier_simple_generic(%struct.ident_t* @[[GLOB1]], i32 [[TMP0]])
68 ; CHECK-NEXT: [[WORKER_IS_ACTIVE:%.*]] = call i1 @__kmpc_kernel_parallel(i8** [[WORKER_WORK_FN_ADDR]])
69 ; CHECK-NEXT: [[WORKER_WORK_FN:%.*]] = load i8*, i8** [[WORKER_WORK_FN_ADDR]], align 8
70 ; CHECK-NEXT: [[WORKER_WORK_FN_ADDR_CAST:%.*]] = bitcast i8* [[WORKER_WORK_FN]] to void (i16, i32)*
71 ; CHECK-NEXT: [[WORKER_IS_DONE:%.*]] = icmp eq i8* [[WORKER_WORK_FN]], null
72 ; CHECK-NEXT: br i1 [[WORKER_IS_DONE]], label [[WORKER_STATE_MACHINE_FINISHED]], label [[WORKER_STATE_MACHINE_IS_ACTIVE_CHECK:%.*]]
73 ; CHECK: worker_state_machine.finished:
74 ; CHECK-NEXT: ret void
75 ; CHECK: worker_state_machine.is_active.check:
76 ; CHECK-NEXT: br i1 [[WORKER_IS_ACTIVE]], label [[WORKER_STATE_MACHINE_PARALLEL_REGION_CHECK:%.*]], label [[WORKER_STATE_MACHINE_DONE_BARRIER:%.*]]
77 ; CHECK: worker_state_machine.parallel_region.check:
78 ; CHECK-NEXT: br i1 true, label [[WORKER_STATE_MACHINE_PARALLEL_REGION_EXECUTE:%.*]], label [[WORKER_STATE_MACHINE_PARALLEL_REGION_CHECK1:%.*]]
79 ; CHECK: worker_state_machine.parallel_region.execute:
80 ; CHECK-NEXT: call void @__omp_outlined___wrapper(i16 0, i32 [[TMP0]])
81 ; CHECK-NEXT: br label [[WORKER_STATE_MACHINE_PARALLEL_REGION_END:%.*]]
82 ; CHECK: worker_state_machine.parallel_region.check1:
83 ; CHECK-NEXT: br label [[WORKER_STATE_MACHINE_PARALLEL_REGION_END]]
84 ; CHECK: worker_state_machine.parallel_region.end:
85 ; CHECK-NEXT: call void @__kmpc_kernel_end_parallel()
86 ; CHECK-NEXT: br label [[WORKER_STATE_MACHINE_DONE_BARRIER]]
87 ; CHECK: worker_state_machine.done.barrier:
88 ; CHECK-NEXT: call void @__kmpc_barrier_simple_generic(%struct.ident_t* @[[GLOB1]], i32 [[TMP0]])
89 ; CHECK-NEXT: br label [[WORKER_STATE_MACHINE_BEGIN]]
90 ; CHECK: thread.user_code.check:
91 ; CHECK-NEXT: [[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP0]], -1
92 ; CHECK-NEXT: br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
93 ; CHECK: user_code.entry:
94 ; CHECK-NEXT: call void @spmd_helper() #[[ATTR5:[0-9]+]]
95 ; CHECK-NEXT: call void @__kmpc_target_deinit(%struct.ident_t* @[[GLOB1]], i8 1, i1 true)
96 ; CHECK-NEXT: ret void
98 ; CHECK-NEXT: ret void
101 %0 = call i32 @__kmpc_target_init(%struct.ident_t* @1, i8 1, i1 true, i1 true)
102 %exec_user_code = icmp eq i32 %0, -1
103 br i1 %exec_user_code, label %user_code.entry, label %worker.exit
105 user_code.entry: ; preds = %entry
106 call void @spmd_helper() #5
107 call void @__kmpc_target_deinit(%struct.ident_t* @1, i8 1, i1 true)
110 worker.exit: ; preds = %entry
114 declare i32 @__kmpc_target_init(%struct.ident_t*, i8, i1, i1)
116 declare void @__kmpc_target_deinit(%struct.ident_t*, i8, i1)
118 ; Function Attrs: convergent noinline norecurse nounwind
119 define weak void @__omp_offloading_2b_10393b5_generic_l20() #0 {
120 ; CHECK-LABEL: define {{[^@]+}}@__omp_offloading_2b_10393b5_generic_l20
121 ; CHECK-SAME: () #[[ATTR0]] {
123 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* @[[GLOB1]], i8 1, i1 false, i1 true)
124 ; CHECK-NEXT: [[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP0]], -1
125 ; CHECK-NEXT: br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
126 ; CHECK: user_code.entry:
127 ; CHECK-NEXT: call void @generic_helper() #[[ATTR6:[0-9]+]]
128 ; CHECK-NEXT: call void @__kmpc_target_deinit(%struct.ident_t* @[[GLOB1]], i8 1, i1 true)
129 ; CHECK-NEXT: ret void
130 ; CHECK: worker.exit:
131 ; CHECK-NEXT: ret void
134 %0 = call i32 @__kmpc_target_init(%struct.ident_t* @1, i8 1, i1 true, i1 true)
135 %exec_user_code = icmp eq i32 %0, -1
136 br i1 %exec_user_code, label %user_code.entry, label %worker.exit
138 user_code.entry: ; preds = %entry
139 call void @generic_helper() #5
140 call void @__kmpc_target_deinit(%struct.ident_t* @1, i8 1, i1 true)
143 worker.exit: ; preds = %entry
147 ; Function Attrs: convergent noinline nounwind
148 define internal void @spmd_helper() #1 {
149 ; CHECK-LABEL: define {{[^@]+}}@spmd_helper
150 ; CHECK-SAME: () #[[ATTR1:[0-9]+]] {
152 ; CHECK-NEXT: [[CAPTURED_VARS_ADDRS:%.*]] = alloca [0 x i8*], align 8
153 ; CHECK-NEXT: call void @leaf() #[[ATTR6]]
154 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB2]]) #[[ATTR2:[0-9]+]]
155 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast [0 x i8*]* [[CAPTURED_VARS_ADDRS]] to i8**
156 ; CHECK-NEXT: call void @__kmpc_parallel_51(%struct.ident_t* @[[GLOB2]], i32 [[TMP0]], i32 1, i32 -1, i32 -1, i8* bitcast (void (i32*, i32*)* @__omp_outlined__ to i8*), i8* @__omp_outlined___wrapper.ID, i8** [[TMP1]], i64 0)
157 ; CHECK-NEXT: ret void
160 %captured_vars_addrs = alloca [0 x i8*], align 8
162 %0 = call i32 @__kmpc_global_thread_num(%struct.ident_t* @2)
163 %1 = bitcast [0 x i8*]* %captured_vars_addrs to i8**
164 call void @__kmpc_parallel_51(%struct.ident_t* @2, i32 %0, i32 1, i32 -1, i32 -1, i8* bitcast (void (i32*, i32*)* @__omp_outlined__ to i8*), i8* bitcast (void (i16, i32)* @__omp_outlined___wrapper to i8*), i8** %1, i64 0)
168 ; Function Attrs: convergent noinline norecurse nounwind
169 define internal void @__omp_outlined__(i32* noalias %.global_tid., i32* noalias %.bound_tid.) #0 {
170 ; CHECK-LABEL: define {{[^@]+}}@__omp_outlined__
171 ; CHECK-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias [[DOTBOUND_TID_:%.*]]) #[[ATTR0]] {
173 ; CHECK-NEXT: [[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
174 ; CHECK-NEXT: [[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
175 ; CHECK-NEXT: call void @unknown() #[[ATTR7:[0-9]+]]
176 ; CHECK-NEXT: ret void
179 %.global_tid..addr = alloca i32*, align 8
180 %.bound_tid..addr = alloca i32*, align 8
181 store i32* %.global_tid., i32** %.global_tid..addr, align 8
182 store i32* %.bound_tid., i32** %.bound_tid..addr, align 8
183 call void @unknown() #5
187 ; Function Attrs: convergent noinline norecurse nounwind
188 define internal void @__omp_outlined___wrapper(i16 zeroext %0, i32 %1) #2 {
189 ; CHECK-LABEL: define {{[^@]+}}@__omp_outlined___wrapper
190 ; CHECK-SAME: (i16 zeroext [[TMP0:%.*]], i32 [[TMP1:%.*]]) #[[ATTR0]] {
192 ; CHECK-NEXT: [[DOTADDR:%.*]] = alloca i16, align 2
193 ; CHECK-NEXT: [[DOTADDR1:%.*]] = alloca i32, align 4
194 ; CHECK-NEXT: [[DOTZERO_ADDR:%.*]] = alloca i32, align 4
195 ; CHECK-NEXT: [[GLOBAL_ARGS:%.*]] = alloca i8**, align 8
196 ; CHECK-NEXT: call void @__kmpc_get_shared_variables(i8*** [[GLOBAL_ARGS]])
197 ; CHECK-NEXT: call void @__omp_outlined__(i32* [[DOTADDR1]], i32* [[DOTZERO_ADDR]]) #[[ATTR2]]
198 ; CHECK-NEXT: ret void
201 %.addr = alloca i16, align 2
202 %.addr1 = alloca i32, align 4
203 %.zero.addr = alloca i32, align 4
204 %global_args = alloca i8**, align 8
205 store i16 %0, i16* %.addr, align 2
206 store i32 %1, i32* %.addr1, align 4
207 store i32 0, i32* %.zero.addr, align 4
208 call void @__kmpc_get_shared_variables(i8*** %global_args)
209 call void @__omp_outlined__(i32* %.addr1, i32* %.zero.addr) #3
213 declare void @__kmpc_get_shared_variables(i8***)
215 ; Function Attrs: nounwind
216 declare i32 @__kmpc_global_thread_num(%struct.ident_t*) #3
218 ; Function Attrs: alwaysinline
219 declare void @__kmpc_parallel_51(%struct.ident_t*, i32, i32, i32, i32, i8*, i8*, i8**, i64) #4
221 ; Function Attrs: convergent noinline nounwind
222 define internal void @leaf() #1 {
223 ; CHECK-LABEL: define {{[^@]+}}@leaf
224 ; CHECK-SAME: () #[[ATTR4:[0-9]+]] {
226 ; CHECK-NEXT: store i32 42, i32* @G, align 4
227 ; CHECK-NEXT: ret void
230 store i32 42, i32* @G, align 4
234 ; Function Attrs: convergent noinline nounwind
235 define internal void @generic_helper() #1 {
236 ; CHECK-LABEL: define {{[^@]+}}@generic_helper
237 ; CHECK-SAME: () #[[ATTR4]] {
239 ; CHECK-NEXT: call void @leaf() #[[ATTR6]]
240 ; CHECK-NEXT: ret void
247 declare void @unknown()
249 attributes #0 = { convergent noinline norecurse nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="sm_53" "target-features"="+ptx32,+sm_53" }
250 attributes #1 = { convergent noinline nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="sm_53" "target-features"="+ptx32,+sm_53" }
251 attributes #2 = { convergent noinline norecurse nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="sm_53" "target-features"="+ptx32,+sm_53" }
252 attributes #3 = { nounwind }
253 attributes #4 = { alwaysinline }
254 attributes #5 = { convergent }
256 !omp_offload.info = !{!0, !1}
257 !nvvm.annotations = !{!2, !3}
258 !llvm.module.flags = !{!4, !5, !6, !7, !8}
261 !0 = !{i32 0, i32 43, i32 17011637, !"spmd", i32 12, i32 0}
262 !1 = !{i32 0, i32 43, i32 17011637, !"generic", i32 20, i32 1}
263 !2 = !{void ()* @__omp_offloading_2b_10393b5_spmd_l12, !"kernel", i32 1}
264 !3 = !{void ()* @__omp_offloading_2b_10393b5_generic_l20, !"kernel", i32 1}
265 !4 = !{i32 1, !"wchar_size", i32 4}
266 !5 = !{i32 7, !"openmp", i32 50}
267 !6 = !{i32 7, !"openmp-device", i32 50}
268 !7 = !{i32 8, !"PIC Level", i32 2}
269 !8 = !{i32 7, !"frame-pointer", i32 2}
270 !9 = !{!"clang version 14.0.0"}
272 ; CHECK: attributes #[[ATTR0]] = { convergent noinline norecurse nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="sm_53" "target-features"="+ptx32,+sm_53" }
273 ; CHECK: attributes #[[ATTR1]] = { convergent noinline nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="sm_53" "target-features"="+ptx32,+sm_53" }
274 ; CHECK: attributes #[[ATTR2]] = { nounwind }
275 ; CHECK: attributes #[[ATTR3:[0-9]+]] = { alwaysinline }
276 ; CHECK: attributes #[[ATTR4]] = { convergent noinline nounwind writeonly "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="sm_53" "target-features"="+ptx32,+sm_53" }
277 ; CHECK: attributes #[[ATTR5]] = { convergent nounwind }
278 ; CHECK: attributes #[[ATTR6]] = { convergent nounwind writeonly }
279 ; CHECK: attributes #[[ATTR7]] = { convergent }
281 ; CHECK: [[META0:![0-9]+]] = !{i32 0, i32 43, i32 17011637, !"spmd", i32 12, i32 0}
282 ; CHECK: [[META1:![0-9]+]] = !{i32 0, i32 43, i32 17011637, !"generic", i32 20, i32 1}
283 ; CHECK: [[META2:![0-9]+]] = !{void ()* @__omp_offloading_2b_10393b5_spmd_l12, !"kernel", i32 1}
284 ; CHECK: [[META3:![0-9]+]] = !{void ()* @__omp_offloading_2b_10393b5_generic_l20, !"kernel", i32 1}
285 ; CHECK: [[META4:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
286 ; CHECK: [[META5:![0-9]+]] = !{i32 7, !"openmp", i32 50}
287 ; CHECK: [[META6:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
288 ; CHECK: [[META7:![0-9]+]] = !{i32 8, !"PIC Level", i32 2}
289 ; CHECK: [[META8:![0-9]+]] = !{i32 7, !"frame-pointer", i32 2}
290 ; CHECK: [[META9:![0-9]+]] = !{!"clang version 14.0.0"}