116
116
//! source-level module, functions from the same module will be available for
117
117
//! inlining, even when they are not marked #[inline].
118
118
119
- use collector:: ReferenceMap ;
119
+ use collector:: InliningMap ;
120
120
use llvm;
121
121
use monomorphize;
122
122
use rustc:: hir:: def_id:: DefId ;
@@ -127,20 +127,9 @@ use syntax::parse::token::{self, InternedString};
127
127
use trans_item:: TransItem ;
128
128
use util:: nodemap:: { FnvHashMap , FnvHashSet } ;
129
129
130
- #[ derive( Clone , Copy , Eq , PartialEq , Debug ) ]
131
- pub enum InstantiationMode {
132
- /// This variant indicates that a translation item should be placed in some
133
- /// codegen unit as a definition and with the given linkage.
134
- Def ( llvm:: Linkage ) ,
135
-
136
- /// This variant indicates that only a declaration of some translation item
137
- /// should be placed in a given codegen unit.
138
- Decl
139
- }
140
-
141
130
pub struct CodegenUnit < ' tcx > {
142
131
pub name : InternedString ,
143
- pub items : FnvHashMap < TransItem < ' tcx > , InstantiationMode > ,
132
+ pub items : FnvHashMap < TransItem < ' tcx > , llvm :: Linkage > ,
144
133
}
145
134
146
135
pub enum PartitioningStrategy {
@@ -157,7 +146,7 @@ const FALLBACK_CODEGEN_UNIT: &'static str = "__rustc_fallback_codegen_unit";
157
146
pub fn partition < ' a , ' tcx , I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
158
147
trans_items : I ,
159
148
strategy : PartitioningStrategy ,
160
- reference_map : & ReferenceMap < ' tcx > )
149
+ inlining_map : & InliningMap < ' tcx > )
161
150
-> Vec < CodegenUnit < ' tcx > >
162
151
where I : Iterator < Item = TransItem < ' tcx > >
163
152
{
@@ -177,13 +166,8 @@ pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
177
166
// translation items can be drop-glue, functions from external crates, and
178
167
// local functions the definition of which is marked with #[inline].
179
168
let post_inlining = place_inlined_translation_items ( initial_partitioning,
180
- reference_map) ;
181
-
182
- // Now we know all *definitions* within all codegen units, thus we can
183
- // easily determine which declarations need to be placed within each one.
184
- let post_declarations = place_declarations ( post_inlining, reference_map) ;
185
-
186
- post_declarations. 0
169
+ inlining_map) ;
170
+ post_inlining. 0
187
171
}
188
172
189
173
struct PreInliningPartitioning < ' tcx > {
@@ -192,7 +176,6 @@ struct PreInliningPartitioning<'tcx> {
192
176
}
193
177
194
178
struct PostInliningPartitioning < ' tcx > ( Vec < CodegenUnit < ' tcx > > ) ;
195
- struct PostDeclarationsPartitioning < ' tcx > ( Vec < CodegenUnit < ' tcx > > ) ;
196
179
197
180
fn place_root_translation_items < ' a , ' tcx , I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
198
181
trans_items : I )
@@ -240,8 +223,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
240
223
}
241
224
} ;
242
225
243
- codegen_unit. items . insert ( trans_item,
244
- InstantiationMode :: Def ( linkage) ) ;
226
+ codegen_unit. items . insert ( trans_item, linkage) ;
245
227
roots. insert ( trans_item) ;
246
228
}
247
229
}
@@ -295,15 +277,15 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
295
277
}
296
278
297
279
fn place_inlined_translation_items < ' tcx > ( initial_partitioning : PreInliningPartitioning < ' tcx > ,
298
- reference_map : & ReferenceMap < ' tcx > )
280
+ inlining_map : & InliningMap < ' tcx > )
299
281
-> PostInliningPartitioning < ' tcx > {
300
282
let mut new_partitioning = Vec :: new ( ) ;
301
283
302
284
for codegen_unit in & initial_partitioning. codegen_units [ ..] {
303
285
// Collect all items that need to be available in this codegen unit
304
286
let mut reachable = FnvHashSet ( ) ;
305
287
for root in codegen_unit. items . keys ( ) {
306
- follow_inlining ( * root, reference_map , & mut reachable) ;
288
+ follow_inlining ( * root, inlining_map , & mut reachable) ;
307
289
}
308
290
309
291
let mut new_codegen_unit = CodegenUnit {
@@ -313,22 +295,22 @@ fn place_inlined_translation_items<'tcx>(initial_partitioning: PreInliningPartit
313
295
314
296
// Add all translation items that are not already there
315
297
for trans_item in reachable {
316
- if let Some ( instantiation_mode ) = codegen_unit. items . get ( & trans_item) {
298
+ if let Some ( linkage ) = codegen_unit. items . get ( & trans_item) {
317
299
// This is a root, just copy it over
318
- new_codegen_unit. items . insert ( trans_item, * instantiation_mode ) ;
300
+ new_codegen_unit. items . insert ( trans_item, * linkage ) ;
319
301
} else {
320
302
if initial_partitioning. roots . contains ( & trans_item) {
321
303
// This item will be instantiated in some other codegen unit,
322
304
// so we just add it here with AvailableExternallyLinkage
323
305
new_codegen_unit. items . insert ( trans_item,
324
- InstantiationMode :: Def ( llvm:: AvailableExternallyLinkage ) ) ;
306
+ llvm:: AvailableExternallyLinkage ) ;
325
307
} else {
326
308
// We can't be sure if this will also be instantiated
327
309
// somewhere else, so we add an instance here with
328
310
// LinkOnceODRLinkage. That way the item can be discarded if
329
311
// it's not needed (inlined) after all.
330
312
new_codegen_unit. items . insert ( trans_item,
331
- InstantiationMode :: Def ( llvm:: LinkOnceODRLinkage ) ) ;
313
+ llvm:: LinkOnceODRLinkage ) ;
332
314
}
333
315
}
334
316
}
@@ -339,43 +321,18 @@ fn place_inlined_translation_items<'tcx>(initial_partitioning: PreInliningPartit
339
321
return PostInliningPartitioning ( new_partitioning) ;
340
322
341
323
fn follow_inlining < ' tcx > ( trans_item : TransItem < ' tcx > ,
342
- reference_map : & ReferenceMap < ' tcx > ,
324
+ inlining_map : & InliningMap < ' tcx > ,
343
325
visited : & mut FnvHashSet < TransItem < ' tcx > > ) {
344
326
if !visited. insert ( trans_item) {
345
327
return ;
346
328
}
347
329
348
- reference_map . with_inlining_candidates ( trans_item, |target| {
349
- follow_inlining ( target, reference_map , visited) ;
330
+ inlining_map . with_inlining_candidates ( trans_item, |target| {
331
+ follow_inlining ( target, inlining_map , visited) ;
350
332
} ) ;
351
333
}
352
334
}
353
335
354
- fn place_declarations < ' tcx > ( codegen_units : PostInliningPartitioning < ' tcx > ,
355
- reference_map : & ReferenceMap < ' tcx > )
356
- -> PostDeclarationsPartitioning < ' tcx > {
357
- let PostInliningPartitioning ( mut codegen_units) = codegen_units;
358
-
359
- for codegen_unit in codegen_units. iter_mut ( ) {
360
- let mut declarations = FnvHashSet ( ) ;
361
-
362
- for ( trans_item, _) in & codegen_unit. items {
363
- for referenced_item in reference_map. get_direct_references_from ( * trans_item) {
364
- if !codegen_unit. items . contains_key ( referenced_item) {
365
- declarations. insert ( * referenced_item) ;
366
- }
367
- }
368
- }
369
-
370
- codegen_unit. items
371
- . extend ( declarations. iter ( )
372
- . map ( |trans_item| ( * trans_item,
373
- InstantiationMode :: Decl ) ) ) ;
374
- }
375
-
376
- PostDeclarationsPartitioning ( codegen_units)
377
- }
378
-
379
336
fn characteristic_def_id_of_trans_item < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
380
337
trans_item : TransItem < ' tcx > )
381
338
-> Option < DefId > {
0 commit comments