@@ -78,18 +78,16 @@ impl<'tcx> crate::MirPass<'tcx> for JumpThreading {
7878 }
7979
8080 let param_env = tcx. param_env_reveal_all_normalized ( def_id) ;
81- let map = Map :: new ( tcx, body, Some ( MAX_PLACES ) ) ;
82- let loop_headers = loop_headers ( body) ;
8381
84- let arena = DroplessArena :: default ( ) ;
82+ let arena = & DroplessArena :: default ( ) ;
8583 let mut finder = TOFinder {
8684 tcx,
8785 param_env,
8886 ecx : InterpCx :: new ( tcx, DUMMY_SP , param_env, DummyMachine ) ,
8987 body,
90- arena : & arena ,
91- map : & map ,
92- loop_headers : & loop_headers,
88+ arena,
89+ map : Map :: new ( tcx , body , Some ( MAX_PLACES ) ) ,
90+ loop_headers : loop_headers ( body ) ,
9391 opportunities : Vec :: new ( ) ,
9492 } ;
9593
@@ -105,7 +103,7 @@ impl<'tcx> crate::MirPass<'tcx> for JumpThreading {
105103
106104 // Verify that we do not thread through a loop header.
107105 for to in opportunities. iter ( ) {
108- assert ! ( to. chain. iter( ) . all( |& block| !loop_headers. contains( block) ) ) ;
106+ assert ! ( to. chain. iter( ) . all( |& block| !finder . loop_headers. contains( block) ) ) ;
109107 }
110108 OpportunitySet :: new ( body, opportunities) . apply ( body) ;
111109 }
@@ -124,8 +122,8 @@ struct TOFinder<'tcx, 'a> {
124122 param_env : ty:: ParamEnv < ' tcx > ,
125123 ecx : InterpCx < ' tcx , DummyMachine > ,
126124 body : & ' a Body < ' tcx > ,
127- map : & ' a Map < ' tcx > ,
128- loop_headers : & ' a BitSet < BasicBlock > ,
125+ map : Map < ' tcx > ,
126+ loop_headers : BitSet < BasicBlock > ,
129127 /// We use an arena to avoid cloning the slices when cloning `state`.
130128 arena : & ' a DroplessArena ,
131129 opportunities : Vec < ThreadingOpportunity > ,
@@ -223,7 +221,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
223221 } ) )
224222 } ;
225223 let conds = ConditionSet ( conds) ;
226- state. insert_value_idx ( discr, conds, self . map ) ;
224+ state. insert_value_idx ( discr, conds, & self . map ) ;
227225
228226 self . find_opportunity ( bb, state, cost, 0 ) ;
229227 }
@@ -264,7 +262,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
264262 // _1 = 5 // Whatever happens here, it won't change the result of a `SwitchInt`.
265263 // _1 = 6
266264 if let Some ( ( lhs, tail) ) = self . mutated_statement ( stmt) {
267- state. flood_with_tail_elem ( lhs. as_ref ( ) , tail, self . map , ConditionSet :: BOTTOM ) ;
265+ state. flood_with_tail_elem ( lhs. as_ref ( ) , tail, & self . map , ConditionSet :: BOTTOM ) ;
268266 }
269267 }
270268
@@ -370,7 +368,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
370368 self . opportunities . push ( ThreadingOpportunity { chain : vec ! [ bb] , target : c. target } )
371369 } ;
372370
373- if let Some ( conditions) = state. try_get_idx ( lhs, self . map )
371+ if let Some ( conditions) = state. try_get_idx ( lhs, & self . map )
374372 && let Immediate :: Scalar ( Scalar :: Int ( int) ) = * rhs
375373 {
376374 conditions. iter_matches ( int) . for_each ( register_opportunity) ;
@@ -406,7 +404,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
406404 }
407405 } ,
408406 & mut |place, op| {
409- if let Some ( conditions) = state. try_get_idx ( place, self . map )
407+ if let Some ( conditions) = state. try_get_idx ( place, & self . map )
410408 && let Ok ( imm) = self . ecx . read_immediate_raw ( op)
411409 && let Some ( imm) = imm. right ( )
412410 && let Immediate :: Scalar ( Scalar :: Int ( int) ) = * imm
@@ -441,7 +439,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
441439 // Transfer the conditions on the copied rhs.
442440 Operand :: Move ( rhs) | Operand :: Copy ( rhs) => {
443441 let Some ( rhs) = self . map . find ( rhs. as_ref ( ) ) else { return } ;
444- state. insert_place_idx ( rhs, lhs, self . map ) ;
442+ state. insert_place_idx ( rhs, lhs, & self . map ) ;
445443 }
446444 }
447445 }
@@ -461,7 +459,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
461459 Rvalue :: CopyForDeref ( rhs) => self . process_operand ( bb, lhs, & Operand :: Copy ( * rhs) , state) ,
462460 Rvalue :: Discriminant ( rhs) => {
463461 let Some ( rhs) = self . map . find_discr ( rhs. as_ref ( ) ) else { return } ;
464- state. insert_place_idx ( rhs, lhs, self . map ) ;
462+ state. insert_place_idx ( rhs, lhs, & self . map ) ;
465463 }
466464 // If we expect `lhs ?= A`, we have an opportunity if we assume `constant == A`.
467465 Rvalue :: Aggregate ( box ref kind, ref operands) => {
@@ -492,10 +490,10 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
492490 }
493491 // Transfer the conditions on the copy rhs, after inversing polarity.
494492 Rvalue :: UnaryOp ( UnOp :: Not , Operand :: Move ( place) | Operand :: Copy ( place) ) => {
495- let Some ( conditions) = state. try_get_idx ( lhs, self . map ) else { return } ;
493+ let Some ( conditions) = state. try_get_idx ( lhs, & self . map ) else { return } ;
496494 let Some ( place) = self . map . find ( place. as_ref ( ) ) else { return } ;
497495 let conds = conditions. map ( self . arena , Condition :: inv) ;
498- state. insert_value_idx ( place, conds, self . map ) ;
496+ state. insert_value_idx ( place, conds, & self . map ) ;
499497 }
500498 // We expect `lhs ?= A`. We found `lhs = Eq(rhs, B)`.
501499 // Create a condition on `rhs ?= B`.
@@ -504,7 +502,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
504502 box ( Operand :: Move ( place) | Operand :: Copy ( place) , Operand :: Constant ( value) )
505503 | box ( Operand :: Constant ( value) , Operand :: Move ( place) | Operand :: Copy ( place) ) ,
506504 ) => {
507- let Some ( conditions) = state. try_get_idx ( lhs, self . map ) else { return } ;
505+ let Some ( conditions) = state. try_get_idx ( lhs, & self . map ) else { return } ;
508506 let Some ( place) = self . map . find ( place. as_ref ( ) ) else { return } ;
509507 let equals = match op {
510508 BinOp :: Eq => ScalarInt :: TRUE ,
@@ -528,7 +526,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
528526 polarity : if c. matches ( equals) { Polarity :: Eq } else { Polarity :: Ne } ,
529527 ..c
530528 } ) ;
531- state. insert_value_idx ( place, conds, self . map ) ;
529+ state. insert_value_idx ( place, conds, & self . map ) ;
532530 }
533531
534532 _ => { }
@@ -583,7 +581,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
583581 StatementKind :: Intrinsic ( box NonDivergingIntrinsic :: Assume (
584582 Operand :: Copy ( place) | Operand :: Move ( place) ,
585583 ) ) => {
586- let Some ( conditions) = state. try_get ( place. as_ref ( ) , self . map ) else { return } ;
584+ let Some ( conditions) = state. try_get ( place. as_ref ( ) , & self . map ) else { return } ;
587585 conditions. iter_matches ( ScalarInt :: TRUE ) . for_each ( register_opportunity) ;
588586 }
589587 StatementKind :: Assign ( box ( lhs_place, rhs) ) => {
@@ -631,7 +629,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
631629 // We can recurse through this terminator.
632630 let mut state = state ( ) ;
633631 if let Some ( place_to_flood) = place_to_flood {
634- state. flood_with ( place_to_flood. as_ref ( ) , self . map , ConditionSet :: BOTTOM ) ;
632+ state. flood_with ( place_to_flood. as_ref ( ) , & self . map , ConditionSet :: BOTTOM ) ;
635633 }
636634 self . find_opportunity ( bb, state, cost. clone ( ) , depth + 1 ) ;
637635 }
@@ -650,7 +648,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
650648 let Some ( discr) = discr. place ( ) else { return } ;
651649 let discr_ty = discr. ty ( self . body , self . tcx ) . ty ;
652650 let Ok ( discr_layout) = self . ecx . layout_of ( discr_ty) else { return } ;
653- let Some ( conditions) = state. try_get ( discr. as_ref ( ) , self . map ) else { return } ;
651+ let Some ( conditions) = state. try_get ( discr. as_ref ( ) , & self . map ) else { return } ;
654652
655653 if let Some ( ( value, _) ) = targets. iter ( ) . find ( |& ( _, target) | target == target_bb) {
656654 let Some ( value) = ScalarInt :: try_from_uint ( value, discr_layout. size ) else { return } ;
0 commit comments