@@ -166,19 +166,9 @@ where
166
166
placed
167
167
} ;
168
168
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]`.
182
172
{
183
173
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_place_inline_items" ) ;
184
174
place_inlined_mono_items ( cx, & mut codegen_units) ;
@@ -190,8 +180,17 @@ where
190
180
debug_dump ( tcx, "INLINE" , & codegen_units, unique_inlined_stats) ;
191
181
}
192
182
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.
195
194
if !tcx. sess . link_dead_code ( ) {
196
195
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_internalize_symbols" ) ;
197
196
internalize_symbols ( cx, & mut codegen_units, internalization_candidates) ;
@@ -314,7 +313,7 @@ fn merge_codegen_units<'tcx>(
314
313
// worse generated code. So we don't allow CGUs smaller than this (unless
315
314
// there is just one CGU, of course). Note that CGU sizes of 100,000+ are
316
315
// 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 ;
318
317
319
318
// Repeatedly merge the two smallest codegen units as long as:
320
319
// - we have more CGUs than the upper limit, or
@@ -338,9 +337,11 @@ fn merge_codegen_units<'tcx>(
338
337
let mut smallest = codegen_units. pop ( ) . unwrap ( ) ;
339
338
let second_smallest = codegen_units. last_mut ( ) . unwrap ( ) ;
340
339
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.
343
343
second_smallest. items_mut ( ) . extend ( smallest. items_mut ( ) . drain ( ) ) ;
344
+ second_smallest. create_size_estimate ( cx. tcx ) ;
344
345
345
346
// Record that `second_smallest` now contains all the stuff that was
346
347
// in `smallest` before.
0 commit comments