@@ -131,11 +131,6 @@ struct PlacedMonoItems<'tcx> {
131
131
codegen_units : Vec < CodegenUnit < ' tcx > > ,
132
132
133
133
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 ) ,
139
134
}
140
135
141
136
// The output CGUs are sorted by name.
@@ -153,11 +148,11 @@ where
153
148
154
149
// Place all mono items into a codegen unit. `place_mono_items` is
155
150
// 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 } = {
157
152
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_place_items" ) ;
158
153
let placed = place_mono_items ( cx, mono_items) ;
159
154
160
- debug_dump ( tcx, "PLACE" , & placed. codegen_units , placed . unique_inlined_stats ) ;
155
+ debug_dump ( tcx, "PLACE" , & placed. codegen_units ) ;
161
156
162
157
placed
163
158
} ;
@@ -168,7 +163,7 @@ where
168
163
{
169
164
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_merge_cgus" ) ;
170
165
merge_codegen_units ( cx, & mut codegen_units) ;
171
- debug_dump ( tcx, "MERGE" , & codegen_units, unique_inlined_stats ) ;
166
+ debug_dump ( tcx, "MERGE" , & codegen_units) ;
172
167
}
173
168
174
169
// Make as many symbols "internal" as possible, so LLVM has more freedom to
@@ -177,7 +172,7 @@ where
177
172
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_internalize_symbols" ) ;
178
173
internalize_symbols ( cx, & mut codegen_units, internalization_candidates) ;
179
174
180
- debug_dump ( tcx, "INTERNALIZE" , & codegen_units, unique_inlined_stats ) ;
175
+ debug_dump ( tcx, "INTERNALIZE" , & codegen_units) ;
181
176
}
182
177
183
178
// Mark one CGU for dead code, if necessary.
@@ -217,19 +212,12 @@ where
217
212
let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( cx. tcx ) ;
218
213
let cgu_name_cache = & mut FxHashMap :: default ( ) ;
219
214
220
- let mut num_unique_inlined_items = 0 ;
221
- let mut unique_inlined_items_size = 0 ;
222
215
for mono_item in mono_items {
223
216
// Handle only root items directly here. Inlined items are handled at
224
217
// the bottom of the loop based on reachability.
225
- let size_estimate = mono_item. size_estimate ( cx. tcx ) ;
226
218
match mono_item. instantiation_mode ( cx. tcx ) {
227
219
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 ,
233
221
}
234
222
235
223
let characteristic_def_id = characteristic_def_id_of_mono_item ( cx. tcx , mono_item) ;
@@ -258,6 +246,7 @@ where
258
246
if visibility == Visibility :: Hidden && can_be_internalized {
259
247
internalization_candidates. insert ( mono_item) ;
260
248
}
249
+ let size_estimate = mono_item. size_estimate ( cx. tcx ) ;
261
250
262
251
cgu. items_mut ( ) . insert ( mono_item, MonoItemData { linkage, visibility, size_estimate } ) ;
263
252
@@ -295,11 +284,7 @@ where
295
284
cgu. compute_size_estimate ( ) ;
296
285
}
297
286
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 } ;
303
288
304
289
fn get_reachable_inlined_items < ' tcx > (
305
290
tcx : TyCtxt < ' tcx > ,
@@ -858,12 +843,7 @@ fn default_visibility(tcx: TyCtxt<'_>, id: DefId, is_generic: bool) -> Visibilit
858
843
}
859
844
}
860
845
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 > ] ) {
867
847
let dump = move || {
868
848
use std:: fmt:: Write ;
869
849
@@ -872,13 +852,17 @@ fn debug_dump<'a, 'tcx: 'a>(
872
852
873
853
// Note: every unique root item is placed exactly once, so the number
874
854
// 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 ( ) ;
875
859
876
860
let mut root_items = 0 ;
877
- // unique_inlined_items is passed in above.
861
+ let mut unique_inlined_items = 0 ;
878
862
let mut placed_inlined_items = 0 ;
879
863
880
864
let mut root_size = 0 ;
881
- // unique_inlined_size is passed in above.
865
+ let mut unique_inlined_size = 0 ;
882
866
let mut placed_inlined_size = 0 ;
883
867
884
868
for cgu in cgus. iter ( ) {
@@ -892,6 +876,10 @@ fn debug_dump<'a, 'tcx: 'a>(
892
876
root_size += data. size_estimate ;
893
877
}
894
878
InstantiationMode :: LocalCopy => {
879
+ if inlined_items. insert ( item) {
880
+ unique_inlined_items += 1 ;
881
+ unique_inlined_size += data. size_estimate ;
882
+ }
895
883
placed_inlined_items += 1 ;
896
884
placed_inlined_size += data. size_estimate ;
897
885
}
0 commit comments