@@ -98,21 +98,17 @@ pub struct Postorder<'a, 'tcx> {
9898 basic_blocks : & ' a IndexSlice < BasicBlock , BasicBlockData < ' tcx > > ,
9999 visited : DenseBitSet < BasicBlock > ,
100100 visit_stack : Vec < ( BasicBlock , Successors < ' a > ) > ,
101- /// A non-empty `extra` allows for a precise calculation of the successors.
102- extra : Option < ( TyCtxt < ' tcx > , Instance < ' tcx > ) > ,
103101}
104102
105103impl < ' a , ' tcx > Postorder < ' a , ' tcx > {
106104 pub fn new (
107105 basic_blocks : & ' a IndexSlice < BasicBlock , BasicBlockData < ' tcx > > ,
108106 root : BasicBlock ,
109- extra : Option < ( TyCtxt < ' tcx > , Instance < ' tcx > ) > ,
110107 ) -> Postorder < ' a , ' tcx > {
111108 let mut po = Postorder {
112109 basic_blocks,
113110 visited : DenseBitSet :: new_empty ( basic_blocks. len ( ) ) ,
114111 visit_stack : Vec :: new ( ) ,
115- extra,
116112 } ;
117113
118114 po. visit ( root) ;
@@ -126,11 +122,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
126122 return ;
127123 }
128124 let data = & self . basic_blocks [ bb] ;
129- let successors = if let Some ( extra) = self . extra {
130- data. mono_successors ( extra. 0 , extra. 1 )
131- } else {
132- data. terminator ( ) . successors ( )
133- } ;
125+ let successors = data. terminator ( ) . successors ( ) ;
134126 self . visit_stack . push ( ( bb, successors) ) ;
135127 }
136128
@@ -225,20 +217,6 @@ pub fn postorder<'a, 'tcx>(
225217 reverse_postorder ( body) . rev ( )
226218}
227219
228- pub fn mono_reachable_reverse_postorder < ' a , ' tcx > (
229- body : & ' a Body < ' tcx > ,
230- tcx : TyCtxt < ' tcx > ,
231- instance : Instance < ' tcx > ,
232- ) -> Vec < BasicBlock > {
233- let mut iter = Postorder :: new ( & body. basic_blocks , START_BLOCK , Some ( ( tcx, instance) ) ) ;
234- let mut items = Vec :: with_capacity ( body. basic_blocks . len ( ) ) ;
235- while let Some ( block) = iter. next ( ) {
236- items. push ( block) ;
237- }
238- items. reverse ( ) ;
239- items
240- }
241-
242220/// Returns an iterator over all basic blocks reachable from the `START_BLOCK` in no particular
243221/// order.
244222///
@@ -286,91 +264,3 @@ pub fn reverse_postorder<'a, 'tcx>(
286264{
287265 body. basic_blocks . reverse_postorder ( ) . iter ( ) . map ( |& bb| ( bb, & body. basic_blocks [ bb] ) )
288266}
289-
290- /// Traversal of a [`Body`] that tries to avoid unreachable blocks in a monomorphized [`Instance`].
291- ///
292- /// This is allowed to have false positives; blocks may be visited even if they are not actually
293- /// reachable.
294- ///
295- /// Such a traversal is mostly useful because it lets us skip lowering the `false` side
296- /// of `if <T as Trait>::CONST`, as well as [`NullOp::UbChecks`].
297- ///
298- /// [`NullOp::UbChecks`]: rustc_middle::mir::NullOp::UbChecks
299- pub fn mono_reachable < ' a , ' tcx > (
300- body : & ' a Body < ' tcx > ,
301- tcx : TyCtxt < ' tcx > ,
302- instance : Instance < ' tcx > ,
303- ) -> MonoReachable < ' a , ' tcx > {
304- MonoReachable :: new ( body, tcx, instance)
305- }
306-
307- /// [`MonoReachable`] internally accumulates a [`DenseBitSet`] of visited blocks. This is just a
308- /// convenience function to run that traversal then extract its set of reached blocks.
309- pub fn mono_reachable_as_bitset < ' a , ' tcx > (
310- body : & ' a Body < ' tcx > ,
311- tcx : TyCtxt < ' tcx > ,
312- instance : Instance < ' tcx > ,
313- ) -> DenseBitSet < BasicBlock > {
314- let mut iter = mono_reachable ( body, tcx, instance) ;
315- while let Some ( _) = iter. next ( ) { }
316- iter. visited
317- }
318-
319- pub struct MonoReachable < ' a , ' tcx > {
320- body : & ' a Body < ' tcx > ,
321- tcx : TyCtxt < ' tcx > ,
322- instance : Instance < ' tcx > ,
323- visited : DenseBitSet < BasicBlock > ,
324- // Other traversers track their worklist in a Vec. But we don't care about order, so we can
325- // store ours in a DenseBitSet and thus save allocations because DenseBitSet has a small size
326- // optimization.
327- worklist : DenseBitSet < BasicBlock > ,
328- }
329-
330- impl < ' a , ' tcx > MonoReachable < ' a , ' tcx > {
331- pub fn new (
332- body : & ' a Body < ' tcx > ,
333- tcx : TyCtxt < ' tcx > ,
334- instance : Instance < ' tcx > ,
335- ) -> MonoReachable < ' a , ' tcx > {
336- let mut worklist = DenseBitSet :: new_empty ( body. basic_blocks . len ( ) ) ;
337- worklist. insert ( START_BLOCK ) ;
338- MonoReachable {
339- body,
340- tcx,
341- instance,
342- visited : DenseBitSet :: new_empty ( body. basic_blocks . len ( ) ) ,
343- worklist,
344- }
345- }
346-
347- fn add_work ( & mut self , blocks : impl IntoIterator < Item = BasicBlock > ) {
348- for block in blocks. into_iter ( ) {
349- if !self . visited . contains ( block) {
350- self . worklist . insert ( block) ;
351- }
352- }
353- }
354- }
355-
356- impl < ' a , ' tcx > Iterator for MonoReachable < ' a , ' tcx > {
357- type Item = ( BasicBlock , & ' a BasicBlockData < ' tcx > ) ;
358-
359- fn next ( & mut self ) -> Option < ( BasicBlock , & ' a BasicBlockData < ' tcx > ) > {
360- while let Some ( idx) = self . worklist . iter ( ) . next ( ) {
361- self . worklist . remove ( idx) ;
362- if !self . visited . insert ( idx) {
363- continue ;
364- }
365-
366- let data = & self . body [ idx] ;
367-
368- let targets = data. mono_successors ( self . tcx , self . instance ) ;
369- self . add_work ( targets) ;
370-
371- return Some ( ( idx, data) ) ;
372- }
373-
374- None
375- }
376- }
0 commit comments