@@ -10,14 +10,15 @@ use rustc_middle::mir::mono::MonoItem;
10
10
11
11
use cranelift_jit:: { JITBuilder , JITModule } ;
12
12
13
- use crate :: prelude:: * ;
13
+ use crate :: { prelude:: * , BackendConfig } ;
14
14
use crate :: { CodegenCx , CodegenMode } ;
15
15
16
16
thread_local ! {
17
+ pub static BACKEND_CONFIG : RefCell <Option <BackendConfig >> = RefCell :: new( None ) ;
17
18
pub static CURRENT_MODULE : RefCell <Option <JITModule >> = RefCell :: new( None ) ;
18
19
}
19
20
20
- pub ( super ) fn run_jit ( tcx : TyCtxt < ' _ > , codegen_mode : CodegenMode ) -> ! {
21
+ pub ( super ) fn run_jit ( tcx : TyCtxt < ' _ > , backend_config : BackendConfig ) -> ! {
21
22
if !tcx. sess . opts . output_types . should_codegen ( ) {
22
23
tcx. sess . fatal ( "JIT mode doesn't work with `cargo check`." ) ;
23
24
}
@@ -46,7 +47,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, codegen_mode: CodegenMode) -> ! {
46
47
crate :: build_isa ( tcx. sess ) ,
47
48
cranelift_module:: default_libcall_names ( ) ,
48
49
) ;
49
- jit_builder. hotswap ( matches ! ( codegen_mode, CodegenMode :: JitLazy ) ) ;
50
+ jit_builder. hotswap ( matches ! ( backend_config . codegen_mode, CodegenMode :: JitLazy ) ) ;
50
51
jit_builder. symbols ( imported_symbols) ;
51
52
let mut jit_module = JITModule :: new ( jit_builder) ;
52
53
assert_eq ! ( pointer_ty( tcx) , jit_module. target_config( ) . pointer_type( ) ) ;
@@ -74,14 +75,14 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, codegen_mode: CodegenMode) -> ! {
74
75
. into_iter ( )
75
76
. collect :: < Vec < ( _ , ( _ , _ ) ) > > ( ) ;
76
77
77
- let mut cx = crate :: CodegenCx :: new ( tcx, jit_module , false , false ) ;
78
+ let mut cx = crate :: CodegenCx :: new ( tcx, backend_config , jit_module , false ) ;
78
79
79
80
super :: time ( tcx, "codegen mono items" , || {
80
81
super :: predefine_mono_items ( & mut cx, & mono_items) ;
81
82
for ( mono_item, ( linkage, visibility) ) in mono_items {
82
83
let linkage = crate :: linkage:: get_clif_linkage ( mono_item, linkage, visibility) ;
83
84
match mono_item {
84
- MonoItem :: Fn ( inst) => match codegen_mode {
85
+ MonoItem :: Fn ( inst) => match backend_config . codegen_mode {
85
86
CodegenMode :: Aot => unreachable ! ( ) ,
86
87
CodegenMode :: Jit => {
87
88
cx. tcx . sess . time ( "codegen fn" , || {
@@ -137,6 +138,12 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, codegen_mode: CodegenMode) -> ! {
137
138
// useful as some dynamic linkers use it as a marker to jump over.
138
139
argv. push ( std:: ptr:: null ( ) ) ;
139
140
141
+ BACKEND_CONFIG . with ( |tls_backend_config| {
142
+ assert ! ( tls_backend_config
143
+ . borrow_mut( )
144
+ . replace( backend_config)
145
+ . is_none( ) )
146
+ } ) ;
140
147
CURRENT_MODULE
141
148
. with ( |current_module| assert ! ( current_module. borrow_mut( ) . replace( jit_module) . is_none( ) ) ) ;
142
149
@@ -154,7 +161,9 @@ extern "C" fn __clif_jit_fn(instance_ptr: *const Instance<'static>) -> *const u8
154
161
CURRENT_MODULE . with ( |jit_module| {
155
162
let mut jit_module = jit_module. borrow_mut ( ) ;
156
163
let jit_module = jit_module. as_mut ( ) . unwrap ( ) ;
157
- let mut cx = crate :: CodegenCx :: new ( tcx, jit_module, false , false ) ;
164
+ let backend_config =
165
+ BACKEND_CONFIG . with ( |backend_config| backend_config. borrow ( ) . clone ( ) . unwrap ( ) ) ;
166
+ let mut cx = crate :: CodegenCx :: new ( tcx, backend_config, jit_module, false ) ;
158
167
159
168
let name = tcx. symbol_name ( instance) . name . to_string ( ) ;
160
169
let sig = crate :: abi:: get_function_sig ( tcx, cx. module . isa ( ) . triple ( ) , instance) ;
0 commit comments