Skip to content

Commit 623a6da

Browse files
committed
Move SelfProfilerRef out of CodegenCx
1 parent 357deaa commit 623a6da

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

src/base.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
66
use cranelift_module::ModuleError;
77
use rustc_ast::InlineAsmOptions;
88
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
9+
use rustc_data_structures::profiling::SelfProfilerRef;
910
use rustc_index::IndexVec;
1011
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1112
use rustc_middle::mir::InlineAsmMacro;
@@ -170,12 +171,13 @@ pub(crate) fn codegen_fn<'tcx>(
170171

171172
pub(crate) fn compile_fn(
172173
cx: &mut crate::CodegenCx,
174+
profiler: &SelfProfilerRef,
173175
cached_context: &mut Context,
174176
module: &mut dyn Module,
175177
codegened_func: CodegenedFunction,
176178
) {
177179
let _timer =
178-
cx.profiler.generic_activity_with_arg("compile function", &*codegened_func.symbol_name);
180+
profiler.generic_activity_with_arg("compile function", &*codegened_func.symbol_name);
179181

180182
let clif_comments = codegened_func.clif_comments;
181183

@@ -213,7 +215,7 @@ pub(crate) fn compile_fn(
213215
};
214216

215217
// Define function
216-
cx.profiler.generic_activity("define function").run(|| {
218+
profiler.generic_activity("define function").run(|| {
217219
context.want_disasm = cx.should_write_ir;
218220
match module.define_function(codegened_func.func_id, context) {
219221
Ok(()) => {}
@@ -254,7 +256,7 @@ pub(crate) fn compile_fn(
254256

255257
// Define debuginfo for function
256258
let debug_context = &mut cx.debug_context;
257-
cx.profiler.generic_activity("generate debug info").run(|| {
259+
profiler.generic_activity("generate debug info").run(|| {
258260
if let Some(debug_context) = debug_context {
259261
codegened_func.func_debug_cx.unwrap().finalize(
260262
debug_context,

src/driver/aot.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,28 +548,36 @@ fn module_codegen(
548548

549549
let producer = crate::debuginfo::producer(tcx.sess);
550550

551+
let profiler = tcx.prof.clone();
552+
551553
OngoingModuleCodegen::Async(std::thread::spawn(move || {
552-
cx.profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| {
554+
profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| {
553555
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
554-
cx.profiler.clone(),
556+
profiler.clone(),
555557
)));
556558

557559
let mut cached_context = Context::new();
558560
for codegened_func in codegened_functions {
559-
crate::base::compile_fn(&mut cx, &mut cached_context, &mut module, codegened_func);
561+
crate::base::compile_fn(
562+
&mut cx,
563+
&profiler,
564+
&mut cached_context,
565+
&mut module,
566+
codegened_func,
567+
);
560568
}
561569
});
562570

563571
let global_asm_object_file =
564-
cx.profiler.generic_activity_with_arg("compile assembly", &*cgu_name).run(|| {
572+
profiler.generic_activity_with_arg("compile assembly", &*cgu_name).run(|| {
565573
crate::global_asm::compile_global_asm(&global_asm_config, &cgu_name, &cx.global_asm)
566574
})?;
567575

568576
let codegen_result =
569-
cx.profiler.generic_activity_with_arg("write object file", &*cgu_name).run(|| {
577+
profiler.generic_activity_with_arg("write object file", &*cgu_name).run(|| {
570578
emit_cgu(
571579
&global_asm_config.output_filenames,
572-
&cx.profiler,
580+
&profiler,
573581
cgu_name,
574582
module,
575583
cx.debug_context,

src/driver/jit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
204204
instance: Instance<'tcx>,
205205
) {
206206
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
207-
cx.profiler.clone(),
207+
tcx.prof.clone(),
208208
)));
209209

210210
tcx.prof.generic_activity("codegen and compile fn").run(|| {
@@ -220,7 +220,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
220220
module,
221221
instance,
222222
) {
223-
crate::base::compile_fn(cx, cached_context, module, codegened_func);
223+
crate::base::compile_fn(cx, &tcx.prof, cached_context, module, codegened_func);
224224
}
225225
});
226226
}

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ use cranelift_codegen::settings::{self, Configurable};
4242
use rustc_codegen_ssa::CodegenResults;
4343
use rustc_codegen_ssa::back::versioned_llvm_target;
4444
use rustc_codegen_ssa::traits::CodegenBackend;
45-
use rustc_data_structures::profiling::SelfProfilerRef;
4645
use rustc_metadata::EncodedMetadata;
4746
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
4847
use rustc_session::Session;
@@ -123,7 +122,6 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
123122
/// The codegen context holds any information shared between the codegen of individual functions
124123
/// inside a single codegen unit with the exception of the Cranelift [`Module`](cranelift_module::Module).
125124
struct CodegenCx {
126-
profiler: SelfProfilerRef,
127125
output_filenames: Arc<OutputFilenames>,
128126
should_write_ir: bool,
129127
global_asm: String,
@@ -142,7 +140,6 @@ impl CodegenCx {
142140
None
143141
};
144142
CodegenCx {
145-
profiler: tcx.prof.clone(),
146143
output_filenames: tcx.output_filenames(()).clone(),
147144
should_write_ir: crate::pretty_clif::should_write_ir(tcx),
148145
global_asm: String::new(),

0 commit comments

Comments
 (0)