Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d2ffe40

Browse files
committed
Cleanup -Ztime-passes output
1 parent a465d6a commit d2ffe40

File tree

5 files changed

+92
-94
lines changed

5 files changed

+92
-94
lines changed

src/base.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub(crate) fn codegen_fn<'tcx>(
9595
next_ssa_var: 0,
9696
};
9797

98-
tcx.sess.time("codegen clif ir", || codegen_fn_body(&mut fx, start_block));
98+
tcx.prof.generic_activity("codegen clif ir").run(|| codegen_fn_body(&mut fx, start_block));
9999
fx.bcx.seal_all_blocks();
100100
fx.bcx.finalize();
101101

@@ -174,7 +174,7 @@ pub(crate) fn compile_fn(
174174
};
175175

176176
// Define function
177-
cx.profiler.verbose_generic_activity("define function").run(|| {
177+
cx.profiler.generic_activity("define function").run(|| {
178178
context.want_disasm = cx.should_write_ir;
179179
module.define_function(codegened_func.func_id, context).unwrap();
180180
});
@@ -203,7 +203,7 @@ pub(crate) fn compile_fn(
203203
let isa = module.isa();
204204
let debug_context = &mut cx.debug_context;
205205
let unwind_context = &mut cx.unwind_context;
206-
cx.profiler.verbose_generic_activity("generate debug info").run(|| {
206+
cx.profiler.generic_activity("generate debug info").run(|| {
207207
if let Some(debug_context) = debug_context {
208208
codegened_func.func_debug_cx.unwrap().finalize(
209209
debug_context,
@@ -220,7 +220,7 @@ pub(crate) fn verify_func(
220220
writer: &crate::pretty_clif::CommentWriter,
221221
func: &Function,
222222
) {
223-
tcx.sess.time("verify clif ir", || {
223+
tcx.prof.generic_activity("verify clif ir").run(|| {
224224
let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder());
225225
match cranelift_codegen::verify_function(&func, &flags) {
226226
Ok(_) => {}
@@ -256,7 +256,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
256256
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
257257
return;
258258
}
259-
fx.tcx.sess.time("codegen prelude", || crate::abi::codegen_fn_prelude(fx, start_block));
259+
fx.tcx
260+
.prof
261+
.generic_activity("codegen prelude")
262+
.run(|| crate::abi::codegen_fn_prelude(fx, start_block));
260263

261264
for (bb, bb_data) in fx.mir.basic_blocks.iter_enumerated() {
262265
let block = fx.get_block(bb);
@@ -417,7 +420,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
417420
cleanup: _,
418421
from_hir_call: _,
419422
} => {
420-
fx.tcx.sess.time("codegen call", || {
423+
fx.tcx.prof.generic_activity("codegen call").run(|| {
421424
crate::abi::codegen_terminator_call(
422425
fx,
423426
mir::SourceInfo { span: *fn_span, ..source_info },

src/config.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ pub struct BackendConfig {
4242
/// Defaults to the value of `CG_CLIF_JIT_ARGS`.
4343
pub jit_args: Vec<String>,
4444

45-
/// Display the time it took to perform codegen for a crate.
46-
///
47-
/// Defaults to true when the `CG_CLIF_DISPLAY_CG_TIME` env var is set to 1 or false otherwise.
48-
/// Can be set using `-Cllvm-args=display_cg_time=...`.
49-
pub display_cg_time: bool,
50-
5145
/// Enable the Cranelift ir verifier for all compilation passes. If not set it will only run
5246
/// once before passing the clif ir to Cranelift for compilation.
5347
///
@@ -73,7 +67,6 @@ impl Default for BackendConfig {
7367
let args = std::env::var("CG_CLIF_JIT_ARGS").unwrap_or_else(|_| String::new());
7468
args.split(' ').map(|arg| arg.to_string()).collect()
7569
},
76-
display_cg_time: bool_env_var("CG_CLIF_DISPLAY_CG_TIME"),
7770
enable_verifier: cfg!(debug_assertions) || bool_env_var("CG_CLIF_ENABLE_VERIFIER"),
7871
disable_incr_cache: bool_env_var("CG_CLIF_DISABLE_INCR_CACHE"),
7972
}
@@ -92,7 +85,6 @@ impl BackendConfig {
9285
if let Some((name, value)) = opt.split_once('=') {
9386
match name {
9487
"mode" => config.codegen_mode = value.parse()?,
95-
"display_cg_time" => config.display_cg_time = parse_bool(name, value)?,
9688
"enable_verifier" => config.enable_verifier = parse_bool(name, value)?,
9789
"disable_incr_cache" => config.disable_incr_cache = parse_bool(name, value)?,
9890
_ => return Err(format!("Unknown option `{}`", name)),

src/driver/aot.rs

Lines changed: 80 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -272,80 +272,97 @@ fn module_codegen(
272272
ConcurrencyLimiterToken,
273273
),
274274
) -> OngoingModuleCodegen {
275-
let (cgu_name, mut cx, mut module, codegened_functions) = tcx.sess.time("codegen cgu", || {
276-
let cgu = tcx.codegen_unit(cgu_name);
277-
let mono_items = cgu.items_in_deterministic_order(tcx);
278-
279-
let mut module = make_module(tcx.sess, &backend_config, cgu_name.as_str().to_string());
280-
281-
let mut cx = crate::CodegenCx::new(
282-
tcx,
283-
backend_config.clone(),
284-
module.isa(),
285-
tcx.sess.opts.debuginfo != DebugInfo::None,
286-
cgu_name,
287-
);
288-
super::predefine_mono_items(tcx, &mut module, &mono_items);
289-
let mut codegened_functions = vec![];
290-
for (mono_item, _) in mono_items {
291-
match mono_item {
292-
MonoItem::Fn(inst) => {
293-
tcx.sess.time("codegen fn", || {
294-
let codegened_function = crate::base::codegen_fn(
275+
let (cgu_name, mut cx, mut module, codegened_functions) =
276+
tcx.prof.verbose_generic_activity_with_arg("codegen cgu", cgu_name.as_str()).run(|| {
277+
let cgu = tcx.codegen_unit(cgu_name);
278+
let mono_items = cgu.items_in_deterministic_order(tcx);
279+
280+
let mut module = make_module(tcx.sess, &backend_config, cgu_name.as_str().to_string());
281+
282+
let mut cx = crate::CodegenCx::new(
283+
tcx,
284+
backend_config.clone(),
285+
module.isa(),
286+
tcx.sess.opts.debuginfo != DebugInfo::None,
287+
cgu_name,
288+
);
289+
super::predefine_mono_items(tcx, &mut module, &mono_items);
290+
let mut codegened_functions = vec![];
291+
for (mono_item, _) in mono_items {
292+
match mono_item {
293+
MonoItem::Fn(inst) => {
294+
tcx.prof.generic_activity("codegen fn").run(|| {
295+
let codegened_function = crate::base::codegen_fn(
296+
tcx,
297+
&mut cx,
298+
Function::new(),
299+
&mut module,
300+
inst,
301+
);
302+
codegened_functions.push(codegened_function);
303+
});
304+
}
305+
MonoItem::Static(def_id) => {
306+
crate::constant::codegen_static(tcx, &mut module, def_id)
307+
}
308+
MonoItem::GlobalAsm(item_id) => {
309+
crate::global_asm::codegen_global_asm_item(
295310
tcx,
296-
&mut cx,
297-
Function::new(),
298-
&mut module,
299-
inst,
311+
&mut cx.global_asm,
312+
item_id,
300313
);
301-
codegened_functions.push(codegened_function);
302-
});
303-
}
304-
MonoItem::Static(def_id) => {
305-
crate::constant::codegen_static(tcx, &mut module, def_id)
306-
}
307-
MonoItem::GlobalAsm(item_id) => {
308-
crate::global_asm::codegen_global_asm_item(tcx, &mut cx.global_asm, item_id);
314+
}
309315
}
310316
}
311-
}
312-
crate::main_shim::maybe_create_entry_wrapper(
313-
tcx,
314-
&mut module,
315-
&mut cx.unwind_context,
316-
false,
317-
cgu.is_primary(),
318-
);
317+
crate::main_shim::maybe_create_entry_wrapper(
318+
tcx,
319+
&mut module,
320+
&mut cx.unwind_context,
321+
false,
322+
cgu.is_primary(),
323+
);
319324

320-
let cgu_name = cgu.name().as_str().to_owned();
325+
let cgu_name = cgu.name().as_str().to_owned();
321326

322-
(cgu_name, cx, module, codegened_functions)
323-
});
327+
(cgu_name, cx, module, codegened_functions)
328+
});
324329

325330
OngoingModuleCodegen::Async(std::thread::spawn(move || {
326-
cx.profiler.clone().verbose_generic_activity("compile functions").run(|| {
327-
let mut cached_context = Context::new();
328-
for codegened_func in codegened_functions {
329-
crate::base::compile_fn(&mut cx, &mut cached_context, &mut module, codegened_func);
330-
}
331-
});
331+
cx.profiler.clone().verbose_generic_activity_with_arg("compile functions", &*cgu_name).run(
332+
|| {
333+
let mut cached_context = Context::new();
334+
for codegened_func in codegened_functions {
335+
crate::base::compile_fn(
336+
&mut cx,
337+
&mut cached_context,
338+
&mut module,
339+
codegened_func,
340+
);
341+
}
342+
},
343+
);
332344

333-
let global_asm_object_file =
334-
cx.profiler.verbose_generic_activity("compile assembly").run(|| {
345+
let global_asm_object_file = cx
346+
.profiler
347+
.verbose_generic_activity_with_arg("compile assembly", &*cgu_name)
348+
.run(|| {
335349
crate::global_asm::compile_global_asm(&global_asm_config, &cgu_name, &cx.global_asm)
336350
})?;
337351

338-
let codegen_result = cx.profiler.verbose_generic_activity("write object file").run(|| {
339-
emit_cgu(
340-
&global_asm_config.output_filenames,
341-
&cx.profiler,
342-
cgu_name,
343-
module,
344-
cx.debug_context,
345-
cx.unwind_context,
346-
global_asm_object_file,
347-
)
348-
});
352+
let codegen_result = cx
353+
.profiler
354+
.verbose_generic_activity_with_arg("write object file", &*cgu_name)
355+
.run(|| {
356+
emit_cgu(
357+
&global_asm_config.output_filenames,
358+
&cx.profiler,
359+
cgu_name,
360+
module,
361+
cx.debug_context,
362+
cx.unwind_context,
363+
global_asm_object_file,
364+
)
365+
});
349366
std::mem::drop(token);
350367
codegen_result
351368
}))
@@ -375,7 +392,7 @@ pub(crate) fn run_aot(
375392

376393
let mut concurrency_limiter = ConcurrencyLimiter::new(tcx.sess, cgus.len());
377394

378-
let modules = super::time(tcx, backend_config.display_cg_time, "codegen mono items", || {
395+
let modules = tcx.sess.time("codegen mono items", || {
379396
cgus.iter()
380397
.map(|cgu| {
381398
let cgu_reuse = if backend_config.disable_incr_cache {
@@ -437,7 +454,6 @@ pub(crate) fn run_aot(
437454
};
438455

439456
let metadata_module = if need_metadata_module {
440-
let _timer = tcx.prof.generic_activity("codegen crate metadata");
441457
let (metadata_cgu_name, tmp_file) = tcx.sess.time("write compressed metadata", || {
442458
use rustc_middle::mir::mono::CodegenUnitNameBuilder;
443459

src/driver/jit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
121121
.into_iter()
122122
.collect::<Vec<(_, (_, _))>>();
123123

124-
super::time(tcx, backend_config.display_cg_time, "codegen mono items", || {
124+
tcx.sess.time("codegen mono items", || {
125125
super::predefine_mono_items(tcx, &mut jit_module, &mono_items);
126126
for (mono_item, _) in mono_items {
127127
match mono_item {
@@ -224,7 +224,7 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
224224
module: &mut dyn Module,
225225
instance: Instance<'tcx>,
226226
) {
227-
tcx.sess.time("codegen and compile fn", || {
227+
tcx.prof.generic_activity("codegen and compile fn").run(|| {
228228
let _inst_guard =
229229
crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name));
230230

src/driver/mod.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn predefine_mono_items<'tcx>(
1717
module: &mut dyn Module,
1818
mono_items: &[(MonoItem<'tcx>, (RLinkage, Visibility))],
1919
) {
20-
tcx.sess.time("predefine functions", || {
20+
tcx.prof.generic_activity("predefine functions").run(|| {
2121
let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
2222
for &(mono_item, (linkage, visibility)) in mono_items {
2323
match mono_item {
@@ -39,16 +39,3 @@ fn predefine_mono_items<'tcx>(
3939
}
4040
});
4141
}
42-
43-
fn time<R>(tcx: TyCtxt<'_>, display: bool, name: &'static str, f: impl FnOnce() -> R) -> R {
44-
if display {
45-
println!("[{:<30}: {}] start", tcx.crate_name(LOCAL_CRATE), name);
46-
let before = std::time::Instant::now();
47-
let res = tcx.sess.time(name, f);
48-
let after = std::time::Instant::now();
49-
println!("[{:<30}: {}] end time: {:?}", tcx.crate_name(LOCAL_CRATE), name, after - before);
50-
res
51-
} else {
52-
tcx.sess.time(name, f)
53-
}
54-
}

0 commit comments

Comments
 (0)