@@ -623,92 +623,14 @@ impl<'a, 'tcx> MirNeighborCollector<'a, 'tcx> {
623
623
value,
624
624
)
625
625
}
626
-
627
- fn find_reachable_blocks ( & mut self , bb : mir:: BasicBlock ) {
628
- if !self . reachable_blocks . insert ( bb) {
629
- return ;
630
- }
631
-
632
- use mir:: TerminatorKind :: * ;
633
- let data = & self . body . basic_blocks ( ) [ bb] ;
634
- match data. terminator ( ) . kind {
635
- Goto { target } => self . find_reachable_blocks ( target) ,
636
- Resume | Abort | Return | Unreachable | GeneratorDrop => ( ) ,
637
- Drop { place : _, target, unwind }
638
- | DropAndReplace { place : _, value : _, target, unwind }
639
- | Assert { cond : _, expected : _, msg : _, target, cleanup : unwind }
640
- | Yield { value : _, resume : target, resume_arg : _, drop : unwind } => {
641
- self . find_reachable_blocks ( target) ;
642
- unwind. map ( |b| self . find_reachable_blocks ( b) ) ;
643
- }
644
- Call { func : _, args : _, destination, cleanup, from_hir_call : _, fn_span : _} => {
645
- destination. map ( |( _, b) | self . find_reachable_blocks ( b) ) ;
646
- cleanup. map ( |b| self . find_reachable_blocks ( b) ) ;
647
- }
648
- FalseEdge { .. } | FalseUnwind { .. } => {
649
- bug ! ( "Expected false edges to already be gone when collecting neighbours for {:?}" , self . instance) ;
650
- }
651
- InlineAsm { template : _, operands : _, options : _, line_spans : _, destination} => {
652
- destination. map ( |b| self . find_reachable_blocks ( b) ) ;
653
- }
654
- SwitchInt { ref discr, switch_ty, ref targets } => {
655
- if let mir:: Operand :: Constant ( constant) = discr {
656
- if let Some ( raw_value) = self . try_eval_constant_to_bits ( constant, switch_ty) {
657
- // We know what this is going to be,
658
- // so we can ignore all the other blocks.
659
- for ( test_value, target) in targets. iter ( ) {
660
- if test_value == raw_value {
661
- return self . find_reachable_blocks ( target) ;
662
- }
663
- }
664
-
665
- return self . find_reachable_blocks ( targets. otherwise ( ) ) ;
666
- }
667
- }
668
-
669
- // If it's not a constant or we can't evaluate it,
670
- // then we have to consider them all as reachable.
671
- for & b in targets. all_targets ( ) {
672
- self . find_reachable_blocks ( b)
673
- }
674
- }
675
- }
676
- }
677
-
678
- fn try_eval_constant_to_bits ( & self , constant : & mir:: Constant < ' tcx > , ty : Ty < ' tcx > ) -> Option < u128 > {
679
- let env = ty:: ParamEnv :: reveal_all ( ) ;
680
- let ct = self . monomorphize ( constant. literal ) ;
681
- let value = match ct {
682
- mir:: ConstantKind :: Val ( value, _) => value,
683
- mir:: ConstantKind :: Ty ( ct) => {
684
- match ct. val {
685
- ty:: ConstKind :: Unevaluated ( ct) => self
686
- . tcx
687
- . const_eval_resolve ( env, ct, None ) . ok ( ) ?,
688
- ty:: ConstKind :: Value ( value) => value,
689
- other => span_bug ! (
690
- constant. span,
691
- "encountered bad ConstKind after monomorphizing: {:?}" ,
692
- other
693
- ) ,
694
- }
695
- }
696
- } ;
697
- value. try_to_bits_for_ty ( self . tcx , env, ty)
698
- }
699
626
}
700
627
701
628
impl < ' a , ' tcx > MirVisitor < ' tcx > for MirNeighborCollector < ' a , ' tcx > {
702
- fn visit_body ( & mut self , body : & mir:: Body < ' tcx > ) {
703
- self . find_reachable_blocks ( mir:: START_BLOCK ) ;
704
- self . super_body ( body) ;
705
- }
706
-
707
629
fn visit_basic_block_data ( & mut self , block : mir:: BasicBlock , data : & mir:: BasicBlockData < ' tcx > ) {
708
630
if self . reachable_blocks . contains ( block) {
709
631
self . super_basic_block_data ( block, data) ;
710
632
} else {
711
- debug ! ( "skipping basic block {:?}" , block) ;
633
+ debug ! ( "skipping mono-unreachable basic block {:?}" , block) ;
712
634
}
713
635
}
714
636
@@ -1482,15 +1404,9 @@ fn collect_neighbours<'tcx>(
1482
1404
debug ! ( "collect_neighbours: {:?}" , instance. def_id( ) ) ;
1483
1405
let body = tcx. instance_mir ( instance. def ) ;
1484
1406
1485
- let reachable_blocks =
1486
- if instance. substs . is_noop ( ) {
1487
- // If it's non-generic, then it's already filtered out
1488
- // any blocks that are unreachable, so don't re-do the work.
1489
- BitSet :: new_filled ( body. basic_blocks ( ) . len ( ) )
1490
- } else {
1491
- BitSet :: new_empty ( body. basic_blocks ( ) . len ( ) )
1492
- } ;
1493
- let mut collector = MirNeighborCollector { tcx, body : & body, output, instance, reachable_blocks } ;
1407
+ let reachable_blocks = body. reachable_blocks_in_mono ( tcx, instance) ;
1408
+ let mut collector =
1409
+ MirNeighborCollector { tcx, body : & body, output, instance, reachable_blocks } ;
1494
1410
collector. visit_body ( & body) ;
1495
1411
}
1496
1412
0 commit comments