Skip to content

Commit d081c20

Browse files
committed
Compile functions from clif ir to object code in parallel
1 parent 1a63233 commit d081c20

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/base.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ use crate::debuginfo::FunctionDebugContext;
1111
use crate::prelude::*;
1212
use crate::pretty_clif::CommentWriter;
1313

14-
struct CodegenedFunction {
14+
pub(crate) struct CodegenedFunction {
1515
symbol_name: String,
1616
func_id: FuncId,
1717
func: Function,
1818
clif_comments: CommentWriter,
1919
func_debug_cx: Option<FunctionDebugContext>,
2020
}
2121

22+
#[cfg_attr(not(feature = "jit"), allow(dead_code))]
2223
pub(crate) fn codegen_and_compile_fn<'tcx>(
2324
tcx: TyCtxt<'tcx>,
2425
cx: &mut crate::CodegenCx,
@@ -35,7 +36,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
3536
compile_fn(cx, cached_context, module, codegened_func);
3637
}
3738

38-
fn codegen_fn<'tcx>(
39+
pub(crate) fn codegen_fn<'tcx>(
3940
tcx: TyCtxt<'tcx>,
4041
cx: &mut crate::CodegenCx,
4142
cached_func: Function,
@@ -135,7 +136,7 @@ fn codegen_fn<'tcx>(
135136
CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
136137
}
137138

138-
fn compile_fn(
139+
pub(crate) fn compile_fn(
139140
cx: &mut crate::CodegenCx,
140141
cached_context: &mut Context,
141142
module: &mut dyn Module,

src/driver/aot.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,14 @@ fn module_codegen(
271271
cgu_name,
272272
);
273273
super::predefine_mono_items(tcx, &mut module, &mono_items);
274-
let mut cached_context = Context::new();
274+
let mut codegened_functions = vec![];
275275
for (mono_item, _) in mono_items {
276276
match mono_item {
277277
MonoItem::Fn(inst) => {
278278
tcx.sess.time("codegen fn", || {
279-
crate::base::codegen_and_compile_fn(
280-
tcx,
281-
&mut cx,
282-
&mut cached_context,
283-
&mut module,
284-
inst,
285-
)
279+
let codegened_function =
280+
crate::base::codegen_fn(tcx, &mut cx, Function::new(), &mut module, inst);
281+
codegened_functions.push(codegened_function);
286282
});
287283
}
288284
MonoItem::Static(def_id) => crate::constant::codegen_static(tcx, &mut module, def_id),
@@ -302,6 +298,11 @@ fn module_codegen(
302298
let cgu_name = cgu.name().as_str().to_owned();
303299

304300
OngoingModuleCodegen::Async(std::thread::spawn(move || {
301+
let mut cached_context = Context::new();
302+
for codegened_func in codegened_functions {
303+
crate::base::compile_fn(&mut cx, &mut cached_context, &mut module, codegened_func);
304+
}
305+
305306
let global_asm_object_file =
306307
crate::global_asm::compile_global_asm(&global_asm_config, &cgu_name, &cx.global_asm)?;
307308

0 commit comments

Comments
 (0)