Skip to content

Commit a465d6a

Browse files
committed
Move codegen_and_compile_fn to driver/jit.rs
1 parent 21bdff8 commit a465d6a

File tree

2 files changed

+26
-35
lines changed

2 files changed

+26
-35
lines changed

src/base.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,6 @@ pub(crate) struct CodegenedFunction {
2121
func_debug_cx: Option<FunctionDebugContext>,
2222
}
2323

24-
#[cfg_attr(not(feature = "jit"), allow(dead_code))]
25-
pub(crate) fn codegen_and_compile_fn<'tcx>(
26-
tcx: TyCtxt<'tcx>,
27-
cx: &mut crate::CodegenCx,
28-
cached_context: &mut Context,
29-
module: &mut dyn Module,
30-
instance: Instance<'tcx>,
31-
) {
32-
let _inst_guard =
33-
crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name));
34-
35-
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
36-
let codegened_func = codegen_fn(tcx, cx, cached_func, module, instance);
37-
38-
compile_fn(cx, cached_context, module, codegened_func);
39-
}
40-
4124
pub(crate) fn codegen_fn<'tcx>(
4225
tcx: TyCtxt<'tcx>,
4326
cx: &mut crate::CodegenCx,

src/driver/jit.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,13 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
128128
MonoItem::Fn(inst) => match backend_config.codegen_mode {
129129
CodegenMode::Aot => unreachable!(),
130130
CodegenMode::Jit => {
131-
tcx.sess.time("codegen fn", || {
132-
crate::base::codegen_and_compile_fn(
133-
tcx,
134-
&mut cx,
135-
&mut cached_context,
136-
&mut jit_module,
137-
inst,
138-
)
139-
});
131+
codegen_and_compile_fn(
132+
tcx,
133+
&mut cx,
134+
&mut cached_context,
135+
&mut jit_module,
136+
inst,
137+
);
140138
}
141139
CodegenMode::JitLazy => {
142140
codegen_shim(tcx, &mut cx, &mut cached_context, &mut jit_module, inst)
@@ -219,6 +217,24 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
219217
}
220218
}
221219

220+
pub(crate) fn codegen_and_compile_fn<'tcx>(
221+
tcx: TyCtxt<'tcx>,
222+
cx: &mut crate::CodegenCx,
223+
cached_context: &mut Context,
224+
module: &mut dyn Module,
225+
instance: Instance<'tcx>,
226+
) {
227+
tcx.sess.time("codegen and compile fn", || {
228+
let _inst_guard =
229+
crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name));
230+
231+
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
232+
let codegened_func = crate::base::codegen_fn(tcx, cx, cached_func, module, instance);
233+
234+
crate::base::compile_fn(cx, cached_context, module, codegened_func);
235+
});
236+
}
237+
222238
extern "C" fn clif_jit_fn(
223239
instance_ptr: *const Instance<'static>,
224240
trampoline_ptr: *const u8,
@@ -271,15 +287,7 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
271287
false,
272288
Symbol::intern("dummy_cgu_name"),
273289
);
274-
tcx.sess.time("codegen fn", || {
275-
crate::base::codegen_and_compile_fn(
276-
tcx,
277-
&mut cx,
278-
&mut Context::new(),
279-
jit_module,
280-
instance,
281-
)
282-
});
290+
codegen_and_compile_fn(tcx, &mut cx, &mut Context::new(), jit_module, instance);
283291

284292
assert!(cx.global_asm.is_empty());
285293
jit_module.finalize_definitions().unwrap();

0 commit comments

Comments
 (0)