diff options
| author | bors <bors@rust-lang.org> | 2018-08-17 21:24:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-08-17 21:24:22 +0000 |
| commit | 1fa944914c092d728c8307e976a4b447df25bf16 (patch) | |
| tree | b61dd57fb983082285f9d301c028ae305d391ffe /src/librustc_codegen_llvm | |
| parent | c8c587fe4ea43afb1c3cf9fe008101f09003ccd1 (diff) | |
| parent | d662083a6c78928c70cc74b600205c246dab3bf6 (diff) | |
| download | rust-1fa944914c092d728c8307e976a4b447df25bf16.tar.gz rust-1fa944914c092d728c8307e976a4b447df25bf16.zip | |
Auto merge of #53356 - michaelwoerister:itlto, r=alexcrichton
Preliminary work for incremental ThinLTO (CGU name edition) Bring back the first half of #52266 but hopefully without the performance regression.
Diffstat (limited to 'src/librustc_codegen_llvm')
| -rw-r--r-- | src/librustc_codegen_llvm/back/link.rs | 7 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/back/lto.rs | 11 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/back/write.rs | 3 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/base.rs | 67 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/lib.rs | 4 |
5 files changed, 31 insertions, 61 deletions
diff --git a/src/librustc_codegen_llvm/back/link.rs b/src/librustc_codegen_llvm/back/link.rs index bbe1ccf3696..37c99932f56 100644 --- a/src/librustc_codegen_llvm/back/link.rs +++ b/src/librustc_codegen_llvm/back/link.rs @@ -46,13 +46,6 @@ use std::process::{Output, Stdio}; use std::str; use syntax::attr; -/// The LLVM module name containing crate-metadata. This includes a `.` on -/// purpose, so it cannot clash with the name of a user-defined module. -pub const METADATA_MODULE_NAME: &'static str = "crate.metadata"; - -// same as for metadata above, but for allocator shim -pub const ALLOCATOR_MODULE_NAME: &'static str = "crate.allocator"; - pub use rustc_codegen_utils::link::{find_crate_name, filename_for_input, default_output_for_target, invalid_output_for_target, build_link_meta, out_filename, check_file_is_writeable}; diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs index d7741230327..56858a31efd 100644 --- a/src/librustc_codegen_llvm/back/lto.rs +++ b/src/librustc_codegen_llvm/back/lto.rs @@ -242,7 +242,7 @@ fn fat_lto(cgcx: &CodegenContext, let llvm = module.llvm().expect("can't lto pre-codegened modules"); (&llvm.llcx, llvm.llmod()) }; - info!("using {:?} as a base module", module.llmod_id); + info!("using {:?} as a base module", module.name); // The linking steps below may produce errors and diagnostics within LLVM // which we'd like to handle and print, so set up our diagnostic handlers @@ -257,7 +257,7 @@ fn fat_lto(cgcx: &CodegenContext, for module in modules { let llvm = module.llvm().expect("can't lto pre-codegened modules"); let buffer = ModuleBuffer::new(llvm.llmod()); - let llmod_id = CString::new(&module.llmod_id[..]).unwrap(); + let llmod_id = CString::new(&module.name[..]).unwrap(); serialized_modules.push((SerializedModule::Local(buffer), llmod_id)); } @@ -384,9 +384,9 @@ fn thin_lto(diag_handler: &Handler, // the most expensive portion of this small bit of global // analysis! for (i, module) in modules.iter().enumerate() { - info!("local module: {} - {}", i, module.llmod_id); + info!("local module: {} - {}", i, module.name); let llvm = module.llvm().expect("can't lto precodegened module"); - let name = CString::new(module.llmod_id.clone()).unwrap(); + let name = CString::new(module.name.clone()).unwrap(); let buffer = ThinBuffer::new(llvm.llmod()); thin_modules.push(llvm::ThinLTOModule { identifier: name.as_ptr(), @@ -395,7 +395,7 @@ fn thin_lto(diag_handler: &Handler, }); thin_buffers.push(buffer); module_names.push(name); - timeline.record(&module.llmod_id); + timeline.record(&module.name); } // FIXME: All upstream crates are deserialized internally in the @@ -668,7 +668,6 @@ impl ThinModule { llcx, tm, }), - llmod_id: self.name().to_string(), name: self.name().to_string(), kind: ModuleKind::Regular, }; diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs index d60983d7697..b62836ec255 100644 --- a/src/librustc_codegen_llvm/back/write.rs +++ b/src/librustc_codegen_llvm/back/write.rs @@ -728,7 +728,7 @@ unsafe fn codegen(cgcx: &CodegenContext, if config.emit_bc_compressed { let dst = bc_out.with_extension(RLIB_BYTECODE_EXTENSION); - let data = bytecode::encode(&module.llmod_id, data); + let data = bytecode::encode(&module.name, data); if let Err(e) = fs::write(&dst, data) { diag_handler.err(&format!("failed to write bytecode: {}", e)); } @@ -1338,7 +1338,6 @@ fn execute_work_item(cgcx: &CodegenContext, assert_eq!(bytecode_compressed.is_some(), config.emit_bc_compressed); Ok(WorkItemResult::Compiled(CompiledModule { - llmod_id: module.llmod_id.clone(), name: module_name, kind: ModuleKind::Regular, pre_existing: true, diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index 7ca6a89dd9b..e626cc3870f 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -36,7 +36,7 @@ use metadata; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::middle::lang_items::StartFnLangItem; use rustc::middle::weak_lang_items; -use rustc::mir::mono::{Linkage, Visibility, Stats}; +use rustc::mir::mono::{Linkage, Visibility, Stats, CodegenUnitNameBuilder}; use rustc::middle::cstore::{EncodedMetadata}; use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::layout::{self, Align, TyLayout, LayoutOf}; @@ -742,19 +742,23 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let crate_hash = tcx.crate_hash(LOCAL_CRATE); let link_meta = link::build_link_meta(crate_hash); + let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx); // Codegen the metadata. tcx.sess.profiler(|p| p.start_activity(ProfileCategory::Codegen)); - let llmod_id = "metadata"; - let metadata_llvm_module = ModuleLlvm::new(tcx.sess, llmod_id); + + let metadata_cgu_name = cgu_name_builder.build_cgu_name(LOCAL_CRATE, + &["crate"], + Some("metadata")).as_str() + .to_string(); + let metadata_llvm_module = ModuleLlvm::new(tcx.sess, &metadata_cgu_name); let metadata = time(tcx.sess, "write metadata", || { write_metadata(tcx, &metadata_llvm_module, &link_meta) }); tcx.sess.profiler(|p| p.end_activity(ProfileCategory::Codegen)); let metadata_module = ModuleCodegen { - name: link::METADATA_MODULE_NAME.to_string(), - llmod_id: llmod_id.to_string(), + name: metadata_cgu_name, source: ModuleSource::Codegened(metadata_llvm_module), kind: ModuleKind::Metadata, }; @@ -833,20 +837,22 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let allocator_module = if any_dynamic_crate { None } else if let Some(kind) = *tcx.sess.allocator_kind.get() { - unsafe { - let llmod_id = "allocator"; - let modules = ModuleLlvm::new(tcx.sess, llmod_id); - time(tcx.sess, "write allocator module", || { + let llmod_id = cgu_name_builder.build_cgu_name(LOCAL_CRATE, + &["crate"], + Some("allocator")).as_str() + .to_string(); + let modules = ModuleLlvm::new(tcx.sess, &llmod_id); + time(tcx.sess, "write allocator module", || { + unsafe { allocator::codegen(tcx, &modules, kind) - }); + } + }); - Some(ModuleCodegen { - name: link::ALLOCATOR_MODULE_NAME.to_string(), - llmod_id: llmod_id.to_string(), - source: ModuleSource::Codegened(modules), - kind: ModuleKind::Allocator, - }) - } + Some(ModuleCodegen { + name: llmod_id, + source: ModuleSource::Codegened(modules), + kind: ModuleKind::Allocator, + }) } else { None }; @@ -889,21 +895,10 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // succeed it means that none of the dependencies has changed // and we can safely re-use. if let Some(dep_node_index) = tcx.dep_graph.try_mark_green(tcx, dep_node) { - // 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", cgu.name()); - let module = ModuleCodegen { name: cgu.name().to_string(), source: ModuleSource::Preexisting(buf), kind: ModuleKind::Regular, - llmod_id, }; tcx.dep_graph.mark_loaded_from_cache(dep_node_index, true); write::submit_codegened_module_to_llvm(tcx, module, 0); @@ -1212,21 +1207,8 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, { let cgu_name = cgu.name().to_string(); - // 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", - cgu.name(), - tcx.crate_disambiguator(LOCAL_CRATE) - .to_fingerprint().to_hex()); - // Instantiate monomorphizations without filling out definitions yet... - let llvm_module = ModuleLlvm::new(tcx.sess, &llmod_id); + let llvm_module = ModuleLlvm::new(tcx.sess, &cgu_name); let stats = { let cx = CodegenCx::new(tcx, cgu, &llvm_module); let mono_items = cx.codegen_unit @@ -1282,7 +1264,6 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, name: cgu_name, source: ModuleSource::Codegened(llvm_module), kind: ModuleKind::Regular, - llmod_id, }) } } diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 390a1df02b8..a65511a24af 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -269,8 +269,8 @@ struct ModuleCodegen { /// unique amongst **all** crates. Therefore, it should contain /// something unique to this crate (e.g., a module path) as well /// as the crate name and disambiguator. + /// We currently generate these names via CodegenUnit::build_cgu_name(). name: String, - llmod_id: String, source: ModuleSource, kind: ModuleKind, } @@ -317,7 +317,6 @@ impl ModuleCodegen { }; CompiledModule { - llmod_id: self.llmod_id, name: self.name.clone(), kind: self.kind, pre_existing, @@ -331,7 +330,6 @@ impl ModuleCodegen { #[derive(Debug)] struct CompiledModule { name: String, - llmod_id: String, kind: ModuleKind, pre_existing: bool, object: Option<PathBuf>, |
