Skip to content

Commit 5d06126

Browse files
committed
XXX: inline before merge (including increase to 1500)
XXX: split out comment changes in a precursor, eventually
1 parent 3e12706 commit 5d06126

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,6 @@ impl<'tcx> CodegenUnit<'tcx> {
335335
.expect("create_size_estimate must be called before getting a size_estimate")
336336
}
337337

338-
pub fn modify_size_estimate(&mut self, delta: usize) {
339-
*self.size_estimate.as_mut().unwrap() += delta;
340-
}
341-
342338
pub fn contains_item(&self, item: &MonoItem<'tcx>) -> bool {
343339
self.items().contains_key(item)
344340
}

compiler/rustc_monomorphize/src/partitioning.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,9 @@ where
166166
placed
167167
};
168168

169-
// Merge until we have at most `max_cgu_count` codegen units.
170-
// `merge_codegen_units` is responsible for updating the CGU size
171-
// estimates.
172-
{
173-
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_merge_cgus");
174-
merge_codegen_units(cx, &mut codegen_units);
175-
debug_dump(tcx, "MERGE", &codegen_units, unique_inlined_stats);
176-
}
177-
178-
// In the next step, we use the inlining map to determine which additional
179-
// monomorphizations have to go into each codegen unit. These additional
180-
// monomorphizations can be drop-glue, functions from external crates, and
181-
// local functions the definition of which is marked with `#[inline]`.
169+
// Use the usage map to put additional mono items in each codegen unit:
170+
// drop-glue, functions from external crates, and local functions the
171+
// definition of which is marked with `#[inline]`.
182172
{
183173
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_inline_items");
184174
place_inlined_mono_items(cx, &mut codegen_units);
@@ -190,8 +180,17 @@ where
190180
debug_dump(tcx, "INLINE", &codegen_units, unique_inlined_stats);
191181
}
192182

193-
// Next we try to make as many symbols "internal" as possible, so LLVM has
194-
// more freedom to optimize.
183+
// Merge until we have at most `max_cgu_count` codegen units.
184+
// `merge_codegen_units` is responsible for updating the CGU size
185+
// estimates.
186+
{
187+
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_merge_cgus");
188+
merge_codegen_units(cx, &mut codegen_units);
189+
debug_dump(tcx, "MERGE", &codegen_units, unique_inlined_stats);
190+
}
191+
192+
// Make as many symbols "internal" as possible, so LLVM has more freedom to
193+
// optimize.
195194
if !tcx.sess.link_dead_code() {
196195
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
197196
internalize_symbols(cx, &mut codegen_units, internalization_candidates);
@@ -314,7 +313,7 @@ fn merge_codegen_units<'tcx>(
314313
// worse generated code. So we don't allow CGUs smaller than this (unless
315314
// there is just one CGU, of course). Note that CGU sizes of 100,000+ are
316315
// common in larger programs, so this isn't all that large.
317-
const NON_INCR_MIN_CGU_SIZE: usize = 1000;
316+
const NON_INCR_MIN_CGU_SIZE: usize = 1500;
318317

319318
// Repeatedly merge the two smallest codegen units as long as:
320319
// - we have more CGUs than the upper limit, or
@@ -338,9 +337,11 @@ fn merge_codegen_units<'tcx>(
338337
let mut smallest = codegen_units.pop().unwrap();
339338
let second_smallest = codegen_units.last_mut().unwrap();
340339

341-
// Move the mono-items from `smallest` to `second_smallest`
342-
second_smallest.modify_size_estimate(smallest.size_estimate());
340+
// Move the items from `smallest` to `second_smallest`. Some of them
341+
// may be duplicate inlined items, in which case the destination CGU is
342+
// unaffected. Recalculate size estimates afterwards.
343343
second_smallest.items_mut().extend(smallest.items_mut().drain());
344+
second_smallest.create_size_estimate(cx.tcx);
344345

345346
// Record that `second_smallest` now contains all the stuff that was
346347
// in `smallest` before.

0 commit comments

Comments
 (0)