diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-01-27 04:43:28 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-27 04:43:28 +0900 |
| commit | acbd1010efd1f0dfc83d45d330a028cc7ca9433d (patch) | |
| tree | a4f59ddcb72a8675b42c01fcf925ee5897809e57 /compiler/rustc_codegen_ssa/src | |
| parent | 3741844711916e306bf570232417d4155c1c7caf (diff) | |
| parent | 59195a277246ec194ca3a02ecc563c4dd9c06857 (diff) | |
| download | rust-acbd1010efd1f0dfc83d45d330a028cc7ca9433d.tar.gz rust-acbd1010efd1f0dfc83d45d330a028cc7ca9433d.zip | |
Rollup merge of #81369 - tgnottingham:codegen-to-llvm-ir-wall-time, r=lcnr
rustc_codegen_ssa: use wall time for codegen_to_LLVM_IR time-passes entry Use elapsed wall time spent on codegen_to_LLVM_IR for all CGUs as a whole, rather than the sum for each CGU (the distinction matters for parallel builds, where some CGUs are processed in parallel).
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/base.rs | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index b205ea9cf6c..ca7d3d1d81b 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -13,7 +13,7 @@ use crate::{CachedModuleCodegen, CrateInfo, MemFlags, ModuleCodegen, ModuleKind} use rustc_attr as attr; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::profiling::print_time_passes_entry; -use rustc_data_structures::sync::{par_iter, Lock, ParallelIterator}; +use rustc_data_structures::sync::{par_iter, ParallelIterator}; use rustc_hir as hir; use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE}; use rustc_hir::lang_items::LangItem; @@ -554,8 +554,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>( codegen_units }; - let total_codegen_time = Lock::new(Duration::new(0, 0)); - // The non-parallel compiler can only translate codegen units to LLVM IR // on a single thread, leading to a staircase effect where the N LLVM // threads have to wait on the single codegen threads to generate work @@ -578,23 +576,25 @@ pub fn codegen_crate<B: ExtraBackendMethods>( .collect(); // Compile the found CGUs in parallel. - par_iter(cgus) + let start_time = Instant::now(); + + let pre_compiled_cgus = par_iter(cgus) .map(|(i, _)| { - let start_time = Instant::now(); let module = backend.compile_codegen_unit(tcx, codegen_units[i].name()); - let mut time = total_codegen_time.lock(); - *time += start_time.elapsed(); (i, module) }) - .collect() + .collect(); + + (pre_compiled_cgus, start_time.elapsed()) }) } else { - FxHashMap::default() + (FxHashMap::default(), Duration::new(0, 0)) } }; let mut cgu_reuse = Vec::new(); let mut pre_compiled_cgus: Option<FxHashMap<usize, _>> = None; + let mut total_codegen_time = Duration::new(0, 0); for (i, cgu) in codegen_units.iter().enumerate() { ongoing_codegen.wait_for_signal_to_codegen_item(); @@ -607,7 +607,9 @@ pub fn codegen_crate<B: ExtraBackendMethods>( codegen_units.iter().map(|cgu| determine_cgu_reuse(tcx, &cgu)).collect() }); // Pre compile some CGUs - pre_compiled_cgus = Some(pre_compile_cgus(&cgu_reuse)); + let (compiled_cgus, codegen_time) = pre_compile_cgus(&cgu_reuse); + pre_compiled_cgus = Some(compiled_cgus); + total_codegen_time += codegen_time; } let cgu_reuse = cgu_reuse[i]; @@ -621,8 +623,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>( } else { let start_time = Instant::now(); let module = backend.compile_codegen_unit(tcx, cgu.name()); - let mut time = total_codegen_time.lock(); - *time += start_time.elapsed(); + total_codegen_time += start_time.elapsed(); module }; submit_codegened_module_to_llvm( @@ -663,11 +664,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>( // Since the main thread is sometimes blocked during codegen, we keep track // -Ztime-passes output manually. - print_time_passes_entry( - tcx.sess.time_passes(), - "codegen_to_LLVM_IR", - total_codegen_time.into_inner(), - ); + print_time_passes_entry(tcx.sess.time_passes(), "codegen_to_LLVM_IR", total_codegen_time); ongoing_codegen.check_for_errors(tcx.sess); |
