Skip to content

Commit 11b1c8b

Browse files
committed
Use multiple codegen units
Fixes #909
1 parent 07799fe commit 11b1c8b

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

src/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module<impl Backend>, cx: &mu
315315
if tcx.is_reachable_non_generic(def_id) {
316316
Linkage::Export
317317
} else {
318-
Linkage::Local
318+
Linkage::Export // FIXME Set hidden visibility
319319
},
320320
);
321321
(data_id, alloc)

src/driver.rs

+30-29
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ fn run_jit(tcx: TyCtxt<'_>) -> ! {
7272
.iter()
7373
.map(|cgu| cgu.items_in_deterministic_order(tcx).into_iter())
7474
.flatten()
75-
.collect::<FxHashMap<_, (_, _)>>();
75+
.collect::<FxHashMap<_, (_, _)>>()
76+
.into_iter()
77+
.collect::<Vec<(_, (_, _))>>();
7678

7779
time(tcx.sess, "codegen mono items", || {
7880
codegen_mono_items(tcx, &mut jit_module, None, mono_items);
@@ -208,36 +210,35 @@ fn run_aot(
208210
};
209211

210212
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
211-
let mono_items = cgus
212-
.iter()
213-
.map(|cgu| cgu.items_in_deterministic_order(tcx).into_iter())
214-
.flatten()
215-
.collect::<FxHashMap<_, (_, _)>>();
216213

217-
let mut module = new_module("some_file".to_string());
214+
let modules = time(tcx.sess, "codegen mono items", move || {
215+
cgus.iter().map(|cgu| {
216+
let mono_items = cgu.items_in_deterministic_order(tcx);
218217

219-
let mut debug = if tcx.sess.opts.debuginfo != DebugInfo::None {
220-
let debug = DebugContext::new(
221-
tcx,
222-
module.target_config().pointer_type().bytes() as u8,
223-
);
224-
Some(debug)
225-
} else {
226-
None
227-
};
218+
let mut module = new_module(cgu.name().as_str().to_string());
228219

229-
time(tcx.sess, "codegen mono items", || {
230-
codegen_mono_items(tcx, &mut module, debug.as_mut(), mono_items);
231-
});
232-
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module);
220+
let mut debug = if tcx.sess.opts.debuginfo != DebugInfo::None {
221+
let debug = DebugContext::new(
222+
tcx,
223+
module.target_config().pointer_type().bytes() as u8,
224+
);
225+
Some(debug)
226+
} else {
227+
None
228+
};
233229

234-
let modules = vec![emit_module(
235-
tcx,
236-
"some_file".to_string(),
237-
ModuleKind::Regular,
238-
module,
239-
debug,
240-
)];
230+
codegen_mono_items(tcx, &mut module, debug.as_mut(), mono_items);
231+
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module);
232+
233+
emit_module(
234+
tcx,
235+
cgu.name().as_str().to_string(),
236+
ModuleKind::Regular,
237+
module,
238+
debug,
239+
)
240+
}).collect::<Vec<_>>()
241+
});
241242

242243
tcx.sess.abort_if_errors();
243244

@@ -310,12 +311,12 @@ fn codegen_mono_items<'tcx>(
310311
tcx: TyCtxt<'tcx>,
311312
module: &mut Module<impl Backend + 'static>,
312313
debug_context: Option<&mut DebugContext<'tcx>>,
313-
mono_items: FxHashMap<MonoItem<'tcx>, (RLinkage, Visibility)>,
314+
mono_items: Vec<(MonoItem<'tcx>, (RLinkage, Visibility))>,
314315
) {
315316
let mut cx = CodegenCx::new(tcx, module, debug_context);
316317

317318
tcx.sess.time("predefine functions", || {
318-
for (&mono_item, &(linkage, visibility)) in &mono_items {
319+
for &(mono_item, (linkage, visibility)) in &mono_items {
319320
match mono_item {
320321
MonoItem::Fn(instance) => {
321322
let (name, sig) =

0 commit comments

Comments
 (0)