Ignore unreachable inlined items in debug_dump
.
They're quite rare, and ignoring them simplifies things quite a bit, and further reduces the number of calls to `MonoItem::size_estimate` to the number of placed items (one per root item, and one or more per reachable inlined item).
This commit is contained in:
parent
edd1f3827e
commit
87c509da95
1 changed files with 18 additions and 30 deletions
|
@ -131,11 +131,6 @@ struct PlacedMonoItems<'tcx> {
|
||||||
codegen_units: Vec<CodegenUnit<'tcx>>,
|
codegen_units: Vec<CodegenUnit<'tcx>>,
|
||||||
|
|
||||||
internalization_candidates: FxHashSet<MonoItem<'tcx>>,
|
internalization_candidates: FxHashSet<MonoItem<'tcx>>,
|
||||||
|
|
||||||
/// These must be obtained when the iterator in `partition` runs. They
|
|
||||||
/// can't be obtained later because some inlined functions might not be
|
|
||||||
/// reachable.
|
|
||||||
unique_inlined_stats: (usize, usize),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The output CGUs are sorted by name.
|
// The output CGUs are sorted by name.
|
||||||
|
@ -153,11 +148,11 @@ where
|
||||||
|
|
||||||
// Place all mono items into a codegen unit. `place_mono_items` is
|
// Place all mono items into a codegen unit. `place_mono_items` is
|
||||||
// responsible for initializing the CGU size estimates.
|
// responsible for initializing the CGU size estimates.
|
||||||
let PlacedMonoItems { mut codegen_units, internalization_candidates, unique_inlined_stats } = {
|
let PlacedMonoItems { mut codegen_units, internalization_candidates } = {
|
||||||
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_items");
|
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_items");
|
||||||
let placed = place_mono_items(cx, mono_items);
|
let placed = place_mono_items(cx, mono_items);
|
||||||
|
|
||||||
debug_dump(tcx, "PLACE", &placed.codegen_units, placed.unique_inlined_stats);
|
debug_dump(tcx, "PLACE", &placed.codegen_units);
|
||||||
|
|
||||||
placed
|
placed
|
||||||
};
|
};
|
||||||
|
@ -168,7 +163,7 @@ where
|
||||||
{
|
{
|
||||||
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_merge_cgus");
|
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_merge_cgus");
|
||||||
merge_codegen_units(cx, &mut codegen_units);
|
merge_codegen_units(cx, &mut codegen_units);
|
||||||
debug_dump(tcx, "MERGE", &codegen_units, unique_inlined_stats);
|
debug_dump(tcx, "MERGE", &codegen_units);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make as many symbols "internal" as possible, so LLVM has more freedom to
|
// Make as many symbols "internal" as possible, so LLVM has more freedom to
|
||||||
|
@ -177,7 +172,7 @@ where
|
||||||
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
|
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
|
||||||
internalize_symbols(cx, &mut codegen_units, internalization_candidates);
|
internalize_symbols(cx, &mut codegen_units, internalization_candidates);
|
||||||
|
|
||||||
debug_dump(tcx, "INTERNALIZE", &codegen_units, unique_inlined_stats);
|
debug_dump(tcx, "INTERNALIZE", &codegen_units);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark one CGU for dead code, if necessary.
|
// Mark one CGU for dead code, if necessary.
|
||||||
|
@ -217,19 +212,12 @@ where
|
||||||
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(cx.tcx);
|
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(cx.tcx);
|
||||||
let cgu_name_cache = &mut FxHashMap::default();
|
let cgu_name_cache = &mut FxHashMap::default();
|
||||||
|
|
||||||
let mut num_unique_inlined_items = 0;
|
|
||||||
let mut unique_inlined_items_size = 0;
|
|
||||||
for mono_item in mono_items {
|
for mono_item in mono_items {
|
||||||
// Handle only root items directly here. Inlined items are handled at
|
// Handle only root items directly here. Inlined items are handled at
|
||||||
// the bottom of the loop based on reachability.
|
// the bottom of the loop based on reachability.
|
||||||
let size_estimate = mono_item.size_estimate(cx.tcx);
|
|
||||||
match mono_item.instantiation_mode(cx.tcx) {
|
match mono_item.instantiation_mode(cx.tcx) {
|
||||||
InstantiationMode::GloballyShared { .. } => {}
|
InstantiationMode::GloballyShared { .. } => {}
|
||||||
InstantiationMode::LocalCopy => {
|
InstantiationMode::LocalCopy => continue,
|
||||||
num_unique_inlined_items += 1;
|
|
||||||
unique_inlined_items_size += size_estimate;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let characteristic_def_id = characteristic_def_id_of_mono_item(cx.tcx, mono_item);
|
let characteristic_def_id = characteristic_def_id_of_mono_item(cx.tcx, mono_item);
|
||||||
|
@ -258,6 +246,7 @@ where
|
||||||
if visibility == Visibility::Hidden && can_be_internalized {
|
if visibility == Visibility::Hidden && can_be_internalized {
|
||||||
internalization_candidates.insert(mono_item);
|
internalization_candidates.insert(mono_item);
|
||||||
}
|
}
|
||||||
|
let size_estimate = mono_item.size_estimate(cx.tcx);
|
||||||
|
|
||||||
cgu.items_mut().insert(mono_item, MonoItemData { linkage, visibility, size_estimate });
|
cgu.items_mut().insert(mono_item, MonoItemData { linkage, visibility, size_estimate });
|
||||||
|
|
||||||
|
@ -295,11 +284,7 @@ where
|
||||||
cgu.compute_size_estimate();
|
cgu.compute_size_estimate();
|
||||||
}
|
}
|
||||||
|
|
||||||
return PlacedMonoItems {
|
return PlacedMonoItems { codegen_units, internalization_candidates };
|
||||||
codegen_units,
|
|
||||||
internalization_candidates,
|
|
||||||
unique_inlined_stats: (num_unique_inlined_items, unique_inlined_items_size),
|
|
||||||
};
|
|
||||||
|
|
||||||
fn get_reachable_inlined_items<'tcx>(
|
fn get_reachable_inlined_items<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
@ -858,12 +843,7 @@ fn default_visibility(tcx: TyCtxt<'_>, id: DefId, is_generic: bool) -> Visibilit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_dump<'a, 'tcx: 'a>(
|
fn debug_dump<'a, 'tcx: 'a>(tcx: TyCtxt<'tcx>, label: &str, cgus: &[CodegenUnit<'tcx>]) {
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
label: &str,
|
|
||||||
cgus: &[CodegenUnit<'tcx>],
|
|
||||||
(unique_inlined_items, unique_inlined_size): (usize, usize),
|
|
||||||
) {
|
|
||||||
let dump = move || {
|
let dump = move || {
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
|
@ -872,13 +852,17 @@ fn debug_dump<'a, 'tcx: 'a>(
|
||||||
|
|
||||||
// Note: every unique root item is placed exactly once, so the number
|
// Note: every unique root item is placed exactly once, so the number
|
||||||
// of unique root items always equals the number of placed root items.
|
// of unique root items always equals the number of placed root items.
|
||||||
|
//
|
||||||
|
// Also, unreached inlined items won't be counted here. This is fine.
|
||||||
|
|
||||||
|
let mut inlined_items = FxHashSet::default();
|
||||||
|
|
||||||
let mut root_items = 0;
|
let mut root_items = 0;
|
||||||
// unique_inlined_items is passed in above.
|
let mut unique_inlined_items = 0;
|
||||||
let mut placed_inlined_items = 0;
|
let mut placed_inlined_items = 0;
|
||||||
|
|
||||||
let mut root_size = 0;
|
let mut root_size = 0;
|
||||||
// unique_inlined_size is passed in above.
|
let mut unique_inlined_size = 0;
|
||||||
let mut placed_inlined_size = 0;
|
let mut placed_inlined_size = 0;
|
||||||
|
|
||||||
for cgu in cgus.iter() {
|
for cgu in cgus.iter() {
|
||||||
|
@ -892,6 +876,10 @@ fn debug_dump<'a, 'tcx: 'a>(
|
||||||
root_size += data.size_estimate;
|
root_size += data.size_estimate;
|
||||||
}
|
}
|
||||||
InstantiationMode::LocalCopy => {
|
InstantiationMode::LocalCopy => {
|
||||||
|
if inlined_items.insert(item) {
|
||||||
|
unique_inlined_items += 1;
|
||||||
|
unique_inlined_size += data.size_estimate;
|
||||||
|
}
|
||||||
placed_inlined_items += 1;
|
placed_inlined_items += 1;
|
||||||
placed_inlined_size += data.size_estimate;
|
placed_inlined_size += data.size_estimate;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue