@@ -128,7 +128,7 @@ impl<'tcx> Partition<'tcx> for Partitioner {
128
128
& mut self ,
129
129
cx : & PartitioningCx < ' _ , ' tcx > ,
130
130
mono_items : & mut I ,
131
- ) -> PreInliningPartitioning < ' tcx >
131
+ ) -> ( Vec < CodegenUnit < ' tcx > > , FxHashSet < MonoItem < ' tcx > > , FxHashSet < MonoItem < ' tcx > > )
132
132
where
133
133
I : Iterator < Item = MonoItem < ' tcx > > ,
134
134
{
@@ -141,24 +141,23 @@ impl<'tcx> Partition<'tcx> for Partitioner {
141
141
fn merge_codegen_units (
142
142
& mut self ,
143
143
cx : & PartitioningCx < ' _ , ' tcx > ,
144
- initial_partitioning : & mut PreInliningPartitioning < ' tcx > ,
144
+ codegen_units : & mut Vec < CodegenUnit < ' tcx > > ,
145
145
) {
146
146
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) ,
150
148
Partitioner :: Unknown => cx. tcx . sess . emit_fatal ( UnknownPartitionStrategy ) ,
151
149
}
152
150
}
153
151
154
152
fn place_inlined_mono_items (
155
153
& mut self ,
156
154
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 > {
159
158
match self {
160
159
Partitioner :: Default ( partitioner) => {
161
- partitioner. place_inlined_mono_items ( cx, initial_partitioning )
160
+ partitioner. place_inlined_mono_items ( cx, codegen_units , roots )
162
161
}
163
162
Partitioner :: Unknown => cx. tcx . sess . emit_fatal ( UnknownPartitionStrategy ) ,
164
163
}
@@ -167,12 +166,17 @@ impl<'tcx> Partition<'tcx> for Partitioner {
167
166
fn internalize_symbols (
168
167
& mut self ,
169
168
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 > > ,
171
172
) {
172
173
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
+ ) ,
176
180
Partitioner :: Unknown => cx. tcx . sess . emit_fatal ( UnknownPartitionStrategy ) ,
177
181
}
178
182
}
@@ -189,26 +193,29 @@ trait Partition<'tcx> {
189
193
& mut self ,
190
194
cx : & PartitioningCx < ' _ , ' tcx > ,
191
195
mono_items : & mut I ,
192
- ) -> PreInliningPartitioning < ' tcx >
196
+ ) -> ( Vec < CodegenUnit < ' tcx > > , FxHashSet < MonoItem < ' tcx > > , FxHashSet < MonoItem < ' tcx > > )
193
197
where
194
198
I : Iterator < Item = MonoItem < ' tcx > > ;
195
199
196
200
fn merge_codegen_units (
197
201
& mut self ,
198
202
cx : & PartitioningCx < ' _ , ' tcx > ,
199
- initial_partitioning : & mut PreInliningPartitioning < ' tcx > ,
203
+ codegen_units : & mut Vec < CodegenUnit < ' tcx > > ,
200
204
) ;
201
205
202
206
fn place_inlined_mono_items (
203
207
& mut self ,
204
208
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 > ;
207
212
208
213
fn internalize_symbols (
209
214
& mut self ,
210
215
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 > > ,
212
219
) ;
213
220
}
214
221
@@ -240,52 +247,57 @@ where
240
247
// In the first step, we place all regular monomorphizations into their
241
248
// respective 'home' codegen unit. Regular monomorphizations are all
242
249
// functions and statics defined in the local crate.
243
- let mut initial_partitioning = {
250
+ let ( mut codegen_units , roots , internalization_candidates ) = {
244
251
let _prof_timer = tcx. prof . generic_activity ( "cgu_partitioning_place_roots" ) ;
245
252
partitioner. place_root_mono_items ( cx, mono_items)
246
253
} ;
247
254
248
- for cgu in & mut initial_partitioning . codegen_units {
255
+ for cgu in & mut codegen_units {
249
256
cgu. create_size_estimate ( tcx) ;
250
257
}
251
258
252
- debug_dump ( tcx, "INITIAL PARTITIONING" , & initial_partitioning . codegen_units ) ;
259
+ debug_dump ( tcx, "INITIAL PARTITIONING" , & codegen_units) ;
253
260
254
261
// Merge until we have at most `max_cgu_count` codegen units.
255
262
{
256
263
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) ;
259
266
}
260
267
261
268
// In the next step, we use the inlining map to determine which additional
262
269
// monomorphizations have to go into each codegen unit. These additional
263
270
// monomorphizations can be drop-glue, functions from external crates, and
264
271
// local functions the definition of which is marked with `#[inline]`.
265
- let mut post_inlining = {
272
+ let mono_item_placements = {
266
273
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 )
268
275
} ;
269
276
270
- for cgu in & mut post_inlining . codegen_units {
277
+ for cgu in & mut codegen_units {
271
278
cgu. create_size_estimate ( tcx) ;
272
279
}
273
280
274
- debug_dump ( tcx, "POST INLINING" , & post_inlining . codegen_units ) ;
281
+ debug_dump ( tcx, "POST INLINING" , & codegen_units) ;
275
282
276
283
// Next we try to make as many symbols "internal" as possible, so LLVM has
277
284
// more freedom to optimize.
278
285
if !tcx. sess . link_dead_code ( ) {
279
286
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
+ ) ;
281
293
}
282
294
283
295
let instrument_dead_code =
284
296
tcx. sess . instrument_coverage ( ) && !tcx. sess . instrument_coverage_except_unused_functions ( ) ;
285
297
286
298
if instrument_dead_code {
287
299
assert ! (
288
- post_inlining . codegen_units. len( ) > 0 ,
300
+ codegen_units. len( ) > 0 ,
289
301
"There must be at least one CGU that code coverage data can be generated in."
290
302
) ;
291
303
@@ -296,7 +308,7 @@ where
296
308
// the object file (CGU) containing the dead function stubs is included
297
309
// in the final binary. This will probably require forcing these
298
310
// 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 ( ) ;
300
312
cgus. sort_by_key ( |cgu| cgu. size_estimate ( ) ) ;
301
313
302
314
let dead_code_cgu =
@@ -307,29 +319,17 @@ where
307
319
} else {
308
320
// If there are no CGUs that have externally linked items,
309
321
// then we just pick the first CGU as a fallback.
310
- & mut post_inlining . codegen_units [ 0 ]
322
+ & mut codegen_units[ 0 ]
311
323
} ;
312
324
dead_code_cgu. make_code_coverage_dead_code_cgu ( ) ;
313
325
}
314
326
315
327
// 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 ( ) ) ) ;
321
329
322
- result . sort_by ( |a , b| a . name ( ) . as_str ( ) . cmp ( b . name ( ) . as_str ( ) ) ) ;
330
+ debug_dump ( tcx , "FINAL" , & codegen_units ) ;
323
331
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
333
333
}
334
334
335
335
/// For symbol internalization, we need to know whether a symbol/mono-item is
@@ -341,12 +341,6 @@ enum MonoItemPlacement {
341
341
MultipleCgus ,
342
342
}
343
343
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
-
350
344
fn debug_dump < ' a , ' tcx : ' a > ( tcx : TyCtxt < ' tcx > , label : & str , cgus : & [ CodegenUnit < ' tcx > ] ) {
351
345
let dump = move || {
352
346
use std:: fmt:: Write ;
0 commit comments