Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,19 @@ impl<'tcx> CodegenUnit<'tcx> {
base_n::encode(hash, base_n::CASE_INSENSITIVE)
}

pub fn estimate_size(&mut self, tcx: TyCtxt<'tcx>) {
pub fn create_size_estimate(&mut self, tcx: TyCtxt<'tcx>) {
// Estimate the size of a codegen unit as (approximately) the number of MIR
// statements it corresponds to.
self.size_estimate = Some(self.items.keys().map(|mi| mi.size_estimate(tcx)).sum());
}

#[inline]
/// Should only be called if [`create_size_estimate`] has previously been called.
///
/// [`create_size_estimate`]: Self::create_size_estimate
pub fn size_estimate(&self) -> usize {
// Should only be called if `estimate_size` has previously been called.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to a doc comment on the method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mejrs I done it

self.size_estimate.expect("estimate_size must be called before getting a size_estimate")
self.size_estimate
.expect("create_size_estimate must be called before getting a size_estimate")
}

pub fn modify_size_estimate(&mut self, delta: usize) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_monomorphize/src/partitioning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub fn partition<'tcx>(
partitioner.place_root_mono_items(cx, mono_items)
};

initial_partitioning.codegen_units.iter_mut().for_each(|cgu| cgu.estimate_size(tcx));
initial_partitioning.codegen_units.iter_mut().for_each(|cgu| cgu.create_size_estimate(tcx));

debug_dump(tcx, "INITIAL PARTITIONING:", initial_partitioning.codegen_units.iter());

Expand All @@ -200,7 +200,7 @@ pub fn partition<'tcx>(
partitioner.place_inlined_mono_items(cx, initial_partitioning)
};

post_inlining.codegen_units.iter_mut().for_each(|cgu| cgu.estimate_size(tcx));
post_inlining.codegen_units.iter_mut().for_each(|cgu| cgu.create_size_estimate(tcx));

debug_dump(tcx, "POST INLINING:", post_inlining.codegen_units.iter());

Expand Down