Move codegen_and_compile_fn to driver/jit.rs

This commit is contained in:
bjorn3 2023-02-03 16:48:35 +00:00
parent 21bdff8bc0
commit a465d6a860
2 changed files with 26 additions and 35 deletions

View File

@ -21,23 +21,6 @@ pub(crate) struct CodegenedFunction {
func_debug_cx: Option<FunctionDebugContext>, func_debug_cx: Option<FunctionDebugContext>,
} }
#[cfg_attr(not(feature = "jit"), allow(dead_code))]
pub(crate) fn codegen_and_compile_fn<'tcx>(
tcx: TyCtxt<'tcx>,
cx: &mut crate::CodegenCx,
cached_context: &mut Context,
module: &mut dyn Module,
instance: Instance<'tcx>,
) {
let _inst_guard =
crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name));
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
let codegened_func = codegen_fn(tcx, cx, cached_func, module, instance);
compile_fn(cx, cached_context, module, codegened_func);
}
pub(crate) fn codegen_fn<'tcx>( pub(crate) fn codegen_fn<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
cx: &mut crate::CodegenCx, cx: &mut crate::CodegenCx,

View File

@ -128,15 +128,13 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
MonoItem::Fn(inst) => match backend_config.codegen_mode { MonoItem::Fn(inst) => match backend_config.codegen_mode {
CodegenMode::Aot => unreachable!(), CodegenMode::Aot => unreachable!(),
CodegenMode::Jit => { CodegenMode::Jit => {
tcx.sess.time("codegen fn", || { codegen_and_compile_fn(
crate::base::codegen_and_compile_fn( tcx,
tcx, &mut cx,
&mut cx, &mut cached_context,
&mut cached_context, &mut jit_module,
&mut jit_module, inst,
inst, );
)
});
} }
CodegenMode::JitLazy => { CodegenMode::JitLazy => {
codegen_shim(tcx, &mut cx, &mut cached_context, &mut jit_module, inst) 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) -> ! {
} }
} }
pub(crate) fn codegen_and_compile_fn<'tcx>(
tcx: TyCtxt<'tcx>,
cx: &mut crate::CodegenCx,
cached_context: &mut Context,
module: &mut dyn Module,
instance: Instance<'tcx>,
) {
tcx.sess.time("codegen and compile fn", || {
let _inst_guard =
crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name));
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
let codegened_func = crate::base::codegen_fn(tcx, cx, cached_func, module, instance);
crate::base::compile_fn(cx, cached_context, module, codegened_func);
});
}
extern "C" fn clif_jit_fn( extern "C" fn clif_jit_fn(
instance_ptr: *const Instance<'static>, instance_ptr: *const Instance<'static>,
trampoline_ptr: *const u8, trampoline_ptr: *const u8,
@ -271,15 +287,7 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
false, false,
Symbol::intern("dummy_cgu_name"), Symbol::intern("dummy_cgu_name"),
); );
tcx.sess.time("codegen fn", || { codegen_and_compile_fn(tcx, &mut cx, &mut Context::new(), jit_module, instance);
crate::base::codegen_and_compile_fn(
tcx,
&mut cx,
&mut Context::new(),
jit_module,
instance,
)
});
assert!(cx.global_asm.is_empty()); assert!(cx.global_asm.is_empty());
jit_module.finalize_definitions().unwrap(); jit_module.finalize_definitions().unwrap();