@@ -147,8 +147,6 @@ where
147147 || accessor_map ( tcx, inlining_map) ,
148148 ) ;
149149
150- initial_partitioning. codegen_units . iter_mut ( ) . for_each ( |cgu| cgu. estimate_size ( tcx) ) ;
151-
152150 debug_dump ( tcx, "INITIAL PARTITIONING:" , initial_partitioning. codegen_units . iter ( ) ) ;
153151
154152 // If the partitioning should produce a fixed count of codegen units, merge
@@ -226,54 +224,57 @@ where
226224
227225 let mono_items: Vec < _ > = mono_items. collect ( ) ;
228226
229- let _prof_timer = tcx. prof . generic_activity ( "place_root_mono_items_par" ) ;
227+ let chunks = tcx. prof . generic_activity ( "place_root_mono_items_par" ) . run ( || {
228+ sync:: par_partition ( & mono_items, 2 , |chunk| {
229+ let mut roots = Vec :: new ( ) ;
230+ let mut codegen_units = FxHashMap :: default ( ) ;
231+ let mut internalization_candidates = Vec :: new ( ) ;
230232
231- let chunks = sync:: par_partition ( & mono_items, 2 , |chunk| {
232- let mut roots = Vec :: new ( ) ;
233- let mut codegen_units = FxHashMap :: default ( ) ;
234- let mut internalization_candidates = Vec :: new ( ) ;
233+ let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( tcx) ;
234+ let cgu_name_cache = & mut FxHashMap :: default ( ) ;
235235
236- let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( tcx) ;
237- let cgu_name_cache = & mut FxHashMap :: default ( ) ;
236+ for & mono_item in chunk {
237+ match mono_item. instantiation_mode ( tcx) {
238+ InstantiationMode :: GloballyShared { .. } => { }
239+ InstantiationMode :: LocalCopy => continue ,
240+ }
238241
239- for & mono_item in chunk {
240- match mono_item. instantiation_mode ( tcx) {
241- InstantiationMode :: GloballyShared { .. } => { }
242- InstantiationMode :: LocalCopy => continue ,
243- }
242+ let characteristic_def_id = characteristic_def_id_of_mono_item ( tcx, mono_item) ;
243+ let is_volatile = is_incremental_build && mono_item. is_generic_fn ( ) ;
244+
245+ let codegen_unit_name = match characteristic_def_id {
246+ Some ( def_id) => compute_codegen_unit_name (
247+ tcx,
248+ cgu_name_builder,
249+ def_id,
250+ is_volatile,
251+ cgu_name_cache,
252+ ) ,
253+ None => fallback_cgu_name ( cgu_name_builder) ,
254+ } ;
244255
245- let characteristic_def_id = characteristic_def_id_of_mono_item ( tcx , mono_item ) ;
246- let is_volatile = is_incremental_build && mono_item . is_generic_fn ( ) ;
256+ let codegen_unit =
257+ codegen_units . entry ( codegen_unit_name ) . or_insert_with ( || ( Vec :: new ( ) , 0 ) ) ;
247258
248- let codegen_unit_name = match characteristic_def_id {
249- Some ( def_id ) => compute_codegen_unit_name (
259+ let mut can_be_internalized = true ;
260+ let ( linkage , visibility ) = mono_item_linkage_and_visibility (
250261 tcx,
251- cgu_name_builder ,
252- def_id ,
253- is_volatile ,
254- cgu_name_cache ,
255- ) ,
256- None => fallback_cgu_name ( cgu_name_builder ) ,
257- } ;
262+ & mono_item ,
263+ & mut can_be_internalized ,
264+ export_generics ,
265+ ) ;
266+ if visibility == Visibility :: Hidden && can_be_internalized {
267+ internalization_candidates . push ( mono_item ) ;
268+ }
258269
259- let codegen_unit = codegen_units. entry ( codegen_unit_name) . or_insert_with ( || Vec :: new ( ) ) ;
260-
261- let mut can_be_internalized = true ;
262- let ( linkage, visibility) = mono_item_linkage_and_visibility (
263- tcx,
264- & mono_item,
265- & mut can_be_internalized,
266- export_generics,
267- ) ;
268- if visibility == Visibility :: Hidden && can_be_internalized {
269- internalization_candidates. push ( mono_item) ;
270- }
270+ codegen_unit. 0 . push ( ( mono_item, ( linkage, visibility) ) ) ;
271+ codegen_unit. 1 += mono_item. size_estimate ( tcx) ;
271272
272- codegen_unit. push ( ( mono_item, ( linkage, visibility) ) ) ;
273- roots. push ( mono_item) ;
274- }
273+ roots. push ( mono_item) ;
274+ }
275275
276- ( roots, codegen_units, internalization_candidates)
276+ ( roots, codegen_units, internalization_candidates)
277+ } )
277278 } ) ;
278279
279280 let _prof_timer = tcx. prof . generic_activity ( "place_root_mono_items_merge" ) ;
@@ -285,8 +286,9 @@ where
285286 for ( chunk_roots, chunk_codegen_units, chunk_internalization_candidates) in chunks {
286287 roots. extend ( chunk_roots) ;
287288 internalization_candidates. extend ( chunk_internalization_candidates) ;
288- for ( name, items) in chunk_codegen_units {
289+ for ( name, ( items, cost ) ) in chunk_codegen_units {
289290 let codegen_unit = codegen_units. entry ( name) . or_insert_with ( || CodegenUnit :: new ( name) ) ;
291+ codegen_unit. modify_size_estimate ( cost) ;
290292 codegen_unit. items_mut ( ) . extend ( items) ;
291293 }
292294 }
0 commit comments