Skip to content

Commit a8e34df

Browse files
trans: Make partitioning available in LocalCrateContext.
1 parent bebcb28 commit a8e34df

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>>,
@@ -201,18 +202,8 @@ impl<'a, 'tcx: 'a> CrateContextList<'a, 'tcx> {
201202
-> CrateContextList<'a, 'tcx> {
202203
CrateContextList {
203204
shared: shared_ccx,
204-
// FIXME: We don't actually use the codegen unit partitioning yet.
205-
local_ccxs: codegen_units.iter().map(|cgu| {
206-
// Append ".rs" to crate name as LLVM module identifier.
207-
//
208-
// LLVM code generator emits a ".file filename" directive
209-
// for ELF backends. Value of the "filename" is set as the
210-
// LLVM module identifier. Due to a LLVM MC bug[1], LLVM
211-
// crashes if the module identifier is same as other symbols
212-
// such as a function name in the module.
213-
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
214-
let llmod_id = format!("{}.rs", cgu.name);
215-
LocalCrateContext::new(shared_ccx, &llmod_id[..])
205+
local_ccxs: codegen_units.into_iter().map(|codegen_unit| {
206+
LocalCrateContext::new(shared_ccx, codegen_unit)
216207
}).collect()
217208
}
218209
}
@@ -497,10 +488,21 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
497488

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

505507
let dbg_cx = if shared.tcx.sess.opts.debuginfo != NoDebugInfo {
506508
Some(debuginfo::CrateDebugContext::new(llmod))
@@ -511,6 +513,7 @@ impl<'tcx> LocalCrateContext<'tcx> {
511513
let local_ccx = LocalCrateContext {
512514
llmod: llmod,
513515
llcx: llcx,
516+
codegen_unit: codegen_unit,
514517
tn: TypeNames::new(),
515518
needs_unwind_cleanup_cache: RefCell::new(FnvHashMap()),
516519
fn_pointer_shims: RefCell::new(FnvHashMap()),
@@ -668,6 +671,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
668671
self.local().llcx
669672
}
670673

674+
pub fn codegen_unit(&self) -> &CodegenUnit<'tcx> {
675+
&self.local().codegen_unit
676+
}
677+
671678
pub fn td(&self) -> llvm::TargetDataRef {
672679
unsafe { llvm::LLVMRustGetModuleDataLayout(self.llmod()) }
673680
}

0 commit comments

Comments
 (0)