diff options
| author | bors <bors@rust-lang.org> | 2019-03-03 19:48:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-03-03 19:48:12 +0000 |
| commit | 87a436377a7cddd1d4426c9604c48e0aa2ec0b11 (patch) | |
| tree | 004e4050002db99f09f07452936cf6b1742d5575 /src/librustc_codegen_ssa | |
| parent | 2cfd6444a7fb4bd6acef2b97ba53059adc0500a6 (diff) | |
| parent | f20ad7043904023e810cfaeb5d775f281a4a1619 (diff) | |
| download | rust-87a436377a7cddd1d4426c9604c48e0aa2ec0b11.tar.gz rust-87a436377a7cddd1d4426c9604c48e0aa2ec0b11.zip | |
Auto merge of #58425 - wesleywiser:more_profiler_changes, r=michaelwoerister
[self-profiler] Make the profiler faster/more efficient Related to #58372 r? @michaelwoerister
Diffstat (limited to 'src/librustc_codegen_ssa')
| -rw-r--r-- | src/librustc_codegen_ssa/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/back/write.rs | 24 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/lib.rs | 3 |
3 files changed, 28 insertions, 0 deletions
diff --git a/src/librustc_codegen_ssa/Cargo.toml b/src/librustc_codegen_ssa/Cargo.toml index 0aba43580f1..4702e34aa19 100644 --- a/src/librustc_codegen_ssa/Cargo.toml +++ b/src/librustc_codegen_ssa/Cargo.toml @@ -19,6 +19,7 @@ memmap = "0.6" log = "0.4.5" libc = "0.2.44" jobserver = "0.1.11" +parking_lot = "0.7" serialize = { path = "../libserialize" } syntax = { path = "../libsyntax" } diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index 908ee95efcb..4bccc2a6d1f 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -19,6 +19,7 @@ use rustc::util::time_graph::{self, TimeGraph, Timeline}; use rustc::hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc::ty::TyCtxt; use rustc::util::common::{time_depth, set_time_depth, print_time_passes_entry}; +use rustc::util::profiling::SelfProfiler; use rustc_fs_util::link_or_copy; use rustc_data_structures::svh::Svh; use rustc_errors::{Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId}; @@ -29,6 +30,7 @@ use syntax::ext::hygiene::Mark; use syntax_pos::MultiSpan; use syntax_pos::symbol::Symbol; use jobserver::{Client, Acquired}; +use parking_lot::Mutex as PlMutex; use std::any::Any; use std::fs; @@ -201,6 +203,7 @@ pub struct CodegenContext<B: WriteBackendMethods> { // Resources needed when running LTO pub backend: B, pub time_passes: bool, + pub profiler: Option<Arc<PlMutex<SelfProfiler>>>, pub lto: Lto, pub no_landing_pads: bool, pub save_temps: bool, @@ -254,6 +257,26 @@ impl<B: WriteBackendMethods> CodegenContext<B> { ModuleKind::Allocator => &self.allocator_module_config, } } + + #[inline(never)] + #[cold] + fn profiler_active<F: FnOnce(&mut SelfProfiler) -> ()>(&self, f: F) { + match &self.profiler { + None => bug!("profiler_active() called but there was no profiler active"), + Some(profiler) => { + let mut p = profiler.lock(); + + f(&mut p); + } + } + } + + #[inline(always)] + pub fn profile<F: FnOnce(&mut SelfProfiler) -> ()>(&self, f: F) { + if unlikely!(self.profiler.is_some()) { + self.profiler_active(f) + } + } } fn generate_lto_work<B: ExtraBackendMethods>( @@ -1033,6 +1056,7 @@ fn start_executing_work<B: ExtraBackendMethods>( save_temps: sess.opts.cg.save_temps, opts: Arc::new(sess.opts.clone()), time_passes: sess.time_passes(), + profiler: sess.self_profiling.clone(), exported_symbols, plugin_passes: sess.plugin_llvm_passes.borrow().clone(), remark: sess.opts.cg.remark.clone(), diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index f38b22aa041..fec41936a23 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -2,9 +2,11 @@ #![feature(box_patterns)] #![feature(box_syntax)] +#![feature(core_intrinsics)] #![feature(custom_attribute)] #![feature(libc)] #![feature(rustc_diagnostic_macros)] +#![feature(stmt_expr_attributes)] #![feature(in_band_lifetimes)] #![feature(nll)] #![allow(unused_attributes)] @@ -20,6 +22,7 @@ #[macro_use] extern crate log; #[macro_use] extern crate rustc; +#[macro_use] extern crate rustc_data_structures; #[macro_use] extern crate syntax; use std::path::PathBuf; |
