Compile functions from clif ir to object code in parallel

This commit is contained in:
bjorn3 2022-08-23 16:09:08 +00:00
parent 1a6323313b
commit d081c20273
2 changed files with 13 additions and 11 deletions

View File

@ -11,7 +11,7 @@ use crate::debuginfo::FunctionDebugContext;
use crate::prelude::*;
use crate::pretty_clif::CommentWriter;
struct CodegenedFunction {
pub(crate) struct CodegenedFunction {
symbol_name: String,
func_id: FuncId,
func: Function,
@ -19,6 +19,7 @@ struct CodegenedFunction {
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,
@ -35,7 +36,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
compile_fn(cx, cached_context, module, codegened_func);
}
fn codegen_fn<'tcx>(
pub(crate) fn codegen_fn<'tcx>(
tcx: TyCtxt<'tcx>,
cx: &mut crate::CodegenCx,
cached_func: Function,
@ -135,7 +136,7 @@ fn codegen_fn<'tcx>(
CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
}
fn compile_fn(
pub(crate) fn compile_fn(
cx: &mut crate::CodegenCx,
cached_context: &mut Context,
module: &mut dyn Module,

View File

@ -271,18 +271,14 @@ fn module_codegen(
cgu_name,
);
super::predefine_mono_items(tcx, &mut module, &mono_items);
let mut cached_context = Context::new();
let mut codegened_functions = vec![];
for (mono_item, _) in mono_items {
match mono_item {
MonoItem::Fn(inst) => {
tcx.sess.time("codegen fn", || {
crate::base::codegen_and_compile_fn(
tcx,
&mut cx,
&mut cached_context,
&mut module,
inst,
)
let codegened_function =
crate::base::codegen_fn(tcx, &mut cx, Function::new(), &mut module, inst);
codegened_functions.push(codegened_function);
});
}
MonoItem::Static(def_id) => crate::constant::codegen_static(tcx, &mut module, def_id),
@ -302,6 +298,11 @@ fn module_codegen(
let cgu_name = cgu.name().as_str().to_owned();
OngoingModuleCodegen::Async(std::thread::spawn(move || {
let mut cached_context = Context::new();
for codegened_func in codegened_functions {
crate::base::compile_fn(&mut cx, &mut cached_context, &mut module, codegened_func);
}
let global_asm_object_file =
crate::global_asm::compile_global_asm(&global_asm_config, &cgu_name, &cx.global_asm)?;