@@ -78,18 +78,16 @@ impl<'tcx> crate::MirPass<'tcx> for JumpThreading {
78
78
}
79
79
80
80
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) ;
83
81
84
- let arena = DroplessArena :: default ( ) ;
82
+ let arena = & DroplessArena :: default ( ) ;
85
83
let mut finder = TOFinder {
86
84
tcx,
87
85
param_env,
88
86
ecx : InterpCx :: new ( tcx, DUMMY_SP , param_env, DummyMachine ) ,
89
87
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 ) ,
93
91
opportunities : Vec :: new ( ) ,
94
92
} ;
95
93
@@ -105,7 +103,7 @@ impl<'tcx> crate::MirPass<'tcx> for JumpThreading {
105
103
106
104
// Verify that we do not thread through a loop header.
107
105
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) ) ) ;
109
107
}
110
108
OpportunitySet :: new ( body, opportunities) . apply ( body) ;
111
109
}
@@ -124,8 +122,8 @@ struct TOFinder<'tcx, 'a> {
124
122
param_env : ty:: ParamEnv < ' tcx > ,
125
123
ecx : InterpCx < ' tcx , DummyMachine > ,
126
124
body : & ' a Body < ' tcx > ,
127
- map : & ' a Map < ' tcx > ,
128
- loop_headers : & ' a BitSet < BasicBlock > ,
125
+ map : Map < ' tcx > ,
126
+ loop_headers : BitSet < BasicBlock > ,
129
127
/// We use an arena to avoid cloning the slices when cloning `state`.
130
128
arena : & ' a DroplessArena ,
131
129
opportunities : Vec < ThreadingOpportunity > ,
@@ -223,7 +221,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
223
221
} ) )
224
222
} ;
225
223
let conds = ConditionSet ( conds) ;
226
- state. insert_value_idx ( discr, conds, self . map ) ;
224
+ state. insert_value_idx ( discr, conds, & self . map ) ;
227
225
228
226
self . find_opportunity ( bb, state, cost, 0 ) ;
229
227
}
@@ -264,7 +262,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
264
262
// _1 = 5 // Whatever happens here, it won't change the result of a `SwitchInt`.
265
263
// _1 = 6
266
264
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 ) ;
268
266
}
269
267
}
270
268
@@ -370,7 +368,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
370
368
self . opportunities . push ( ThreadingOpportunity { chain : vec ! [ bb] , target : c. target } )
371
369
} ;
372
370
373
- if let Some ( conditions) = state. try_get_idx ( lhs, self . map )
371
+ if let Some ( conditions) = state. try_get_idx ( lhs, & self . map )
374
372
&& let Immediate :: Scalar ( Scalar :: Int ( int) ) = * rhs
375
373
{
376
374
conditions. iter_matches ( int) . for_each ( register_opportunity) ;
@@ -406,7 +404,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
406
404
}
407
405
} ,
408
406
& 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 )
410
408
&& let Ok ( imm) = self . ecx . read_immediate_raw ( op)
411
409
&& let Some ( imm) = imm. right ( )
412
410
&& let Immediate :: Scalar ( Scalar :: Int ( int) ) = * imm
@@ -441,7 +439,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
441
439
// Transfer the conditions on the copied rhs.
442
440
Operand :: Move ( rhs) | Operand :: Copy ( rhs) => {
443
441
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 ) ;
445
443
}
446
444
}
447
445
}
@@ -461,7 +459,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
461
459
Rvalue :: CopyForDeref ( rhs) => self . process_operand ( bb, lhs, & Operand :: Copy ( * rhs) , state) ,
462
460
Rvalue :: Discriminant ( rhs) => {
463
461
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 ) ;
465
463
}
466
464
// If we expect `lhs ?= A`, we have an opportunity if we assume `constant == A`.
467
465
Rvalue :: Aggregate ( box ref kind, ref operands) => {
@@ -492,10 +490,10 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
492
490
}
493
491
// Transfer the conditions on the copy rhs, after inversing polarity.
494
492
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 } ;
496
494
let Some ( place) = self . map . find ( place. as_ref ( ) ) else { return } ;
497
495
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 ) ;
499
497
}
500
498
// We expect `lhs ?= A`. We found `lhs = Eq(rhs, B)`.
501
499
// Create a condition on `rhs ?= B`.
@@ -504,7 +502,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
504
502
box ( Operand :: Move ( place) | Operand :: Copy ( place) , Operand :: Constant ( value) )
505
503
| box ( Operand :: Constant ( value) , Operand :: Move ( place) | Operand :: Copy ( place) ) ,
506
504
) => {
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 } ;
508
506
let Some ( place) = self . map . find ( place. as_ref ( ) ) else { return } ;
509
507
let equals = match op {
510
508
BinOp :: Eq => ScalarInt :: TRUE ,
@@ -528,7 +526,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
528
526
polarity : if c. matches ( equals) { Polarity :: Eq } else { Polarity :: Ne } ,
529
527
..c
530
528
} ) ;
531
- state. insert_value_idx ( place, conds, self . map ) ;
529
+ state. insert_value_idx ( place, conds, & self . map ) ;
532
530
}
533
531
534
532
_ => { }
@@ -583,7 +581,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
583
581
StatementKind :: Intrinsic ( box NonDivergingIntrinsic :: Assume (
584
582
Operand :: Copy ( place) | Operand :: Move ( place) ,
585
583
) ) => {
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 } ;
587
585
conditions. iter_matches ( ScalarInt :: TRUE ) . for_each ( register_opportunity) ;
588
586
}
589
587
StatementKind :: Assign ( box ( lhs_place, rhs) ) => {
@@ -631,7 +629,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
631
629
// We can recurse through this terminator.
632
630
let mut state = state ( ) ;
633
631
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 ) ;
635
633
}
636
634
self . find_opportunity ( bb, state, cost. clone ( ) , depth + 1 ) ;
637
635
}
@@ -650,7 +648,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
650
648
let Some ( discr) = discr. place ( ) else { return } ;
651
649
let discr_ty = discr. ty ( self . body , self . tcx ) . ty ;
652
650
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 } ;
654
652
655
653
if let Some ( ( value, _) ) = targets. iter ( ) . find ( |& ( _, target) | target == target_bb) {
656
654
let Some ( value) = ScalarInt :: try_from_uint ( value, discr_layout. size ) else { return } ;
0 commit comments