mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Rollup merge of #113390 - nnethercote:cgu-tweaks, r=wesleywiser
CGU formation tweaks Minor improvements I found while trying out something bigger that didn't work out. r? ``@wesleywiser``
This commit is contained in:
commit
d5b1ef98b0
@ -231,8 +231,8 @@ impl<'tcx> UsageMap<'tcx> {
|
|||||||
assert!(self.used_map.insert(user_item, used_items).is_none());
|
assert!(self.used_map.insert(user_item, used_items).is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_user_items(&self, item: MonoItem<'tcx>) -> Option<&[MonoItem<'tcx>]> {
|
pub fn get_user_items(&self, item: MonoItem<'tcx>) -> &[MonoItem<'tcx>] {
|
||||||
self.user_map.get(&item).map(|items| items.as_slice())
|
self.user_map.get(&item).map(|items| items.as_slice()).unwrap_or(&[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Internally iterate over all inlined items used by `item`.
|
/// Internally iterate over all inlined items used by `item`.
|
||||||
|
@ -427,9 +427,9 @@ fn merge_codegen_units<'tcx>(
|
|||||||
// zero-padded suffixes, which means they are automatically sorted by
|
// zero-padded suffixes, which means they are automatically sorted by
|
||||||
// names. The numeric suffix width depends on the number of CGUs, which
|
// names. The numeric suffix width depends on the number of CGUs, which
|
||||||
// is always greater than zero:
|
// is always greater than zero:
|
||||||
// - [1,9] CGUS: `0`, `1`, `2`, ...
|
// - [1,9] CGUs: `0`, `1`, `2`, ...
|
||||||
// - [10,99] CGUS: `00`, `01`, `02`, ...
|
// - [10,99] CGUs: `00`, `01`, `02`, ...
|
||||||
// - [100,999] CGUS: `000`, `001`, `002`, ...
|
// - [100,999] CGUs: `000`, `001`, `002`, ...
|
||||||
// - etc.
|
// - etc.
|
||||||
//
|
//
|
||||||
// If we didn't zero-pad the sorted-by-name order would be `XYZ-cgu.0`,
|
// If we didn't zero-pad the sorted-by-name order would be `XYZ-cgu.0`,
|
||||||
@ -458,7 +458,7 @@ fn internalize_symbols<'tcx>(
|
|||||||
/// used to keep track of that.
|
/// used to keep track of that.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
enum MonoItemPlacement {
|
enum MonoItemPlacement {
|
||||||
SingleCgu { cgu_name: Symbol },
|
SingleCgu(Symbol),
|
||||||
MultipleCgus,
|
MultipleCgus,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,7 +466,7 @@ fn internalize_symbols<'tcx>(
|
|||||||
let single_codegen_unit = codegen_units.len() == 1;
|
let single_codegen_unit = codegen_units.len() == 1;
|
||||||
|
|
||||||
if !single_codegen_unit {
|
if !single_codegen_unit {
|
||||||
for cgu in codegen_units.iter_mut() {
|
for cgu in codegen_units.iter() {
|
||||||
for item in cgu.items().keys() {
|
for item in cgu.items().keys() {
|
||||||
// If there is more than one codegen unit, we need to keep track
|
// If there is more than one codegen unit, we need to keep track
|
||||||
// in which codegen units each monomorphization is placed.
|
// in which codegen units each monomorphization is placed.
|
||||||
@ -474,13 +474,13 @@ fn internalize_symbols<'tcx>(
|
|||||||
Entry::Occupied(e) => {
|
Entry::Occupied(e) => {
|
||||||
let placement = e.into_mut();
|
let placement = e.into_mut();
|
||||||
debug_assert!(match *placement {
|
debug_assert!(match *placement {
|
||||||
MonoItemPlacement::SingleCgu { cgu_name } => cgu_name != cgu.name(),
|
MonoItemPlacement::SingleCgu(cgu_name) => cgu_name != cgu.name(),
|
||||||
MonoItemPlacement::MultipleCgus => true,
|
MonoItemPlacement::MultipleCgus => true,
|
||||||
});
|
});
|
||||||
*placement = MonoItemPlacement::MultipleCgus;
|
*placement = MonoItemPlacement::MultipleCgus;
|
||||||
}
|
}
|
||||||
Entry::Vacant(e) => {
|
Entry::Vacant(e) => {
|
||||||
e.insert(MonoItemPlacement::SingleCgu { cgu_name: cgu.name() });
|
e.insert(MonoItemPlacement::SingleCgu(cgu.name()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -490,7 +490,7 @@ fn internalize_symbols<'tcx>(
|
|||||||
// For each internalization candidates in each codegen unit, check if it is
|
// For each internalization candidates in each codegen unit, check if it is
|
||||||
// used from outside its defining codegen unit.
|
// used from outside its defining codegen unit.
|
||||||
for cgu in codegen_units {
|
for cgu in codegen_units {
|
||||||
let home_cgu = MonoItemPlacement::SingleCgu { cgu_name: cgu.name() };
|
let home_cgu = MonoItemPlacement::SingleCgu(cgu.name());
|
||||||
|
|
||||||
for (item, linkage_and_visibility) in cgu.items_mut() {
|
for (item, linkage_and_visibility) in cgu.items_mut() {
|
||||||
if !internalization_candidates.contains(item) {
|
if !internalization_candidates.contains(item) {
|
||||||
@ -501,20 +501,20 @@ fn internalize_symbols<'tcx>(
|
|||||||
if !single_codegen_unit {
|
if !single_codegen_unit {
|
||||||
debug_assert_eq!(mono_item_placements[item], home_cgu);
|
debug_assert_eq!(mono_item_placements[item], home_cgu);
|
||||||
|
|
||||||
if let Some(user_items) = cx.usage_map.get_user_items(*item) {
|
if cx
|
||||||
if user_items
|
.usage_map
|
||||||
.iter()
|
.get_user_items(*item)
|
||||||
.filter_map(|user_item| {
|
.iter()
|
||||||
// Some user mono items might not have been
|
.filter_map(|user_item| {
|
||||||
// instantiated. We can safely ignore those.
|
// Some user mono items might not have been
|
||||||
mono_item_placements.get(user_item)
|
// instantiated. We can safely ignore those.
|
||||||
})
|
mono_item_placements.get(user_item)
|
||||||
.any(|placement| *placement != home_cgu)
|
})
|
||||||
{
|
.any(|placement| *placement != home_cgu)
|
||||||
// Found a user from another CGU, so skip to the next item
|
{
|
||||||
// without marking this one as internal.
|
// Found a user from another CGU, so skip to the next item
|
||||||
continue;
|
// without marking this one as internal.
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user