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 target triple = "nvptx64"
5 %struct.KernelEnvironmentTy = type { %struct.ConfigurationEnvironmentTy, ptr, ptr }
6 %struct.ConfigurationEnvironmentTy = type { i8, i8, i8, i32, i32, i32, i32, i32, i32 }
8 @G = external global i8
9 @is_spmd_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 2, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr null, ptr null }
10 @will_be_spmd_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr null, ptr null }
11 @none_spmd_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr null, ptr null }
12 @will_not_be_spmd_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr null, ptr null }
15 ; CHECK: @G = external global i8
16 ; CHECK: @is_spmd_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 2, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr null, ptr null }
17 ; CHECK: @will_be_spmd_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 3, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr null, ptr null }
18 ; CHECK: @none_spmd_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr null, ptr null }
19 ; CHECK: @will_not_be_spmd_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 0, i8 0, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr null, ptr null }
21 define weak void @is_spmd() "kernel" {
22 ; CHECK-LABEL: define {{[^@]+}}@is_spmd
23 ; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
24 ; CHECK-NEXT: [[I:%.*]] = call i32 @__kmpc_target_init(ptr @is_spmd_kernel_environment, ptr null)
25 ; CHECK-NEXT: call void @is_spmd_helper1()
26 ; CHECK-NEXT: call void @is_spmd_helper2()
27 ; CHECK-NEXT: call void @is_mixed_helper()
28 ; CHECK-NEXT: call void @__kmpc_target_deinit()
29 ; CHECK-NEXT: ret void
31 %i = call i32 @__kmpc_target_init(ptr @is_spmd_kernel_environment, ptr null)
32 call void @is_spmd_helper1()
33 call void @is_spmd_helper2()
34 call void @is_mixed_helper()
35 call void @__kmpc_target_deinit()
39 define weak void @will_be_spmd() "kernel" {
40 ; CHECK-LABEL: define {{[^@]+}}@will_be_spmd
41 ; CHECK-SAME: () #[[ATTR0]] {
43 ; CHECK-NEXT: [[CAPTURED_VARS_ADDRS:%.*]] = alloca [0 x ptr], align 8
44 ; CHECK-NEXT: [[I:%.*]] = call i32 @__kmpc_target_init(ptr @will_be_spmd_kernel_environment, ptr null)
45 ; CHECK-NEXT: [[EXEC_USER_CODE:%.*]] = icmp eq i32 [[I]], -1
46 ; CHECK-NEXT: br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[COMMON_RET:%.*]]
48 ; CHECK-NEXT: ret void
49 ; CHECK: user_code.entry:
50 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(ptr null) #[[ATTR3:[0-9]+]]
51 ; CHECK-NEXT: call void @is_spmd_helper2()
52 ; CHECK-NEXT: call void @__kmpc_parallel_51(ptr null, i32 [[TMP0]], i32 1, i32 -1, i32 -1, ptr @__omp_outlined__, ptr @__omp_outlined___wrapper, ptr [[CAPTURED_VARS_ADDRS]], i64 0)
53 ; CHECK-NEXT: call void @__kmpc_target_deinit()
54 ; CHECK-NEXT: ret void
57 %captured_vars_addrs = alloca [0 x ptr], align 8
58 %i = call i32 @__kmpc_target_init(ptr @will_be_spmd_kernel_environment, ptr null)
59 %exec_user_code = icmp eq i32 %i, -1
60 br i1 %exec_user_code, label %user_code.entry, label %common.ret
66 %0 = call i32 @__kmpc_global_thread_num(ptr null)
67 call void @is_spmd_helper2()
68 call void @__kmpc_parallel_51(ptr null, i32 %0, i32 1, i32 -1, i32 -1, ptr @__omp_outlined__, ptr @__omp_outlined___wrapper, ptr %captured_vars_addrs, i64 0)
69 call void @__kmpc_target_deinit()
73 define weak void @non_spmd() "kernel" {
74 ; CHECK-LABEL: define {{[^@]+}}@non_spmd
75 ; CHECK-SAME: () #[[ATTR0]] {
76 ; CHECK-NEXT: [[I:%.*]] = call i32 @__kmpc_target_init(ptr @none_spmd_kernel_environment, ptr null)
77 ; CHECK-NEXT: call void @is_generic_helper1()
78 ; CHECK-NEXT: call void @is_generic_helper2()
79 ; CHECK-NEXT: call void @is_mixed_helper()
80 ; CHECK-NEXT: call void @__kmpc_target_deinit()
81 ; CHECK-NEXT: ret void
83 %i = call i32 @__kmpc_target_init(ptr @none_spmd_kernel_environment, ptr null)
84 call void @is_generic_helper1()
85 call void @is_generic_helper2()
86 call void @is_mixed_helper()
87 call void @__kmpc_target_deinit()
91 define weak void @will_not_be_spmd() "kernel" {
92 ; CHECK-LABEL: define {{[^@]+}}@will_not_be_spmd
93 ; CHECK-SAME: () #[[ATTR0]] {
94 ; CHECK-NEXT: [[I:%.*]] = call i32 @__kmpc_target_init(ptr @will_not_be_spmd_kernel_environment, ptr null)
95 ; CHECK-NEXT: call void @is_generic_helper1()
96 ; CHECK-NEXT: call void @is_generic_helper2()
97 ; CHECK-NEXT: call void @is_mixed_helper()
98 ; CHECK-NEXT: call void @__kmpc_target_deinit()
99 ; CHECK-NEXT: ret void
101 %i = call i32 @__kmpc_target_init(ptr @will_not_be_spmd_kernel_environment, ptr null)
102 call void @is_generic_helper1()
103 call void @is_generic_helper2()
104 call void @is_mixed_helper()
105 call void @__kmpc_target_deinit()
109 define internal void @is_spmd_helper1() {
110 ; CHECK-LABEL: define {{[^@]+}}@is_spmd_helper1() {
111 ; CHECK-NEXT: store i8 1, ptr @G, align 1
112 ; CHECK-NEXT: ret void
114 %isSPMD = call i8 @__kmpc_is_spmd_exec_mode()
115 store i8 %isSPMD, ptr @G
119 define internal void @is_spmd_helper2() {
120 ; CHECK-LABEL: define {{[^@]+}}@is_spmd_helper2() {
121 ; CHECK-NEXT: br label [[F:%.*]]
123 ; CHECK-NEXT: unreachable
125 ; CHECK-NEXT: ret void
127 %isSPMD = call i8 @__kmpc_is_spmd_exec_mode()
128 %c = icmp eq i8 %isSPMD, 0
129 br i1 %c, label %t, label %f
131 call void @spmd_compatible()
137 define internal void @is_generic_helper1() {
138 ; CHECK-LABEL: define {{[^@]+}}@is_generic_helper1() {
139 ; CHECK-NEXT: store i8 0, ptr @G, align 1
140 ; CHECK-NEXT: ret void
142 %isSPMD = call i8 @__kmpc_is_spmd_exec_mode()
143 store i8 %isSPMD, ptr @G
147 define internal void @is_generic_helper2() {
148 ; CHECK-LABEL: define {{[^@]+}}@is_generic_helper2() {
149 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 0, 0
150 ; CHECK-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
152 ; CHECK-NEXT: call void @foo()
153 ; CHECK-NEXT: ret void
155 ; CHECK-NEXT: call void @bar()
156 ; CHECK-NEXT: ret void
158 %isSPMD = call i8 @__kmpc_is_spmd_exec_mode()
159 %c = icmp eq i8 %isSPMD, 0
160 br i1 %c, label %t, label %f
169 define internal void @is_mixed_helper() {
170 ; CHECK-LABEL: define {{[^@]+}}@is_mixed_helper() {
171 ; CHECK-NEXT: [[ISSPMD:%.*]] = call i8 @__kmpc_is_spmd_exec_mode()
172 ; CHECK-NEXT: store i8 [[ISSPMD]], ptr @G, align 1
173 ; CHECK-NEXT: ret void
175 %isSPMD = call i8 @__kmpc_is_spmd_exec_mode()
176 store i8 %isSPMD, ptr @G
180 define internal void @__omp_outlined__(ptr noalias %.global_tid., ptr noalias %.bound_tid.) {
181 ; CHECK-LABEL: define {{[^@]+}}@__omp_outlined__
182 ; CHECK-SAME: (ptr noalias [[DOTGLOBAL_TID_:%.*]], ptr noalias [[DOTBOUND_TID_:%.*]]) {
184 ; CHECK-NEXT: ret void
190 define internal void @__omp_outlined___wrapper(i16 zeroext %0, i32 %1) {
191 ; CHECK-LABEL: define {{[^@]+}}@__omp_outlined___wrapper
192 ; CHECK-SAME: (i16 zeroext [[TMP0:%.*]], i32 [[TMP1:%.*]]) {
194 ; CHECK-NEXT: ret void
200 declare void @spmd_compatible() "llvm.assume"="ompx_spmd_amenable"
201 declare i8 @__kmpc_is_spmd_exec_mode()
202 declare i32 @__kmpc_target_init(ptr, ptr)
203 declare void @__kmpc_target_deinit()
204 declare void @__kmpc_parallel_51(ptr, i32, i32, i32, i32, ptr, ptr, ptr, i64)
205 declare i32 @__kmpc_global_thread_num(ptr)
209 !llvm.module.flags = !{!0, !1}
210 !nvvm.annotations = !{!2, !3, !4, !5}
212 !0 = !{i32 7, !"openmp", i32 50}
213 !1 = !{i32 7, !"openmp-device", i32 50}
214 !2 = !{ptr @is_spmd, !"kernel", i32 1}
215 !3 = !{ptr @will_be_spmd, !"kernel", i32 1}
216 !4 = !{ptr @non_spmd, !"kernel", i32 1}
217 !5 = !{ptr @will_not_be_spmd, !"kernel", i32 1}
219 ; CHECK: attributes #[[ATTR0]] = { "kernel" }
220 ; CHECK: attributes #[[ATTR1:[0-9]+]] = { "llvm.assume"="ompx_spmd_amenable" }
221 ; CHECK: attributes #[[ATTR2:[0-9]+]] = { alwaysinline }
222 ; CHECK: attributes #[[ATTR3]] = { nounwind }
224 ; CHECK: [[META0:![0-9]+]] = !{i32 7, !"openmp", i32 50}
225 ; CHECK: [[META1:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
226 ; CHECK: [[META2:![0-9]+]] = !{ptr @is_spmd, !"kernel", i32 1}
227 ; CHECK: [[META3:![0-9]+]] = !{ptr @will_be_spmd, !"kernel", i32 1}
228 ; CHECK: [[META4:![0-9]+]] = !{ptr @non_spmd, !"kernel", i32 1}
229 ; CHECK: [[META5:![0-9]+]] = !{ptr @will_not_be_spmd, !"kernel", i32 1}