@@ -128,7 +128,7 @@ impl<'tcx> Partition<'tcx> for Partitioner {
128128 & mut self ,
129129 cx : & PartitioningCx < ' _ , ' tcx > ,
130130 mono_items : & mut I ,
131- ) -> PreInliningPartitioning < ' tcx >
131+ ) -> ( Vec < CodegenUnit < ' tcx > > , FxHashSet < MonoItem < ' tcx > > , FxHashSet < MonoItem < ' tcx > > )
132132 where
133133 I : Iterator < Item = MonoItem < ' tcx > > ,
134134 {
@@ -141,24 +141,23 @@ impl<'tcx> Partition<'tcx> for Partitioner {
141141 fn merge_codegen_units (
142142 & mut self ,
143143 cx : & PartitioningCx < ' _ , ' tcx > ,
144- initial_partitioning : & mut PreInliningPartitioning < ' tcx > ,
144+ codegen_units : & mut Vec < CodegenUnit < ' tcx > > ,
145145 ) {
146146 match self {
147- Partitioner :: Default ( partitioner) => {
148- partitioner. merge_codegen_units ( cx, initial_partitioning)
149- }
147+ Partitioner :: Default ( partitioner) => partitioner. merge_codegen_units ( cx, codegen_units) ,
150148 Partitioner :: Unknown => cx. tcx . sess . emit_fatal ( UnknownPartitionStrategy ) ,
151149 }
152150 }
153151
154152 fn place_inlined_mono_items (
155153 & mut self ,
156154 cx : & PartitioningCx < ' _ , ' tcx > ,
157- initial_partitioning : PreInliningPartitioning < ' tcx > ,
158- ) -> PostInliningPartitioning < ' tcx > {
155+ codegen_units : & mut [ CodegenUnit < ' tcx > ] ,
156+ roots : FxHashSet < MonoItem < ' tcx > > ,
157+ ) -> FxHashMap < MonoItem < ' tcx > , MonoItemPlacement > {
159158 match self {
160159 Partitioner :: Default ( partitioner) => {
161- partitioner. place_inlined_mono_items ( cx, initial_partitioning )
160+ partitioner. place_inlined_mono_items ( cx, codegen_units , roots )
162161 }
163162 Partitioner :: Unknown => cx. tcx . sess . emit_fatal ( UnknownPartitionStrategy ) ,
164163 }
@@ -167,12 +166,17 @@ impl<'tcx> Partition<'tcx> for Partitioner {
167166 fn internalize_symbols (
168167 & mut self ,
169168 cx : & PartitioningCx < ' _ , ' tcx > ,
170- post_inlining_partitioning : & mut PostInliningPartitioning < ' tcx > ,
169+ codegen_units : & mut [ CodegenUnit < ' tcx > ] ,
170+ mono_item_placements : FxHashMap < MonoItem < ' tcx > , MonoItemPlacement > ,
171+ internalization_candidates : FxHashSet < MonoItem < ' tcx > > ,
171172 ) {
172173 match self {
173- Partitioner :: Default ( partitioner) => {
174- partitioner. internalize_symbols ( cx, post_inlining_partitioning)
175- }
174+ Partitioner :: Default ( partitioner) => partitioner. internalize_symbols (
175+ cx,
176+ codegen_units,
177+ mono_item_placements,
178+ internalization_candidates,
179+ ) ,
176180 Partitioner :: Unknown => cx. tcx . sess . emit_fatal ( UnknownPartitionStrategy ) ,
177181 }
178182 }
@@ -189,26 +193,29 @@ trait Partition<'tcx> {
189193 & mut self ,
190194 cx : & PartitioningCx < ' _ , ' tcx > ,
191195 mono_items : & mut I ,
192- ) -> PreInliningPartitioning < ' tcx >
196+ ) -> ( Vec < CodegenUnit < ' tcx > > , FxHashSet < MonoItem < ' tcx > > , FxHashSet < MonoItem < ' tcx > > )
193197 where
194198 I : Iterator < Item = MonoItem < ' tcx > > ;
195199
196200 fn merge_codegen_units (
197201 & mut self ,
198202 cx : & PartitioningCx < ' _ , ' tcx > ,
199- initial_partitioning : & mut PreInliningPartitioning < ' tcx > ,
203+ codegen_units : & mut Vec < CodegenUnit < ' tcx > > ,
200204 ) ;
201205
202206 fn place_inlined_mono_items (
203207 & mut self ,
204208 cx : & PartitioningCx < ' _ , ' tcx > ,
205- initial_partitioning : PreInliningPartitioning < ' tcx > ,
206- ) -> PostInliningPartitioning < ' tcx > ;
209+ codegen_units : & mut [ CodegenUnit < ' tcx > ] ,
210+ roots : FxHashSet < MonoItem < ' tcx > > ,
211+ ) -> FxHashMap < MonoItem < ' tcx > , MonoItemPlacement > ;
207212
208213 fn internalize_symbols (
209214 & mut self ,
210215 cx : & PartitioningCx < ' _ , ' tcx > ,
211- partitioning : & mut PostInliningPartitioning < ' tcx > ,
216+ codegen_units : & mut [ CodegenUnit < ' tcx > ] ,
217+ mono_item_placements : FxHashMap < MonoItem < ' tcx > , MonoItemPlacement > ,
218+ internalization_candidates : FxHashSet < MonoItem < ' tcx > > ,
212219 ) ;
213220}
214221
@@ -240,52 +247,57 @@ where
240247 // In the first step, we place all regular monomorphizations into their
241248 // respective 'home' codegen unit. Regular monomorphizations are all
242249 // functions and statics defined in the local crate.
243- let mut initial_partitioning = {
250+ let ( mut codegen_units , roots , internalization_candidates ) = {
244251 let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_place_roots" ) ;
245252 partitioner. place_root_mono_items ( cx, mono_items)
246253 } ;
247254
248- for cgu in & mut initial_partitioning . codegen_units {
255+ for cgu in & mut codegen_units {
249256 cgu. create_size_estimate ( tcx) ;
250257 }
251258
252- debug_dump ( tcx, "INITIAL PARTITIONING" , & initial_partitioning . codegen_units ) ;
259+ debug_dump ( tcx, "INITIAL PARTITIONING" , & codegen_units) ;
253260
254261 // Merge until we have at most `max_cgu_count` codegen units.
255262 {
256263 let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_merge_cgus" ) ;
257- partitioner. merge_codegen_units ( cx, & mut initial_partitioning ) ;
258- debug_dump ( tcx, "POST MERGING" , & initial_partitioning . codegen_units ) ;
264+ partitioner. merge_codegen_units ( cx, & mut codegen_units ) ;
265+ debug_dump ( tcx, "POST MERGING" , & codegen_units) ;
259266 }
260267
261268 // In the next step, we use the inlining map to determine which additional
262269 // monomorphizations have to go into each codegen unit. These additional
263270 // monomorphizations can be drop-glue, functions from external crates, and
264271 // local functions the definition of which is marked with `#[inline]`.
265- let mut post_inlining = {
272+ let mono_item_placements = {
266273 let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_place_inline_items" ) ;
267- partitioner. place_inlined_mono_items ( cx, initial_partitioning )
274+ partitioner. place_inlined_mono_items ( cx, & mut codegen_units , roots )
268275 } ;
269276
270- for cgu in & mut post_inlining . codegen_units {
277+ for cgu in & mut codegen_units {
271278 cgu. create_size_estimate ( tcx) ;
272279 }
273280
274- debug_dump ( tcx, "POST INLINING" , & post_inlining . codegen_units ) ;
281+ debug_dump ( tcx, "POST INLINING" , & codegen_units) ;
275282
276283 // Next we try to make as many symbols "internal" as possible, so LLVM has
277284 // more freedom to optimize.
278285 if !tcx. sess . link_dead_code ( ) {
279286 let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_internalize_symbols" ) ;
280- partitioner. internalize_symbols ( cx, & mut post_inlining) ;
287+ partitioner. internalize_symbols (
288+ cx,
289+ & mut codegen_units,
290+ mono_item_placements,
291+ internalization_candidates,
292+ ) ;
281293 }
282294
283295 let instrument_dead_code =
284296 tcx. sess . instrument_coverage ( ) && !tcx. sess . instrument_coverage_except_unused_functions ( ) ;
285297
286298 if instrument_dead_code {
287299 assert ! (
288- post_inlining . codegen_units. len( ) > 0 ,
300+ codegen_units. len( ) > 0 ,
289301 "There must be at least one CGU that code coverage data can be generated in."
290302 ) ;
291303
@@ -296,7 +308,7 @@ where
296308 // the object file (CGU) containing the dead function stubs is included
297309 // in the final binary. This will probably require forcing these
298310 // function symbols to be included via `-u` or `/include` linker args.
299- let mut cgus: Vec < _ > = post_inlining . codegen_units . iter_mut ( ) . collect ( ) ;
311+ let mut cgus: Vec < _ > = codegen_units. iter_mut ( ) . collect ( ) ;
300312 cgus. sort_by_key ( |cgu| cgu. size_estimate ( ) ) ;
301313
302314 let dead_code_cgu =
@@ -307,29 +319,17 @@ where
307319 } else {
308320 // If there are no CGUs that have externally linked items,
309321 // then we just pick the first CGU as a fallback.
310- & mut post_inlining . codegen_units [ 0 ]
322+ & mut codegen_units[ 0 ]
311323 } ;
312324 dead_code_cgu. make_code_coverage_dead_code_cgu ( ) ;
313325 }
314326
315327 // Finally, sort by codegen unit name, so that we get deterministic results.
316- let PostInliningPartitioning {
317- codegen_units : mut result,
318- mono_item_placements : _,
319- internalization_candidates : _,
320- } = post_inlining;
328+ codegen_units. sort_by ( |a, b| a. name ( ) . as_str ( ) . cmp ( b. name ( ) . as_str ( ) ) ) ;
321329
322- result . sort_by ( |a , b| a . name ( ) . as_str ( ) . cmp ( b . name ( ) . as_str ( ) ) ) ;
330+ debug_dump ( tcx , "FINAL" , & codegen_units ) ;
323331
324- debug_dump ( tcx, "FINAL" , & result) ;
325-
326- result
327- }
328-
329- pub struct PreInliningPartitioning < ' tcx > {
330- codegen_units : Vec < CodegenUnit < ' tcx > > ,
331- roots : FxHashSet < MonoItem < ' tcx > > ,
332- internalization_candidates : FxHashSet < MonoItem < ' tcx > > ,
332+ codegen_units
333333}
334334
335335/// For symbol internalization, we need to know whether a symbol/mono-item is
@@ -341,12 +341,6 @@ enum MonoItemPlacement {
341341 MultipleCgus ,
342342}
343343
344- struct PostInliningPartitioning < ' tcx > {
345- codegen_units : Vec < CodegenUnit < ' tcx > > ,
346- mono_item_placements : FxHashMap < MonoItem < ' tcx > , MonoItemPlacement > ,
347- internalization_candidates : FxHashSet < MonoItem < ' tcx > > ,
348- }
349-
350344fn debug_dump < ' a , ' tcx : ' a > ( tcx : TyCtxt < ' tcx > , label : & str , cgus : & [ CodegenUnit < ' tcx > ] ) {
351345 let dump = move || {
352346 use std:: fmt:: Write ;
0 commit comments