@@ -109,22 +109,18 @@ pub struct Postorder<'a, 'tcx> {
109109 visited : DenseBitSet < BasicBlock > ,
110110 visit_stack : Vec < ( BasicBlock , Successors < ' a > ) > ,
111111 root_is_start_block : bool ,
112- /// A non-empty `extra` allows for a precise calculation of the successors.
113- extra : Option < ( TyCtxt < ' tcx > , Instance < ' tcx > ) > ,
114112}
115113
116114impl < ' a , ' tcx > Postorder < ' a , ' tcx > {
117115 pub fn new (
118116 basic_blocks : & ' a IndexSlice < BasicBlock , BasicBlockData < ' tcx > > ,
119117 root : BasicBlock ,
120- extra : Option < ( TyCtxt < ' tcx > , Instance < ' tcx > ) > ,
121118 ) -> Postorder < ' a , ' tcx > {
122119 let mut po = Postorder {
123120 basic_blocks,
124121 visited : DenseBitSet :: new_empty ( basic_blocks. len ( ) ) ,
125122 visit_stack : Vec :: new ( ) ,
126123 root_is_start_block : root == START_BLOCK ,
127- extra,
128124 } ;
129125
130126 po. visit ( root) ;
@@ -138,11 +134,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
138134 return ;
139135 }
140136 let data = & self . basic_blocks [ bb] ;
141- let successors = if let Some ( extra) = self . extra {
142- data. mono_successors ( extra. 0 , extra. 1 )
143- } else {
144- data. terminator ( ) . successors ( )
145- } ;
137+ let successors = data. terminator ( ) . successors ( ) ;
146138 self . visit_stack . push ( ( bb, successors) ) ;
147139 }
148140
@@ -240,20 +232,6 @@ pub fn postorder<'a, 'tcx>(
240232 reverse_postorder ( body) . rev ( )
241233}
242234
243- pub fn mono_reachable_reverse_postorder < ' a , ' tcx > (
244- body : & ' a Body < ' tcx > ,
245- tcx : TyCtxt < ' tcx > ,
246- instance : Instance < ' tcx > ,
247- ) -> Vec < BasicBlock > {
248- let mut iter = Postorder :: new ( & body. basic_blocks , START_BLOCK , Some ( ( tcx, instance) ) ) ;
249- let mut items = Vec :: with_capacity ( body. basic_blocks . len ( ) ) ;
250- while let Some ( block) = iter. next ( ) {
251- items. push ( block) ;
252- }
253- items. reverse ( ) ;
254- items
255- }
256-
257235/// Returns an iterator over all basic blocks reachable from the `START_BLOCK` in no particular
258236/// order.
259237///
@@ -301,91 +279,3 @@ pub fn reverse_postorder<'a, 'tcx>(
301279{
302280 body. basic_blocks . reverse_postorder ( ) . iter ( ) . map ( |& bb| ( bb, & body. basic_blocks [ bb] ) )
303281}
304-
305- /// Traversal of a [`Body`] that tries to avoid unreachable blocks in a monomorphized [`Instance`].
306- ///
307- /// This is allowed to have false positives; blocks may be visited even if they are not actually
308- /// reachable.
309- ///
310- /// Such a traversal is mostly useful because it lets us skip lowering the `false` side
311- /// of `if <T as Trait>::CONST`, as well as [`NullOp::UbChecks`].
312- ///
313- /// [`NullOp::UbChecks`]: rustc_middle::mir::NullOp::UbChecks
314- pub fn mono_reachable < ' a , ' tcx > (
315- body : & ' a Body < ' tcx > ,
316- tcx : TyCtxt < ' tcx > ,
317- instance : Instance < ' tcx > ,
318- ) -> MonoReachable < ' a , ' tcx > {
319- MonoReachable :: new ( body, tcx, instance)
320- }
321-
322- /// [`MonoReachable`] internally accumulates a [`DenseBitSet`] of visited blocks. This is just a
323- /// convenience function to run that traversal then extract its set of reached blocks.
324- pub fn mono_reachable_as_bitset < ' a , ' tcx > (
325- body : & ' a Body < ' tcx > ,
326- tcx : TyCtxt < ' tcx > ,
327- instance : Instance < ' tcx > ,
328- ) -> DenseBitSet < BasicBlock > {
329- let mut iter = mono_reachable ( body, tcx, instance) ;
330- while let Some ( _) = iter. next ( ) { }
331- iter. visited
332- }
333-
334- pub struct MonoReachable < ' a , ' tcx > {
335- body : & ' a Body < ' tcx > ,
336- tcx : TyCtxt < ' tcx > ,
337- instance : Instance < ' tcx > ,
338- visited : DenseBitSet < BasicBlock > ,
339- // Other traversers track their worklist in a Vec. But we don't care about order, so we can
340- // store ours in a DenseBitSet and thus save allocations because DenseBitSet has a small size
341- // optimization.
342- worklist : DenseBitSet < BasicBlock > ,
343- }
344-
345- impl < ' a , ' tcx > MonoReachable < ' a , ' tcx > {
346- pub fn new (
347- body : & ' a Body < ' tcx > ,
348- tcx : TyCtxt < ' tcx > ,
349- instance : Instance < ' tcx > ,
350- ) -> MonoReachable < ' a , ' tcx > {
351- let mut worklist = DenseBitSet :: new_empty ( body. basic_blocks . len ( ) ) ;
352- worklist. insert ( START_BLOCK ) ;
353- MonoReachable {
354- body,
355- tcx,
356- instance,
357- visited : DenseBitSet :: new_empty ( body. basic_blocks . len ( ) ) ,
358- worklist,
359- }
360- }
361-
362- fn add_work ( & mut self , blocks : impl IntoIterator < Item = BasicBlock > ) {
363- for block in blocks. into_iter ( ) {
364- if !self . visited . contains ( block) {
365- self . worklist . insert ( block) ;
366- }
367- }
368- }
369- }
370-
371- impl < ' a , ' tcx > Iterator for MonoReachable < ' a , ' tcx > {
372- type Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) ;
373-
374- fn next ( & mut self ) -> Option < ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > {
375- while let Some ( idx) = self . worklist . iter ( ) . next ( ) {
376- self . worklist . remove ( idx) ;
377- if !self . visited . insert ( idx) {
378- continue ;
379- }
380-
381- let data = & self . body [ idx] ;
382-
383- let targets = data. mono_successors ( self . tcx , self . instance ) ;
384- self . add_work ( targets) ;
385-
386- return Some ( ( idx, data) ) ;
387- }
388-
389- None
390- }
391- }
0 commit comments