xref: /llvm-project/llvm/test/Transforms/OpenMP/global_constructor.ll (revision 07ed8187acc31ac3f4779da452864a29d48799ac)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --include-generated-funcs
2; RUN: opt -S -passes=openmp-opt < %s | FileCheck %s
3
4%struct.ident_t = type { i32, i32, i32, i32, ptr }
5%struct.KernelEnvironmentTy = type { %struct.ConfigurationEnvironmentTy, ptr, ptr }
6%struct.ConfigurationEnvironmentTy = type { i8, i8, i8, i32, i32, i32, i32, i32, i32 }
7
8@0 = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00", align 1
9@1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, ptr @0 }, align 8
10@_ZL6Device = internal global double 0.000000e+00, align 8
11@__omp_offloading_fd02_85283c04_main_l11_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 @1, ptr null }
12
13define weak ptx_kernel void @__omp_offloading_fd02_85283c04_main_l11(ptr %dyn, ptr nonnull align 8 dereferenceable(8) %X) local_unnamed_addr "kernel" {
14entry:
15  %0 = tail call i32 @__kmpc_target_init(ptr @__omp_offloading_fd02_85283c04_main_l11_kernel_environment, ptr %dyn) #0
16  %exec_user_code = icmp eq i32 %0, -1
17  br i1 %exec_user_code, label %user_code.entry, label %common.ret
18
19common.ret:
20  ret void
21
22user_code.entry:
23  %1 = load double, ptr @_ZL6Device, align 8, !tbaa !11
24  %2 = tail call i32 @__kmpc_get_hardware_thread_id_in_block() #0
25  %3 = icmp eq i32 %2, 0
26  br i1 %3, label %region.guarded, label %region.barrier
27
28region.guarded:
29  store double %1, ptr %X, align 8, !tbaa !11
30  br label %region.barrier
31
32region.barrier:
33  tail call void @__kmpc_barrier_simple_spmd(ptr nonnull @1, i32 %2)
34  tail call void @__kmpc_target_deinit() #0
35  br label %common.ret
36}
37
38declare i32 @__kmpc_target_init(ptr, ptr) local_unnamed_addr
39
40declare void @__kmpc_target_deinit() local_unnamed_addr
41
42define weak ptx_kernel void @__omp_offloading__fd02_85283c04_Device_l6_ctor() "kernel" {
43entry:
44  %call.i = tail call double @__nv_log(double noundef 2.000000e+00) #1
45  %call.i2 = tail call double @__nv_log(double noundef 2.000000e+00) #1
46  %div = fdiv double %call.i, %call.i2
47  store double %div, ptr @_ZL6Device, align 8, !tbaa !11
48  ret void
49}
50
51declare double @__nv_log(double)
52
53declare i32 @__kmpc_get_hardware_thread_id_in_block()
54
55declare void @__kmpc_barrier_simple_spmd(ptr, i32)
56
57attributes #0 = { nounwind }
58attributes #1 = { convergent nounwind }
59
60!omp_offload.info = !{!0, !1, !2}
61!llvm.module.flags = !{!5, !6, !7, !8, !9}
62!llvm.ident = !{!10}
63
64!0 = !{i32 0, i32 64770, i32 -2060960764, !"__omp_offloading__fd02_85283c04_Device_l6_ctor", i32 6, i32 1}
65!1 = !{i32 0, i32 64770, i32 -2060960764, !"main", i32 11, i32 2}
66!2 = !{i32 1, !"_ZL6Device", i32 0, i32 0}
67!5 = !{i32 1, !"wchar_size", i32 4}
68!6 = !{i32 7, !"openmp", i32 50}
69!7 = !{i32 7, !"openmp-device", i32 50}
70!8 = !{i32 7, !"PIC Level", i32 2}
71!9 = !{i32 7, !"frame-pointer", i32 2}
72!10 = !{!"clang version 14.0.0"}
73!11 = !{!12, !12, i64 0}
74!12 = !{!"double", !13, i64 0}
75!13 = !{!"omnipotent char", !14, i64 0}
76!14 = !{!"Simple C++ TBAA"}
77; CHECK-LABEL: define {{[^@]+}}@__omp_offloading_fd02_85283c04_main_l11
78; CHECK-SAME: (ptr [[DYN:%.*]], ptr nonnull align 8 dereferenceable(8) [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
79; CHECK-NEXT:  entry:
80; CHECK-NEXT:    [[TMP0:%.*]] = tail call i32 @__kmpc_target_init(ptr @__omp_offloading_fd02_85283c04_main_l11_kernel_environment, ptr [[DYN]]) #[[ATTR1:[0-9]+]]
81; CHECK-NEXT:    [[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP0]], -1
82; CHECK-NEXT:    br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[COMMON_RET:%.*]]
83; CHECK:       common.ret:
84; CHECK-NEXT:    ret void
85; CHECK:       user_code.entry:
86; CHECK-NEXT:    [[TMP1:%.*]] = load double, ptr @_ZL6Device, align 8, !tbaa [[TBAA9:![0-9]+]]
87; CHECK-NEXT:    [[TMP2:%.*]] = tail call i32 @__kmpc_get_hardware_thread_id_in_block() #[[ATTR1]]
88; CHECK-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[TMP2]], 0
89; CHECK-NEXT:    br i1 [[TMP3]], label [[REGION_GUARDED:%.*]], label [[REGION_BARRIER:%.*]]
90; CHECK:       region.guarded:
91; CHECK-NEXT:    store double [[TMP1]], ptr [[X]], align 8, !tbaa [[TBAA9]]
92; CHECK-NEXT:    br label [[REGION_BARRIER]]
93; CHECK:       region.barrier:
94; CHECK-NEXT:    tail call void @__kmpc_barrier_simple_spmd(ptr nonnull @[[GLOB1:[0-9]+]], i32 [[TMP2]]) #[[ATTR1]]
95; CHECK-NEXT:    tail call void @__kmpc_target_deinit() #[[ATTR1]]
96; CHECK-NEXT:    br label [[COMMON_RET]]
97;
98;
99; CHECK-LABEL: define {{[^@]+}}@__omp_offloading__fd02_85283c04_Device_l6_ctor
100; CHECK-SAME: () #[[ATTR0]] {
101; CHECK-NEXT:  entry:
102; CHECK-NEXT:    [[CALL_I:%.*]] = tail call double @__nv_log(double noundef 2.000000e+00) #[[ATTR2:[0-9]+]]
103; CHECK-NEXT:    [[CALL_I2:%.*]] = tail call double @__nv_log(double noundef 2.000000e+00) #[[ATTR2]]
104; CHECK-NEXT:    [[DIV:%.*]] = fdiv double [[CALL_I]], [[CALL_I2]]
105; CHECK-NEXT:    store double [[DIV]], ptr @_ZL6Device, align 8, !tbaa [[TBAA9]]
106; CHECK-NEXT:    ret void
107;
108