diff --git a/src/base.rs b/src/base.rs index 6a276df40bac..a7c7f66e166b 100644 --- a/src/base.rs +++ b/src/base.rs @@ -36,7 +36,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>( let cached_func = std::mem::replace(&mut cached_context.func, Function::new()); let codegened_func = codegen_fn(tcx, cx, cached_func, module, instance); - compile_fn(tcx, cx, cached_context, module, codegened_func); + compile_fn(cx, cached_context, module, codegened_func); } fn codegen_fn<'tcx>( @@ -142,7 +142,6 @@ fn codegen_fn<'tcx>( } fn compile_fn<'tcx>( - tcx: TyCtxt<'tcx>, cx: &mut crate::CodegenCx<'tcx>, cached_context: &mut Context, module: &mut dyn Module, @@ -193,7 +192,7 @@ fn compile_fn<'tcx>( }; // Define function - tcx.sess.time("define function", || { + cx.profiler.verbose_generic_activity("define function").run(|| { context.want_disasm = cx.should_write_ir; module.define_function(codegened_func.func_id, context).unwrap(); }); @@ -222,7 +221,7 @@ fn compile_fn<'tcx>( let isa = module.isa(); let debug_context = &mut cx.debug_context; let unwind_context = &mut cx.unwind_context; - tcx.sess.time("generate debug info", || { + cx.profiler.verbose_generic_activity("generate debug info").run(|| { if let Some(debug_context) = debug_context { debug_context.define_function( codegened_func.instance, diff --git a/src/lib.rs b/src/lib.rs index 1e851e31ac30..f4ffbbcf86ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,6 +30,7 @@ use std::sync::Arc; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::CodegenResults; +use rustc_data_structures::profiling::SelfProfilerRef; use rustc_errors::ErrorGuaranteed; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; @@ -122,6 +123,7 @@ impl String> Drop for PrintOnPanic { /// The codegen context holds any information shared between the codegen of individual functions /// inside a single codegen unit with the exception of the Cranelift [`Module`](cranelift_module::Module). struct CodegenCx<'tcx> { + profiler: SelfProfilerRef, output_filenames: Arc, should_write_ir: bool, global_asm: String, @@ -149,6 +151,7 @@ impl<'tcx> CodegenCx<'tcx> { None }; CodegenCx { + profiler: tcx.prof.clone(), output_filenames: tcx.output_filenames(()).clone(), should_write_ir: crate::pretty_clif::should_write_ir(tcx), global_asm: String::new(),