Use CGU name as LLVM module name and add some caching to CGU name generation.
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user