Skip to content

Commit c62fa76

Browse files
trans: Make partitioning available in LocalCrateContext.
1 parent a95a50f commit c62fa76

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/librustc_trans/context.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub struct LocalCrateContext<'tcx> {
9696
llmod: ModuleRef,
9797
llcx: ContextRef,
9898
tn: TypeNames, // FIXME: This seems to be largely unused.
99+
codegen_unit: CodegenUnit<'tcx>,
99100
needs_unwind_cleanup_cache: RefCell<FnvHashMap<Ty<'tcx>, bool>>,
100101
fn_pointer_shims: RefCell<FnvHashMap<Ty<'tcx>, ValueRef>>,
101102
drop_glues: RefCell<FnvHashMap<DropGlueKind<'tcx>, ValueRef>>,
@@ -198,18 +199,8 @@ impl<'a, 'tcx: 'a> CrateContextList<'a, 'tcx> {
198199
-> CrateContextList<'a, 'tcx> {
199200
CrateContextList {
200201
shared: shared_ccx,
201-
// FIXME: We don't actually use the codegen unit partitioning yet.
202-
local_ccxs: codegen_units.iter().map(|cgu| {
203-
// Append ".rs" to crate name as LLVM module identifier.
204-
//
205-
// LLVM code generator emits a ".file filename" directive
206-
// for ELF backends. Value of the "filename" is set as the
207-
// LLVM module identifier. Due to a LLVM MC bug[1], LLVM
208-
// crashes if the module identifier is same as other symbols
209-
// such as a function name in the module.
210-
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
211-
let llmod_id = format!("{}.rs", cgu.name);
212-
LocalCrateContext::new(shared_ccx, &llmod_id[..])
202+
local_ccxs: codegen_units.into_iter().map(|codegen_unit| {
203+
LocalCrateContext::new(shared_ccx, codegen_unit)
213204
}).collect()
214205
}
215206
}
@@ -494,10 +485,21 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
494485

495486
impl<'tcx> LocalCrateContext<'tcx> {
496487
fn new<'a>(shared: &SharedCrateContext<'a, 'tcx>,
497-
name: &str)
488+
codegen_unit: CodegenUnit<'tcx>)
498489
-> LocalCrateContext<'tcx> {
499490
unsafe {
500-
let (llcx, llmod) = create_context_and_module(&shared.tcx.sess, name);
491+
// Append ".rs" to LLVM module identifier.
492+
//
493+
// LLVM code generator emits a ".file filename" directive
494+
// for ELF backends. Value of the "filename" is set as the
495+
// LLVM module identifier. Due to a LLVM MC bug[1], LLVM
496+
// crashes if the module identifier is same as other symbols
497+
// such as a function name in the module.
498+
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
499+
let llmod_id = format!("{}.rs", codegen_unit.name);
500+
501+
let (llcx, llmod) = create_context_and_module(&shared.tcx.sess,
502+
&llmod_id[..]);
501503

502504
let dbg_cx = if shared.tcx.sess.opts.debuginfo != NoDebugInfo {
503505
Some(debuginfo::CrateDebugContext::new(llmod))
@@ -508,6 +510,7 @@ impl<'tcx> LocalCrateContext<'tcx> {
508510
let local_ccx = LocalCrateContext {
509511
llmod: llmod,
510512
llcx: llcx,
513+
codegen_unit: codegen_unit,
511514
tn: TypeNames::new(),
512515
needs_unwind_cleanup_cache: RefCell::new(FnvHashMap()),
513516
fn_pointer_shims: RefCell::new(FnvHashMap()),
@@ -664,6 +667,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
664667
self.local().llcx
665668
}
666669

670+
pub fn codegen_unit(&self) -> &CodegenUnit<'tcx> {
671+
&self.local().codegen_unit
672+
}
673+
667674
pub fn td(&self) -> llvm::TargetDataRef {
668675
unsafe { llvm::LLVMRustGetModuleDataLayout(self.llmod()) }
669676
}

0 commit comments

Comments
 (0)