@@ -5,15 +5,62 @@ use crate::common::AsCCharPtr;
5
5
use crate :: llvm:: AttributePlace :: Function ;
6
6
use crate :: llvm:: { self , Linkage , build_string} ;
7
7
use crate :: { LlvmCodegenBackend , ModuleLlvm , SimpleCx , attributes} ;
8
+ use rustc_codegen_ssa:: back:: write:: { CodegenContext , FatLtoInput } ;
8
9
9
10
use llvm:: Linkage :: * ;
10
11
use rustc_abi:: Align ;
11
12
use rustc_codegen_ssa:: traits:: BaseTypeCodegenMethods ;
12
13
14
+ // We don't copy types from other functions because we generate a new module and context.
15
+ // Bringing in types from other contexts would likely cause issues.
16
+ pub ( crate ) fn gen_image_wrapper_module < ' ll > (
17
+ cgcx : & CodegenContext < LlvmCodegenBackend > ,
18
+ old_cx : & SimpleCx < ' ll > ,
19
+ ) {
20
+ unsafe {
21
+ let llcx = llvm:: LLVMRustContextCreate ( false ) ;
22
+ let module_name = CString :: new ( "offload.wrapper.module" ) . unwrap ( ) ;
23
+ let llmod = llvm:: LLVMModuleCreateWithNameInContext ( module_name. as_ptr ( ) , llcx) ;
24
+ let cx = SimpleCx :: new ( llmod, llcx, cgcx. pointer_size ) ;
25
+ let tptr = cx. type_ptr ( ) ;
26
+ let ti64 = cx. type_i64 ( ) ;
27
+ let ti32 = cx. type_i32 ( ) ;
28
+ let ti16 = cx. type_i16 ( ) ;
29
+ let ti8 = cx. type_i8 ( ) ;
30
+ let dl_cstr = llvm:: LLVMGetDataLayoutStr ( old_cx. llmod ) ;
31
+ llvm:: LLVMSetDataLayout ( llmod, dl_cstr) ;
32
+ // target triple = "x86_64-unknown-linux-gnu"
33
+
34
+ let mut entry_fields = [ ti64, ti16, ti16, ti32, tptr, tptr, ti64, ti64, tptr] ;
35
+
36
+ let entry_struct_name = CString :: new ( "__tgt_offload_entry" ) . unwrap ( ) ;
37
+ let entry_struct = llvm:: LLVMStructCreateNamed ( llcx, entry_struct_name. as_ptr ( ) ) ;
38
+ llvm:: LLVMStructSetBody (
39
+ entry_struct,
40
+ entry_fields. as_mut_ptr ( ) ,
41
+ entry_fields. len ( ) as u32 ,
42
+ 0 ,
43
+ ) ;
44
+
45
+ llvm:: LLVMPrintModuleToFile (
46
+ llmod,
47
+ CString :: new ( "rustmagic.openmp.image.wrapper.ll" ) . unwrap ( ) . as_ptr ( ) ,
48
+ std:: ptr:: null_mut ( ) ,
49
+ ) ;
50
+
51
+ // Clean up
52
+ llvm:: LLVMDisposeModule ( llmod) ;
53
+ llvm:: LLVMContextDispose ( llcx) ;
54
+ }
55
+ }
56
+
13
57
// first we need to add all the fun to the host module
14
58
// %struct.__tgt_offload_entry = type { i64, i16, i16, i32, ptr, ptr, i64, i64, ptr }
15
59
// %struct.__tgt_kernel_arguments = type { i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, [3 x i32], [3 x i32], i32 }
16
- pub ( crate ) fn handle_gpu_code < ' ll > ( cx : & ' ll SimpleCx < ' _ > ) {
60
+ pub ( crate ) fn handle_gpu_code < ' ll > (
61
+ cgcx : & CodegenContext < LlvmCodegenBackend > ,
62
+ cx : & ' ll SimpleCx < ' _ > ,
63
+ ) {
17
64
if cx. get_function ( "gen_tgt_offload" ) . is_some ( ) {
18
65
let ( offload_entry_ty, at_one, begin, update, end, fn_ty) = gen_globals ( & cx) ;
19
66
@@ -29,7 +76,7 @@ pub(crate) fn handle_gpu_code<'ll>(cx: &'ll SimpleCx<'_>) {
29
76
}
30
77
dbg ! ( "gen_call_handling" ) ;
31
78
gen_call_handling ( & cx, & kernels, at_one, begin, update, end, fn_ty, & o_types) ;
32
- gen_image_wrapper_module ( ) ;
79
+ gen_image_wrapper_module ( & cgcx , & cx ) ;
33
80
} else {
34
81
dbg ! ( "no marker found" ) ;
35
82
}
@@ -413,5 +460,3 @@ fn gen_call_handling<'ll>(
413
460
// @1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @0 }, align 8
414
461
}
415
462
}
416
-
417
- pub ( crate ) fn gen_image_wrapper_module ( ) { }
0 commit comments