@@ -131,11 +131,6 @@ struct PlacedMonoItems<'tcx> {
131131 codegen_units : Vec < CodegenUnit < ' tcx > > ,
132132
133133 internalization_candidates : FxHashSet < MonoItem < ' tcx > > ,
134-
135- /// These must be obtained when the iterator in `partition` runs. They
136- /// can't be obtained later because some inlined functions might not be
137- /// reachable.
138- unique_inlined_stats : ( usize , usize ) ,
139134}
140135
141136// The output CGUs are sorted by name.
@@ -153,11 +148,11 @@ where
153148
154149 // Place all mono items into a codegen unit. `place_mono_items` is
155150 // responsible for initializing the CGU size estimates.
156- let PlacedMonoItems { mut codegen_units, internalization_candidates, unique_inlined_stats } = {
151+ let PlacedMonoItems { mut codegen_units, internalization_candidates } = {
157152 let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_place_items" ) ;
158153 let placed = place_mono_items ( cx, mono_items) ;
159154
160- debug_dump ( tcx, "PLACE" , & placed. codegen_units , placed . unique_inlined_stats ) ;
155+ debug_dump ( tcx, "PLACE" , & placed. codegen_units ) ;
161156
162157 placed
163158 } ;
@@ -168,7 +163,7 @@ where
168163 {
169164 let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_merge_cgus" ) ;
170165 merge_codegen_units ( cx, & mut codegen_units) ;
171- debug_dump ( tcx, "MERGE" , & codegen_units, unique_inlined_stats ) ;
166+ debug_dump ( tcx, "MERGE" , & codegen_units) ;
172167 }
173168
174169 // Make as many symbols "internal" as possible, so LLVM has more freedom to
@@ -177,7 +172,7 @@ where
177172 let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_internalize_symbols" ) ;
178173 internalize_symbols ( cx, & mut codegen_units, internalization_candidates) ;
179174
180- debug_dump ( tcx, "INTERNALIZE" , & codegen_units, unique_inlined_stats ) ;
175+ debug_dump ( tcx, "INTERNALIZE" , & codegen_units) ;
181176 }
182177
183178 // Mark one CGU for dead code, if necessary.
@@ -217,19 +212,12 @@ where
217212 let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( cx. tcx ) ;
218213 let cgu_name_cache = & mut FxHashMap :: default ( ) ;
219214
220- let mut num_unique_inlined_items = 0 ;
221- let mut unique_inlined_items_size = 0 ;
222215 for mono_item in mono_items {
223216 // Handle only root items directly here. Inlined items are handled at
224217 // the bottom of the loop based on reachability.
225- let size_estimate = mono_item. size_estimate ( cx. tcx ) ;
226218 match mono_item. instantiation_mode ( cx. tcx ) {
227219 InstantiationMode :: GloballyShared { .. } => { }
228- InstantiationMode :: LocalCopy => {
229- num_unique_inlined_items += 1 ;
230- unique_inlined_items_size += size_estimate;
231- continue ;
232- }
220+ InstantiationMode :: LocalCopy => continue ,
233221 }
234222
235223 let characteristic_def_id = characteristic_def_id_of_mono_item ( cx. tcx , mono_item) ;
@@ -258,6 +246,7 @@ where
258246 if visibility == Visibility :: Hidden && can_be_internalized {
259247 internalization_candidates. insert ( mono_item) ;
260248 }
249+ let size_estimate = mono_item. size_estimate ( cx. tcx ) ;
261250
262251 cgu. items_mut ( ) . insert ( mono_item, MonoItemData { linkage, visibility, size_estimate } ) ;
263252
@@ -295,11 +284,7 @@ where
295284 cgu. compute_size_estimate ( ) ;
296285 }
297286
298- return PlacedMonoItems {
299- codegen_units,
300- internalization_candidates,
301- unique_inlined_stats : ( num_unique_inlined_items, unique_inlined_items_size) ,
302- } ;
287+ return PlacedMonoItems { codegen_units, internalization_candidates } ;
303288
304289 fn get_reachable_inlined_items < ' tcx > (
305290 tcx : TyCtxt < ' tcx > ,
@@ -858,12 +843,7 @@ fn default_visibility(tcx: TyCtxt<'_>, id: DefId, is_generic: bool) -> Visibilit
858843 }
859844}
860845
861- fn debug_dump < ' a , ' tcx : ' a > (
862- tcx : TyCtxt < ' tcx > ,
863- label : & str ,
864- cgus : & [ CodegenUnit < ' tcx > ] ,
865- ( unique_inlined_items, unique_inlined_size) : ( usize , usize ) ,
866- ) {
846+ fn debug_dump < ' a , ' tcx : ' a > ( tcx : TyCtxt < ' tcx > , label : & str , cgus : & [ CodegenUnit < ' tcx > ] ) {
867847 let dump = move || {
868848 use std:: fmt:: Write ;
869849
@@ -872,13 +852,17 @@ fn debug_dump<'a, 'tcx: 'a>(
872852
873853 // Note: every unique root item is placed exactly once, so the number
874854 // of unique root items always equals the number of placed root items.
855+ //
856+ // Also, unreached inlined items won't be counted here. This is fine.
857+
858+ let mut inlined_items = FxHashSet :: default ( ) ;
875859
876860 let mut root_items = 0 ;
877- // unique_inlined_items is passed in above.
861+ let mut unique_inlined_items = 0 ;
878862 let mut placed_inlined_items = 0 ;
879863
880864 let mut root_size = 0 ;
881- // unique_inlined_size is passed in above.
865+ let mut unique_inlined_size = 0 ;
882866 let mut placed_inlined_size = 0 ;
883867
884868 for cgu in cgus. iter ( ) {
@@ -892,6 +876,10 @@ fn debug_dump<'a, 'tcx: 'a>(
892876 root_size += data. size_estimate ;
893877 }
894878 InstantiationMode :: LocalCopy => {
879+ if inlined_items. insert ( item) {
880+ unique_inlined_items += 1 ;
881+ unique_inlined_size += data. size_estimate ;
882+ }
895883 placed_inlined_items += 1 ;
896884 placed_inlined_size += data. size_estimate ;
897885 }
0 commit comments