-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CGU cleanups #111899
Merged
Merged
CGU cleanups #111899
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e26c0c9
Inline and remove `numbered_codegen_unit_name`.
nnethercote b39b709
Remove the `merging` module.
nnethercote 20de2ba
Remove `{Pre,Post}InliningPartitioning`.
nnethercote 59c5259
Add a clarifying comment.
nnethercote 86754cd
Remove some unnecessary `pub` markers.
nnethercote ed216e2
Streamline `modify_size_estimate`.
nnethercote e6b99a6
Add struct for the return type of `place_root_mono_items`.
nnethercote File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,7 @@ use rustc_span::symbol::Symbol; | |
|
||
use super::PartitioningCx; | ||
use crate::collector::InliningMap; | ||
use crate::partitioning::{ | ||
MonoItemPlacement, Partition, PostInliningPartitioning, PreInliningPartitioning, | ||
}; | ||
use crate::partitioning::{MonoItemPlacement, Partition}; | ||
|
||
pub struct DefaultPartitioning; | ||
|
||
|
@@ -26,7 +24,7 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning { | |
&mut self, | ||
cx: &PartitioningCx<'_, 'tcx>, | ||
mono_items: &mut I, | ||
) -> PreInliningPartitioning<'tcx> | ||
) -> (Vec<CodegenUnit<'tcx>>, FxHashSet<MonoItem<'tcx>>, FxHashSet<MonoItem<'tcx>>) | ||
where | ||
I: Iterator<Item = MonoItem<'tcx>>, | ||
{ | ||
|
@@ -91,20 +89,15 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning { | |
codegen_units.insert(codegen_unit_name, CodegenUnit::new(codegen_unit_name)); | ||
} | ||
|
||
PreInliningPartitioning { | ||
codegen_units: codegen_units.into_values().collect(), | ||
roots, | ||
internalization_candidates, | ||
} | ||
(codegen_units.into_values().collect(), roots, internalization_candidates) | ||
} | ||
|
||
fn merge_codegen_units( | ||
&mut self, | ||
cx: &PartitioningCx<'_, 'tcx>, | ||
initial_partitioning: &mut PreInliningPartitioning<'tcx>, | ||
codegen_units: &mut Vec<CodegenUnit<'tcx>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing the structs in argument position is nice because there are still names attached to it |
||
) { | ||
assert!(cx.target_cgu_count >= 1); | ||
let codegen_units = &mut initial_partitioning.codegen_units; | ||
|
||
// Note that at this point in time the `codegen_units` here may not be | ||
// in a deterministic order (but we know they're deterministically the | ||
|
@@ -201,20 +194,14 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning { | |
fn place_inlined_mono_items( | ||
&mut self, | ||
cx: &PartitioningCx<'_, 'tcx>, | ||
initial_partitioning: PreInliningPartitioning<'tcx>, | ||
) -> PostInliningPartitioning<'tcx> { | ||
let mut new_partitioning = Vec::new(); | ||
codegen_units: &mut [CodegenUnit<'tcx>], | ||
roots: FxHashSet<MonoItem<'tcx>>, | ||
) -> FxHashMap<MonoItem<'tcx>, MonoItemPlacement> { | ||
let mut mono_item_placements = FxHashMap::default(); | ||
|
||
let PreInliningPartitioning { | ||
codegen_units: initial_cgus, | ||
roots, | ||
internalization_candidates, | ||
} = initial_partitioning; | ||
|
||
let single_codegen_unit = initial_cgus.len() == 1; | ||
let single_codegen_unit = codegen_units.len() == 1; | ||
|
||
for old_codegen_unit in initial_cgus { | ||
for old_codegen_unit in codegen_units.iter_mut() { | ||
// Collect all items that need to be available in this codegen unit. | ||
let mut reachable = FxHashSet::default(); | ||
for root in old_codegen_unit.items().keys() { | ||
|
@@ -266,14 +253,10 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning { | |
} | ||
} | ||
|
||
new_partitioning.push(new_codegen_unit); | ||
*old_codegen_unit = new_codegen_unit; | ||
} | ||
|
||
return PostInliningPartitioning { | ||
codegen_units: new_partitioning, | ||
mono_item_placements, | ||
internalization_candidates, | ||
}; | ||
return mono_item_placements; | ||
|
||
fn follow_inlining<'tcx>( | ||
mono_item: MonoItem<'tcx>, | ||
|
@@ -293,14 +276,16 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning { | |
fn internalize_symbols( | ||
&mut self, | ||
cx: &PartitioningCx<'_, 'tcx>, | ||
partitioning: &mut PostInliningPartitioning<'tcx>, | ||
codegen_units: &mut [CodegenUnit<'tcx>], | ||
mono_item_placements: FxHashMap<MonoItem<'tcx>, MonoItemPlacement>, | ||
internalization_candidates: FxHashSet<MonoItem<'tcx>>, | ||
) { | ||
if partitioning.codegen_units.len() == 1 { | ||
if codegen_units.len() == 1 { | ||
// Fast path for when there is only one codegen unit. In this case we | ||
// can internalize all candidates, since there is nowhere else they | ||
// could be accessed from. | ||
for cgu in &mut partitioning.codegen_units { | ||
for candidate in &partitioning.internalization_candidates { | ||
for cgu in codegen_units { | ||
for candidate in &internalization_candidates { | ||
cgu.items_mut().insert(*candidate, (Linkage::Internal, Visibility::Default)); | ||
} | ||
} | ||
|
@@ -317,15 +302,13 @@ impl<'tcx> Partition<'tcx> for DefaultPartitioning { | |
} | ||
}); | ||
|
||
let mono_item_placements = &partitioning.mono_item_placements; | ||
|
||
// For each internalization candidates in each codegen unit, check if it is | ||
// accessed from outside its defining codegen unit. | ||
for cgu in &mut partitioning.codegen_units { | ||
for cgu in codegen_units { | ||
let home_cgu = MonoItemPlacement::SingleCgu { cgu_name: cgu.name() }; | ||
|
||
for (accessee, linkage_and_visibility) in cgu.items_mut() { | ||
if !partitioning.internalization_candidates.contains(accessee) { | ||
if !internalization_candidates.contains(accessee) { | ||
// This item is no candidate for internalizing, so skip it. | ||
continue; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning a tuple of two values with the same type is a little confusing, I'd prefer seeing the struct here.