From a8e34dfc29df9ca817e9d1e91f3e49f6d405fe28 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 6 May 2016 15:21:17 -0400 Subject: [PATCH] trans: Make partitioning available in LocalCrateContext. --- src/librustc_trans/context.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs index 9f5fe28ee8218..9692d31ee1451 100644 --- a/src/librustc_trans/context.rs +++ b/src/librustc_trans/context.rs @@ -96,6 +96,7 @@ pub struct LocalCrateContext<'tcx> { llmod: ModuleRef, llcx: ContextRef, tn: TypeNames, // FIXME: This seems to be largely unused. + codegen_unit: CodegenUnit<'tcx>, needs_unwind_cleanup_cache: RefCell, bool>>, fn_pointer_shims: RefCell, ValueRef>>, drop_glues: RefCell, ValueRef>>, @@ -201,18 +202,8 @@ impl<'a, 'tcx: 'a> CrateContextList<'a, 'tcx> { -> CrateContextList<'a, 'tcx> { CrateContextList { shared: shared_ccx, - // FIXME: We don't actually use the codegen unit partitioning yet. - local_ccxs: codegen_units.iter().map(|cgu| { - // Append ".rs" to crate name as LLVM module identifier. - // - // LLVM code generator emits a ".file filename" directive - // for ELF backends. Value of the "filename" is set as the - // LLVM module identifier. Due to a LLVM MC bug[1], LLVM - // crashes if the module identifier is same as other symbols - // such as a function name in the module. - // 1. http://llvm.org/bugs/show_bug.cgi?id=11479 - let llmod_id = format!("{}.rs", cgu.name); - LocalCrateContext::new(shared_ccx, &llmod_id[..]) + local_ccxs: codegen_units.into_iter().map(|codegen_unit| { + LocalCrateContext::new(shared_ccx, codegen_unit) }).collect() } } @@ -497,10 +488,21 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> { impl<'tcx> LocalCrateContext<'tcx> { fn new<'a>(shared: &SharedCrateContext<'a, 'tcx>, - name: &str) + codegen_unit: CodegenUnit<'tcx>) -> LocalCrateContext<'tcx> { unsafe { - let (llcx, llmod) = create_context_and_module(&shared.tcx.sess, name); + // Append ".rs" to LLVM module identifier. + // + // LLVM code generator emits a ".file filename" directive + // for ELF backends. Value of the "filename" is set as the + // LLVM module identifier. Due to a LLVM MC bug[1], LLVM + // crashes if the module identifier is same as other symbols + // such as a function name in the module. + // 1. http://llvm.org/bugs/show_bug.cgi?id=11479 + let llmod_id = format!("{}.rs", codegen_unit.name); + + let (llcx, llmod) = create_context_and_module(&shared.tcx.sess, + &llmod_id[..]); let dbg_cx = if shared.tcx.sess.opts.debuginfo != NoDebugInfo { Some(debuginfo::CrateDebugContext::new(llmod)) @@ -511,6 +513,7 @@ impl<'tcx> LocalCrateContext<'tcx> { let local_ccx = LocalCrateContext { llmod: llmod, llcx: llcx, + codegen_unit: codegen_unit, tn: TypeNames::new(), needs_unwind_cleanup_cache: RefCell::new(FnvHashMap()), fn_pointer_shims: RefCell::new(FnvHashMap()), @@ -668,6 +671,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { self.local().llcx } + pub fn codegen_unit(&self) -> &CodegenUnit<'tcx> { + &self.local().codegen_unit + } + pub fn td(&self) -> llvm::TargetDataRef { unsafe { llvm::LLVMRustGetModuleDataLayout(self.llmod()) } }