Use multiple codegen units

Fixes #909
This commit is contained in:
bjorn3 2020-03-09 11:21:40 +01:00
parent 07799fee41
commit 11b1c8b5c6
2 changed files with 31 additions and 30 deletions

View File

@ -315,7 +315,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module<impl Backend>, cx: &mu
if tcx.is_reachable_non_generic(def_id) { if tcx.is_reachable_non_generic(def_id) {
Linkage::Export Linkage::Export
} else { } else {
Linkage::Local Linkage::Export // FIXME Set hidden visibility
}, },
); );
(data_id, alloc) (data_id, alloc)

View File

@ -72,7 +72,9 @@ fn run_jit(tcx: TyCtxt<'_>) -> ! {
.iter() .iter()
.map(|cgu| cgu.items_in_deterministic_order(tcx).into_iter()) .map(|cgu| cgu.items_in_deterministic_order(tcx).into_iter())
.flatten() .flatten()
.collect::<FxHashMap<_, (_, _)>>(); .collect::<FxHashMap<_, (_, _)>>()
.into_iter()
.collect::<Vec<(_, (_, _))>>();
time(tcx.sess, "codegen mono items", || { time(tcx.sess, "codegen mono items", || {
codegen_mono_items(tcx, &mut jit_module, None, mono_items); codegen_mono_items(tcx, &mut jit_module, None, mono_items);
@ -208,36 +210,35 @@ fn run_aot(
}; };
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE); let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
let mono_items = cgus
.iter()
.map(|cgu| cgu.items_in_deterministic_order(tcx).into_iter())
.flatten()
.collect::<FxHashMap<_, (_, _)>>();
let mut module = new_module("some_file".to_string()); let modules = time(tcx.sess, "codegen mono items", move || {
cgus.iter().map(|cgu| {
let mono_items = cgu.items_in_deterministic_order(tcx);
let mut debug = if tcx.sess.opts.debuginfo != DebugInfo::None { let mut module = new_module(cgu.name().as_str().to_string());
let debug = DebugContext::new(
tcx,
module.target_config().pointer_type().bytes() as u8,
);
Some(debug)
} else {
None
};
time(tcx.sess, "codegen mono items", || { let mut debug = if tcx.sess.opts.debuginfo != DebugInfo::None {
codegen_mono_items(tcx, &mut module, debug.as_mut(), mono_items); let debug = DebugContext::new(
tcx,
module.target_config().pointer_type().bytes() as u8,
);
Some(debug)
} else {
None
};
codegen_mono_items(tcx, &mut module, debug.as_mut(), mono_items);
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module);
emit_module(
tcx,
cgu.name().as_str().to_string(),
ModuleKind::Regular,
module,
debug,
)
}).collect::<Vec<_>>()
}); });
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module);
let modules = vec![emit_module(
tcx,
"some_file".to_string(),
ModuleKind::Regular,
module,
debug,
)];
tcx.sess.abort_if_errors(); tcx.sess.abort_if_errors();
@ -310,12 +311,12 @@ fn codegen_mono_items<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
module: &mut Module<impl Backend + 'static>, module: &mut Module<impl Backend + 'static>,
debug_context: Option<&mut DebugContext<'tcx>>, debug_context: Option<&mut DebugContext<'tcx>>,
mono_items: FxHashMap<MonoItem<'tcx>, (RLinkage, Visibility)>, mono_items: Vec<(MonoItem<'tcx>, (RLinkage, Visibility))>,
) { ) {
let mut cx = CodegenCx::new(tcx, module, debug_context); let mut cx = CodegenCx::new(tcx, module, debug_context);
tcx.sess.time("predefine functions", || { tcx.sess.time("predefine functions", || {
for (&mono_item, &(linkage, visibility)) in &mono_items { for &(mono_item, (linkage, visibility)) in &mono_items {
match mono_item { match mono_item {
MonoItem::Fn(instance) => { MonoItem::Fn(instance) => {
let (name, sig) = let (name, sig) =