diff options
| author | Wesley Wiser <wwiser@gmail.com> | 2019-02-13 08:13:30 -0500 |
|---|---|---|
| committer | Wesley Wiser <wwiser@gmail.com> | 2019-03-10 11:10:55 -0400 |
| commit | 4c8cc141863274683681a6fa3d5d4e0230780c66 (patch) | |
| tree | 427ecfcfd5b62a1287d9ff11799c247fc600b05a /src/librustc_codegen_llvm/back | |
| parent | 913ad6d1f092c70049934ba538d342d295d35997 (diff) | |
| download | rust-4c8cc141863274683681a6fa3d5d4e0230780c66.tar.gz rust-4c8cc141863274683681a6fa3d5d4e0230780c66.zip | |
Replace TimeLine with SelfProfiler
Diffstat (limited to 'src/librustc_codegen_llvm/back')
| -rw-r--r-- | src/librustc_codegen_llvm/back/lto.rs | 44 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/back/write.rs | 58 |
2 files changed, 45 insertions, 57 deletions
diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs index 944569c8b74..84c652ff238 100644 --- a/src/librustc_codegen_llvm/back/lto.rs +++ b/src/librustc_codegen_llvm/back/lto.rs @@ -3,7 +3,6 @@ use crate::back::write::{self, DiagnosticHandlers, with_llvm_pmb, save_temp_bitc to_llvm_opt_settings}; use crate::llvm::archive_ro::ArchiveRO; use crate::llvm::{self, True, False}; -use crate::time_graph::Timeline; use crate::{ModuleLlvm, LlvmCodegenBackend}; use rustc_codegen_ssa::back::symbol_export; use rustc_codegen_ssa::back::write::{ModuleConfig, CodegenContext, FatLTOInput}; @@ -16,6 +15,7 @@ use rustc::hir::def_id::LOCAL_CRATE; use rustc::middle::exported_symbols::SymbolExportLevel; use rustc::session::config::{self, Lto}; use rustc::util::common::time_ext; +use rustc::util::profiling::ProfileCategory; use rustc_data_structures::fx::FxHashMap; use rustc_codegen_ssa::{ModuleCodegen, ModuleKind}; @@ -37,7 +37,6 @@ pub fn crate_type_allows_lto(crate_type: config::CrateType) -> bool { } fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>, - timeline: &mut Timeline, diag_handler: &Handler) -> Result<(Vec<CString>, Vec<(SerializedModule<ModuleBuffer>, CString)>), FatalError> { @@ -68,7 +67,8 @@ fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>, .iter() .filter_map(symbol_filter) .collect::<Vec<CString>>(); - timeline.record("whitelist"); + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, + "generate_symbol_white_list_for_thinlto"); info!("{} symbols to preserve in this crate", symbol_white_list.len()); // If we're performing LTO for the entire crate graph, then for each of our @@ -97,6 +97,8 @@ fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>, } for &(cnum, ref path) in cgcx.each_linked_rlib_for_lto.iter() { + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, + format!("load: {}", path.display())); let exported_symbols = cgcx.exported_symbols .as_ref().expect("needs exported symbols for LTO"); symbol_white_list.extend( @@ -121,7 +123,6 @@ fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>, let bc = SerializedModule::FromRlib(bc); upstream_modules.push((bc, CString::new(id).unwrap())); } - timeline.record(&format!("load: {}", path.display())); } } @@ -132,12 +133,11 @@ fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>, /// for further optimization. pub(crate) fn run_fat(cgcx: &CodegenContext<LlvmCodegenBackend>, modules: Vec<FatLTOInput<LlvmCodegenBackend>>, - cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>, - timeline: &mut Timeline) + cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>) -> Result<LtoModuleCodegen<LlvmCodegenBackend>, FatalError> { let diag_handler = cgcx.create_diag_handler(); - let (symbol_white_list, upstream_modules) = prepare_lto(cgcx, timeline, &diag_handler)?; + let (symbol_white_list, upstream_modules) = prepare_lto(cgcx, &diag_handler)?; let symbol_white_list = symbol_white_list.iter() .map(|c| c.as_ptr()) .collect::<Vec<_>>(); @@ -148,7 +148,6 @@ pub(crate) fn run_fat(cgcx: &CodegenContext<LlvmCodegenBackend>, cached_modules, upstream_modules, &symbol_white_list, - timeline, ) } @@ -157,12 +156,11 @@ pub(crate) fn run_fat(cgcx: &CodegenContext<LlvmCodegenBackend>, /// can simply be copied over from the incr. comp. cache. pub(crate) fn run_thin(cgcx: &CodegenContext<LlvmCodegenBackend>, modules: Vec<(String, ThinBuffer)>, - cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>, - timeline: &mut Timeline) + cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>) -> Result<(Vec<LtoModuleCodegen<LlvmCodegenBackend>>, Vec<WorkProduct>), FatalError> { let diag_handler = cgcx.create_diag_handler(); - let (symbol_white_list, upstream_modules) = prepare_lto(cgcx, timeline, &diag_handler)?; + let (symbol_white_list, upstream_modules) = prepare_lto(cgcx, &diag_handler)?; let symbol_white_list = symbol_white_list.iter() .map(|c| c.as_ptr()) .collect::<Vec<_>>(); @@ -175,8 +173,7 @@ pub(crate) fn run_thin(cgcx: &CodegenContext<LlvmCodegenBackend>, modules, upstream_modules, cached_modules, - &symbol_white_list, - timeline) + &symbol_white_list) } pub(crate) fn prepare_thin( @@ -192,8 +189,7 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>, mut modules: Vec<FatLTOInput<LlvmCodegenBackend>>, cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>, mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>, - symbol_white_list: &[*const libc::c_char], - timeline: &mut Timeline) + symbol_white_list: &[*const libc::c_char]) -> Result<LtoModuleCodegen<LlvmCodegenBackend>, FatalError> { info!("going for a fat lto"); @@ -303,7 +299,6 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>, write::llvm_err(&diag_handler, &msg) }) })?; - timeline.record(&format!("link {:?}", name)); serialized_bitcode.push(bc_decoded); } drop(linker); @@ -325,7 +320,6 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>, } save_temp_bitcode(&cgcx, &module, "lto.after-nounwind"); } - timeline.record("passes"); } Ok(LtoModuleCodegen::Fat { @@ -395,8 +389,7 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>, modules: Vec<(String, ThinBuffer)>, serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>, cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>, - symbol_white_list: &[*const libc::c_char], - timeline: &mut Timeline) + symbol_white_list: &[*const libc::c_char]) -> Result<(Vec<LtoModuleCodegen<LlvmCodegenBackend>>, Vec<WorkProduct>), FatalError> { unsafe { @@ -422,7 +415,6 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>, }); thin_buffers.push(buffer); module_names.push(cname); - timeline.record(&name); } // FIXME: All upstream crates are deserialized internally in the @@ -475,7 +467,6 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>, })?; info!("thin LTO data created"); - timeline.record("data"); let import_map = if cgcx.incr_comp_session_dir.is_some() { ThinLTOImports::from_thin_lto_data(data) @@ -486,7 +477,6 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>, ThinLTOImports::default() }; info!("thin LTO import map loaded"); - timeline.record("import-map-loaded"); let data = ThinData(data); @@ -691,7 +681,6 @@ impl Drop for ThinBuffer { pub unsafe fn optimize_thin_module( thin_module: &mut ThinModule<LlvmCodegenBackend>, cgcx: &CodegenContext<LlvmCodegenBackend>, - timeline: &mut Timeline ) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> { let diag_handler = cgcx.create_diag_handler(); let tm = (cgcx.tm_factory.0)().map_err(|e| { @@ -738,9 +727,10 @@ pub unsafe fn optimize_thin_module( // Like with "fat" LTO, get some better optimizations if landing pads // are disabled by removing all landing pads. if cgcx.no_landing_pads { + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, + "LLVM_remove_landing_pads"); llvm::LLVMRustMarkAllFunctionsNounwind(llmod); save_temp_bitcode(&cgcx, &module, "thin-lto-after-nounwind"); - timeline.record("nounwind"); } // Up next comes the per-module local analyses that we do for Thin LTO. @@ -756,25 +746,21 @@ pub unsafe fn optimize_thin_module( return Err(write::llvm_err(&diag_handler, msg)) } save_temp_bitcode(cgcx, &module, "thin-lto-after-rename"); - timeline.record("rename"); if !llvm::LLVMRustPrepareThinLTOResolveWeak(thin_module.shared.data.0, llmod) { let msg = "failed to prepare thin LTO module"; return Err(write::llvm_err(&diag_handler, msg)) } save_temp_bitcode(cgcx, &module, "thin-lto-after-resolve"); - timeline.record("resolve"); if !llvm::LLVMRustPrepareThinLTOInternalize(thin_module.shared.data.0, llmod) { let msg = "failed to prepare thin LTO module"; return Err(write::llvm_err(&diag_handler, msg)) } save_temp_bitcode(cgcx, &module, "thin-lto-after-internalize"); - timeline.record("internalize"); if !llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod) { let msg = "failed to prepare thin LTO module"; return Err(write::llvm_err(&diag_handler, msg)) } save_temp_bitcode(cgcx, &module, "thin-lto-after-import"); - timeline.record("import"); // Ok now this is a bit unfortunate. This is also something you won't // find upstream in LLVM's ThinLTO passes! This is a hack for now to @@ -807,7 +793,6 @@ pub unsafe fn optimize_thin_module( // fixed in LLVM. llvm::LLVMRustThinLTOPatchDICompileUnit(llmod, cu1); save_temp_bitcode(cgcx, &module, "thin-lto-after-patch"); - timeline.record("patch"); // Alright now that we've done everything related to the ThinLTO // analysis it's time to run some optimizations! Here we use the same @@ -818,7 +803,6 @@ pub unsafe fn optimize_thin_module( let config = cgcx.config(module.kind); run_pass_manager(cgcx, &module, config, true); save_temp_bitcode(cgcx, &module, "thin-lto-after-pm"); - timeline.record("thin-done"); } Ok(module) } diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs index db5430a4219..dc4dd4e39e1 100644 --- a/src/librustc_codegen_llvm/back/write.rs +++ b/src/librustc_codegen_llvm/back/write.rs @@ -3,7 +3,6 @@ use crate::back::bytecode::{self, RLIB_BYTECODE_EXTENSION}; use crate::back::lto::ThinBuffer; use crate::base; use crate::consts; -use crate::time_graph::Timeline; use crate::llvm::{self, DiagnosticInfo, PassManager, SMDiagnostic}; use crate::llvm_util; use crate::ModuleLlvm; @@ -19,6 +18,7 @@ use rustc::session::Session; use rustc::ty::TyCtxt; use rustc_codegen_ssa::{ModuleCodegen, CompiledModule}; use rustc::util::common::time_ext; +use rustc::util::profiling::ProfileCategory; use rustc_fs_util::{path_to_c_string, link_or_copy}; use rustc_data_structures::small_c_str::SmallCStr; use errors::{Handler, FatalError}; @@ -305,8 +305,7 @@ unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>, diag_handler: &Handler, module: &ModuleCodegen<ModuleLlvm>, - config: &ModuleConfig, - timeline: &mut Timeline) + config: &ModuleConfig) -> Result<(), FatalError> { let llmod = module.module_llvm.llmod(); @@ -415,19 +414,24 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>, diag_handler.abort_if_errors(); // Finally, run the actual optimization passes - time_ext(config.time_passes, - None, - &format!("llvm function passes [{}]", module_name.unwrap()), - || { - llvm::LLVMRustRunFunctionPassManager(fpm, llmod) - }); - timeline.record("fpm"); - time_ext(config.time_passes, - None, - &format!("llvm module passes [{}]", module_name.unwrap()), - || { - llvm::LLVMRunPassManager(mpm, llmod) - }); + { + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, "LLVM_function_passes"); + time_ext(config.time_passes, + None, + &format!("llvm function passes [{}]", module_name.unwrap()), + || { + llvm::LLVMRustRunFunctionPassManager(fpm, llmod) + }); + } + { + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, "LLVM_module_passes"); + time_ext(config.time_passes, + None, + &format!("llvm module passes [{}]", module_name.unwrap()), + || { + llvm::LLVMRunPassManager(mpm, llmod) + }); + } // Deallocate managers that we're now done with llvm::LLVMDisposePassManager(fpm); @@ -439,11 +443,10 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>, pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>, diag_handler: &Handler, module: ModuleCodegen<ModuleLlvm>, - config: &ModuleConfig, - timeline: &mut Timeline) + config: &ModuleConfig) -> Result<CompiledModule, FatalError> { - timeline.record("codegen"); + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, "codegen"); { let llmod = module.module_llvm.llmod(); let llcx = &*module.module_llvm.llcx; @@ -494,29 +497,30 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>, if write_bc || config.emit_bc_compressed || config.embed_bitcode { + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, "LLVM_make_bitcode"); let thin = ThinBuffer::new(llmod); let data = thin.data(); - timeline.record("make-bc"); if write_bc { + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, "LLVM_emit_bitcode"); if let Err(e) = fs::write(&bc_out, data) { diag_handler.err(&format!("failed to write bytecode: {}", e)); } - timeline.record("write-bc"); } if config.embed_bitcode { + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, "LLVM_embed_bitcode"); embed_bitcode(cgcx, llcx, llmod, Some(data)); - timeline.record("embed-bc"); } if config.emit_bc_compressed { + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, + "LLVM_compress_bitcode"); let dst = bc_out.with_extension(RLIB_BYTECODE_EXTENSION); let data = bytecode::encode(&module.name, data); if let Err(e) = fs::write(&dst, data) { diag_handler.err(&format!("failed to write bytecode: {}", e)); } - timeline.record("compress-bc"); } } else if config.embed_bitcode_marker { embed_bitcode(cgcx, llcx, llmod, None); @@ -525,6 +529,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>, time_ext(config.time_passes, None, &format!("codegen passes [{}]", module_name.unwrap()), || -> Result<(), FatalError> { if config.emit_ir { + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, "LLVM_emit_ir"); let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name); let out = path_to_c_string(&out); @@ -563,10 +568,10 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>, llvm::LLVMRustPrintModule(cpm, llmod, out.as_ptr(), demangle_callback); llvm::LLVMDisposePassManager(cpm); }); - timeline.record("ir"); } if config.emit_asm || asm_to_obj { + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, "LLVM_emit_asm"); let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name); // We can't use the same module for asm and binary output, because that triggers @@ -581,19 +586,18 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<LlvmCodegenBackend>, write_output_file(diag_handler, tm, cpm, llmod, &path, llvm::FileType::AssemblyFile) })?; - timeline.record("asm"); } if write_obj { + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, "LLVM_emit_obj"); with_codegen(tm, llmod, config.no_builtins, |cpm| { write_output_file(diag_handler, tm, cpm, llmod, &obj_out, llvm::FileType::ObjectFile) })?; - timeline.record("obj"); } else if asm_to_obj { + let _timer = cgcx.profile_activity(ProfileCategory::Codegen, "LLVM_asm_to_obj"); let assembly = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name); run_assembler(cgcx, diag_handler, &assembly, &obj_out); - timeline.record("asm_to_obj"); if !config.emit_asm && !cgcx.save_temps { drop(fs::remove_file(&assembly)); |
