Skip to content

Commit 2351ae8

Browse files
committed
wip
1 parent 433bd14 commit 2351ae8

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fn create_struct_ty<'ll>(
2323
entry_struct
2424
}
2525
}
26+
//const DATA_NULL: &[u8] = c"111111";
2627

2728
// We don't copy types from other functions because we generate a new module and context.
2829
// Bringing in types from other contexts would likely cause issues.
@@ -100,10 +101,43 @@ pub(crate) fn gen_image_wrapper_module<'ll>(
100101
llvm::Visibility::Default,
101102
mapper_fn_ty,
102103
);
104+
let baz = crate::declare::declare_simple_fn(
105+
&cx,
106+
&"atexit",
107+
llvm::CallConv::CCallConv,
108+
llvm::UnnamedAddr::No,
109+
llvm::Visibility::Default,
110+
cx.type_func(&[tptr], ti32),
111+
);
103112

104-
// @__start_omp_offloading_entries = external hidden constant [0 x %struct.__tgt_offload_entry]
105-
// @__stop_omp_offloading_entries = external hidden constant [0 x %struct.__tgt_offload_entry]
106-
// @__dummy.omp_offloading_entries = internal constant [0 x %struct.__tgt_offload_entry] zeroinitializer, section "omp_offloading_entries"
113+
let unknown_txt = "11111111111111";
114+
let c_entry_name = CString::new(unknown_txt).unwrap();
115+
let c_val = c_entry_name.as_bytes_with_nul();
116+
let initializer = crate::common::bytes_in_context(cx.llcx, c_val);
117+
let llglobal =
118+
add_unnamed_global(&cx, &".omp_offloading.device_image", initializer, InternalLinkage);
119+
let c_section_name = CString::new(".llvm.offloading").unwrap();
120+
llvm::set_section(llglobal, &c_section_name);
121+
llvm::set_alignment(llglobal, Align::EIGHT);
122+
123+
//@.omp_offloading.device_image = internal unnamed_addr constant [4040 x i8] c"111111111", section ".llvm.offloading", align 8
124+
// TODO
125+
// @.omp_offloading.device_images = internal unnamed_addr constant [1 x %__tgt_device_image] [%__tgt_device_image { ptr getelementptr ([4040 x i8], ptr @.omp_offloading.device_image, i64 0, i64 144), ptr getelementptr ([4040 x i8], ptr @.omp_offloading.device_image, i64 0, i64 4040), ptr @__start_omp_offloading_entries, ptr @__stop_omp_offloading_entries }]
126+
// @.omp_offloading.descriptor = internal constant %__tgt_bin_desc { i32 1, ptr @.omp_offloading.device_images, ptr @__start_omp_offloading_entries, ptr @__stop_omp_offloading_entries }
127+
// @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 101, ptr @.omp_offloading.descriptor_reg, ptr null }]
128+
//
129+
// define internal void @.omp_offloading.descriptor_reg() section ".text.startup" {
130+
// entry:
131+
// call void @__tgt_register_lib(ptr @.omp_offloading.descriptor)
132+
// %0 = call i32 @atexit(ptr @.omp_offloading.descriptor_unreg)
133+
// ret void
134+
// }
135+
//
136+
// define internal void @.omp_offloading.descriptor_unreg() section ".text.startup" {
137+
// entry:
138+
// call void @__tgt_unregister_lib(ptr @.omp_offloading.descriptor)
139+
// ret void
140+
// }
107141

108142
llvm::LLVMPrintModuleToFile(
109143
llmod,

0 commit comments

Comments
 (0)