@@ -222,11 +222,12 @@ where
222
222
for mono_item in mono_items {
223
223
// Handle only root items directly here. Inlined items are handled at
224
224
// the bottom of the loop based on reachability.
225
+ let size_estimate = mono_item. size_estimate ( cx. tcx ) ;
225
226
match mono_item. instantiation_mode ( cx. tcx ) {
226
227
InstantiationMode :: GloballyShared { .. } => { }
227
228
InstantiationMode :: LocalCopy => {
228
229
num_unique_inlined_items += 1 ;
229
- unique_inlined_items_size += mono_item . size_estimate ( cx . tcx ) ;
230
+ unique_inlined_items_size += size_estimate;
230
231
continue ;
231
232
}
232
233
}
@@ -258,7 +259,7 @@ where
258
259
internalization_candidates. insert ( mono_item) ;
259
260
}
260
261
261
- cgu. items_mut ( ) . insert ( mono_item, MonoItemData { linkage, visibility } ) ;
262
+ cgu. items_mut ( ) . insert ( mono_item, MonoItemData { linkage, visibility, size_estimate } ) ;
262
263
263
264
// Get all inlined items that are reachable from `mono_item` without
264
265
// going via another root item. This includes drop-glue, functions from
@@ -272,9 +273,11 @@ where
272
273
// the `insert` will be a no-op.
273
274
for inlined_item in reachable_inlined_items {
274
275
// This is a CGU-private copy.
275
- let linkage = Linkage :: Internal ;
276
- let visibility = Visibility :: Default ;
277
- cgu. items_mut ( ) . insert ( inlined_item, MonoItemData { linkage, visibility } ) ;
276
+ cgu. items_mut ( ) . entry ( inlined_item) . or_insert_with ( || MonoItemData {
277
+ linkage : Linkage :: Internal ,
278
+ visibility : Visibility :: Default ,
279
+ size_estimate : inlined_item. size_estimate ( cx. tcx ) ,
280
+ } ) ;
278
281
}
279
282
}
280
283
@@ -289,7 +292,7 @@ where
289
292
codegen_units. sort_by ( |a, b| a. name ( ) . as_str ( ) . cmp ( b. name ( ) . as_str ( ) ) ) ;
290
293
291
294
for cgu in codegen_units. iter_mut ( ) {
292
- cgu. compute_size_estimate ( cx . tcx ) ;
295
+ cgu. compute_size_estimate ( ) ;
293
296
}
294
297
295
298
return PlacedMonoItems {
@@ -352,7 +355,7 @@ fn merge_codegen_units<'tcx>(
352
355
&& codegen_units. iter ( ) . any ( |cgu| cgu. size_estimate ( ) < NON_INCR_MIN_CGU_SIZE ) )
353
356
{
354
357
// Sort small cgus to the back.
355
- codegen_units. sort_by_cached_key ( |cgu| cmp:: Reverse ( cgu. size_estimate ( ) ) ) ;
358
+ codegen_units. sort_by_key ( |cgu| cmp:: Reverse ( cgu. size_estimate ( ) ) ) ;
356
359
357
360
let mut smallest = codegen_units. pop ( ) . unwrap ( ) ;
358
361
let second_smallest = codegen_units. last_mut ( ) . unwrap ( ) ;
@@ -361,7 +364,7 @@ fn merge_codegen_units<'tcx>(
361
364
// may be duplicate inlined items, in which case the destination CGU is
362
365
// unaffected. Recalculate size estimates afterwards.
363
366
second_smallest. items_mut ( ) . extend ( smallest. items_mut ( ) . drain ( ) ) ;
364
- second_smallest. compute_size_estimate ( cx . tcx ) ;
367
+ second_smallest. compute_size_estimate ( ) ;
365
368
366
369
// Record that `second_smallest` now contains all the stuff that was
367
370
// in `smallest` before.
@@ -882,15 +885,15 @@ fn debug_dump<'a, 'tcx: 'a>(
882
885
num_cgus += 1 ;
883
886
all_cgu_sizes. push ( cgu. size_estimate ( ) ) ;
884
887
885
- for ( item, _ ) in cgu. items ( ) {
888
+ for ( item, data ) in cgu. items ( ) {
886
889
match item. instantiation_mode ( tcx) {
887
890
InstantiationMode :: GloballyShared { .. } => {
888
891
root_items += 1 ;
889
- root_size += item . size_estimate ( tcx ) ;
892
+ root_size += data . size_estimate ;
890
893
}
891
894
InstantiationMode :: LocalCopy => {
892
895
placed_inlined_items += 1 ;
893
- placed_inlined_size += item . size_estimate ( tcx ) ;
896
+ placed_inlined_size += data . size_estimate ;
894
897
}
895
898
}
896
899
}
@@ -932,7 +935,7 @@ fn debug_dump<'a, 'tcx: 'a>(
932
935
let mean_size = size as f64 / num_items as f64 ;
933
936
934
937
let mut placed_item_sizes: Vec < _ > =
935
- cgu. items ( ) . iter ( ) . map ( |( item , _ ) | item . size_estimate ( tcx ) ) . collect ( ) ;
938
+ cgu. items ( ) . values ( ) . map ( |data| data . size_estimate ) . collect ( ) ;
936
939
placed_item_sizes. sort_unstable_by_key ( |& n| cmp:: Reverse ( n) ) ;
937
940
let sizes = list ( & placed_item_sizes) ;
938
941
@@ -946,11 +949,11 @@ fn debug_dump<'a, 'tcx: 'a>(
946
949
let symbol_name = item. symbol_name ( tcx) . name ;
947
950
let symbol_hash_start = symbol_name. rfind ( 'h' ) ;
948
951
let symbol_hash = symbol_hash_start. map_or ( "<no hash>" , |i| & symbol_name[ i..] ) ;
949
- let size = item. size_estimate ( tcx) ;
950
952
let kind = match item. instantiation_mode ( tcx) {
951
953
InstantiationMode :: GloballyShared { .. } => "root" ,
952
954
InstantiationMode :: LocalCopy => "inlined" ,
953
955
} ;
956
+ let size = data. size_estimate ;
954
957
let _ = with_no_trimmed_paths ! ( writeln!(
955
958
s,
956
959
" - {item} [{linkage:?}] [{symbol_hash}] ({kind}, size: {size})"
0 commit comments