mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-09 16:37:36 +00:00
Compile functions from clif ir to object code in parallel
This commit is contained in:
parent
1a6323313b
commit
d081c20273
@ -11,7 +11,7 @@ use crate::debuginfo::FunctionDebugContext;
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::pretty_clif::CommentWriter;
|
use crate::pretty_clif::CommentWriter;
|
||||||
|
|
||||||
struct CodegenedFunction {
|
pub(crate) struct CodegenedFunction {
|
||||||
symbol_name: String,
|
symbol_name: String,
|
||||||
func_id: FuncId,
|
func_id: FuncId,
|
||||||
func: Function,
|
func: Function,
|
||||||
@ -19,6 +19,7 @@ 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>(
|
pub(crate) fn codegen_and_compile_fn<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
cx: &mut crate::CodegenCx,
|
cx: &mut crate::CodegenCx,
|
||||||
@ -35,7 +36,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
|
|||||||
compile_fn(cx, cached_context, module, codegened_func);
|
compile_fn(cx, cached_context, module, codegened_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn codegen_fn<'tcx>(
|
pub(crate) fn codegen_fn<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
cx: &mut crate::CodegenCx,
|
cx: &mut crate::CodegenCx,
|
||||||
cached_func: Function,
|
cached_func: Function,
|
||||||
@ -135,7 +136,7 @@ fn codegen_fn<'tcx>(
|
|||||||
CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
|
CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_fn(
|
pub(crate) fn compile_fn(
|
||||||
cx: &mut crate::CodegenCx,
|
cx: &mut crate::CodegenCx,
|
||||||
cached_context: &mut Context,
|
cached_context: &mut Context,
|
||||||
module: &mut dyn Module,
|
module: &mut dyn Module,
|
||||||
|
@ -271,18 +271,14 @@ fn module_codegen(
|
|||||||
cgu_name,
|
cgu_name,
|
||||||
);
|
);
|
||||||
super::predefine_mono_items(tcx, &mut module, &mono_items);
|
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 {
|
for (mono_item, _) in mono_items {
|
||||||
match mono_item {
|
match mono_item {
|
||||||
MonoItem::Fn(inst) => {
|
MonoItem::Fn(inst) => {
|
||||||
tcx.sess.time("codegen fn", || {
|
tcx.sess.time("codegen fn", || {
|
||||||
crate::base::codegen_and_compile_fn(
|
let codegened_function =
|
||||||
tcx,
|
crate::base::codegen_fn(tcx, &mut cx, Function::new(), &mut module, inst);
|
||||||
&mut cx,
|
codegened_functions.push(codegened_function);
|
||||||
&mut cached_context,
|
|
||||||
&mut module,
|
|
||||||
inst,
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
MonoItem::Static(def_id) => crate::constant::codegen_static(tcx, &mut module, def_id),
|
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();
|
let cgu_name = cgu.name().as_str().to_owned();
|
||||||
|
|
||||||
OngoingModuleCodegen::Async(std::thread::spawn(move || {
|
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 =
|
let global_asm_object_file =
|
||||||
crate::global_asm::compile_global_asm(&global_asm_config, &cgu_name, &cx.global_asm)?;
|
crate::global_asm::compile_global_asm(&global_asm_config, &cgu_name, &cx.global_asm)?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user