116116//! source-level module, functions from the same module will be available for
117117//! inlining, even when they are not marked #[inline].
118118
119- use collector:: ReferenceMap ;
119+ use collector:: InliningMap ;
120120use llvm;
121121use monomorphize;
122122use rustc:: hir:: def_id:: DefId ;
@@ -127,20 +127,9 @@ use syntax::parse::token::{self, InternedString};
127127use trans_item:: TransItem ;
128128use util:: nodemap:: { FnvHashMap , FnvHashSet } ;
129129
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-
141130pub struct CodegenUnit < ' tcx > {
142131 pub name : InternedString ,
143- pub items : FnvHashMap < TransItem < ' tcx > , InstantiationMode > ,
132+ pub items : FnvHashMap < TransItem < ' tcx > , llvm :: Linkage > ,
144133}
145134
146135pub enum PartitioningStrategy {
@@ -157,7 +146,7 @@ const FALLBACK_CODEGEN_UNIT: &'static str = "__rustc_fallback_codegen_unit";
157146pub fn partition < ' a , ' tcx , I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
158147 trans_items : I ,
159148 strategy : PartitioningStrategy ,
160- reference_map : & ReferenceMap < ' tcx > )
149+ inlining_map : & InliningMap < ' tcx > )
161150 -> Vec < CodegenUnit < ' tcx > >
162151 where I : Iterator < Item = TransItem < ' tcx > >
163152{
@@ -177,13 +166,8 @@ pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
177166 // translation items can be drop-glue, functions from external crates, and
178167 // local functions the definition of which is marked with #[inline].
179168 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
187171}
188172
189173struct PreInliningPartitioning < ' tcx > {
@@ -192,7 +176,6 @@ struct PreInliningPartitioning<'tcx> {
192176}
193177
194178struct PostInliningPartitioning < ' tcx > ( Vec < CodegenUnit < ' tcx > > ) ;
195- struct PostDeclarationsPartitioning < ' tcx > ( Vec < CodegenUnit < ' tcx > > ) ;
196179
197180fn place_root_translation_items < ' a , ' tcx , I > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
198181 trans_items : I )
@@ -240,8 +223,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
240223 }
241224 } ;
242225
243- codegen_unit. items . insert ( trans_item,
244- InstantiationMode :: Def ( linkage) ) ;
226+ codegen_unit. items . insert ( trans_item, linkage) ;
245227 roots. insert ( trans_item) ;
246228 }
247229 }
@@ -295,15 +277,15 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning<
295277}
296278
297279fn place_inlined_translation_items < ' tcx > ( initial_partitioning : PreInliningPartitioning < ' tcx > ,
298- reference_map : & ReferenceMap < ' tcx > )
280+ inlining_map : & InliningMap < ' tcx > )
299281 -> PostInliningPartitioning < ' tcx > {
300282 let mut new_partitioning = Vec :: new ( ) ;
301283
302284 for codegen_unit in & initial_partitioning. codegen_units [ ..] {
303285 // Collect all items that need to be available in this codegen unit
304286 let mut reachable = FnvHashSet ( ) ;
305287 for root in codegen_unit. items . keys ( ) {
306- follow_inlining ( * root, reference_map , & mut reachable) ;
288+ follow_inlining ( * root, inlining_map , & mut reachable) ;
307289 }
308290
309291 let mut new_codegen_unit = CodegenUnit {
@@ -313,22 +295,22 @@ fn place_inlined_translation_items<'tcx>(initial_partitioning: PreInliningPartit
313295
314296 // Add all translation items that are not already there
315297 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) {
317299 // 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 ) ;
319301 } else {
320302 if initial_partitioning. roots . contains ( & trans_item) {
321303 // This item will be instantiated in some other codegen unit,
322304 // so we just add it here with AvailableExternallyLinkage
323305 new_codegen_unit. items . insert ( trans_item,
324- InstantiationMode :: Def ( llvm:: AvailableExternallyLinkage ) ) ;
306+ llvm:: AvailableExternallyLinkage ) ;
325307 } else {
326308 // We can't be sure if this will also be instantiated
327309 // somewhere else, so we add an instance here with
328310 // LinkOnceODRLinkage. That way the item can be discarded if
329311 // it's not needed (inlined) after all.
330312 new_codegen_unit. items . insert ( trans_item,
331- InstantiationMode :: Def ( llvm:: LinkOnceODRLinkage ) ) ;
313+ llvm:: LinkOnceODRLinkage ) ;
332314 }
333315 }
334316 }
@@ -339,43 +321,18 @@ fn place_inlined_translation_items<'tcx>(initial_partitioning: PreInliningPartit
339321 return PostInliningPartitioning ( new_partitioning) ;
340322
341323 fn follow_inlining < ' tcx > ( trans_item : TransItem < ' tcx > ,
342- reference_map : & ReferenceMap < ' tcx > ,
324+ inlining_map : & InliningMap < ' tcx > ,
343325 visited : & mut FnvHashSet < TransItem < ' tcx > > ) {
344326 if !visited. insert ( trans_item) {
345327 return ;
346328 }
347329
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) ;
350332 } ) ;
351333 }
352334}
353335
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-
379336fn characteristic_def_id_of_trans_item < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
380337 trans_item : TransItem < ' tcx > )
381338 -> Option < DefId > {
0 commit comments