Skip to content

Commit cd64248

Browse files
Rollup merge of #111743 - nnethercote:improve-cgu-merging-debug-output, r=lqd
Improve cgu merging debug output r? ``@lqd``
2 parents 61e1b0a + 1bb957e commit cd64248

File tree

1 file changed

+18
-12
lines changed
  • compiler/rustc_monomorphize/src/partitioning

1 file changed

+18
-12
lines changed

compiler/rustc_monomorphize/src/partitioning/mod.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ where
250250
cgu.create_size_estimate(tcx);
251251
}
252252

253-
debug_dump(tcx, "INITIAL PARTITIONING:", initial_partitioning.codegen_units.iter());
253+
debug_dump(tcx, "INITIAL PARTITIONING", &initial_partitioning.codegen_units);
254254

255255
// Merge until we have at most `max_cgu_count` codegen units.
256256
{
257257
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_merge_cgus");
258258
partitioner.merge_codegen_units(cx, &mut initial_partitioning);
259-
debug_dump(tcx, "POST MERGING:", initial_partitioning.codegen_units.iter());
259+
debug_dump(tcx, "POST MERGING", &initial_partitioning.codegen_units);
260260
}
261261

262262
// In the next step, we use the inlining map to determine which additional
@@ -272,7 +272,7 @@ where
272272
cgu.create_size_estimate(tcx);
273273
}
274274

275-
debug_dump(tcx, "POST INLINING:", post_inlining.codegen_units.iter());
275+
debug_dump(tcx, "POST INLINING", &post_inlining.codegen_units);
276276

277277
// Next we try to make as many symbols "internal" as possible, so LLVM has
278278
// more freedom to optimize.
@@ -322,6 +322,8 @@ where
322322

323323
result.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));
324324

325+
debug_dump(tcx, "FINAL", &result);
326+
325327
result
326328
}
327329

@@ -346,33 +348,37 @@ struct PostInliningPartitioning<'tcx> {
346348
internalization_candidates: FxHashSet<MonoItem<'tcx>>,
347349
}
348350

349-
fn debug_dump<'a, 'tcx, I>(tcx: TyCtxt<'tcx>, label: &str, cgus: I)
350-
where
351-
I: Iterator<Item = &'a CodegenUnit<'tcx>>,
352-
'tcx: 'a,
353-
{
351+
fn debug_dump<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx>, label: &str, cgus: &[CodegenUnit<'tcx>]) {
354352
let dump = move || {
355353
use std::fmt::Write;
356354

355+
let num_cgus = cgus.len();
356+
let max = cgus.iter().map(|cgu| cgu.size_estimate()).max().unwrap();
357+
let min = cgus.iter().map(|cgu| cgu.size_estimate()).min().unwrap();
358+
let ratio = max as f64 / min as f64;
359+
357360
let s = &mut String::new();
358-
let _ = writeln!(s, "{label}");
361+
let _ = writeln!(
362+
s,
363+
"{label} ({num_cgus} CodegenUnits, max={max}, min={min}, max/min={ratio:.1}):"
364+
);
359365
for cgu in cgus {
360366
let _ =
361-
writeln!(s, "CodegenUnit {} estimated size {} :", cgu.name(), cgu.size_estimate());
367+
writeln!(s, "CodegenUnit {} estimated size {}:", cgu.name(), cgu.size_estimate());
362368

363369
for (mono_item, linkage) in cgu.items() {
364370
let symbol_name = mono_item.symbol_name(tcx).name;
365371
let symbol_hash_start = symbol_name.rfind('h');
366372
let symbol_hash = symbol_hash_start.map_or("<no hash>", |i| &symbol_name[i..]);
367373

368-
let _ = writeln!(
374+
let _ = with_no_trimmed_paths!(writeln!(
369375
s,
370376
" - {} [{:?}] [{}] estimated size {}",
371377
mono_item,
372378
linkage,
373379
symbol_hash,
374380
mono_item.size_estimate(tcx)
375-
);
381+
));
376382
}
377383

378384
let _ = writeln!(s);

0 commit comments

Comments
 (0)