File tree 3 files changed +17
-16
lines changed
compiler/rustc_mir/src/transform
3 files changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -14,14 +14,9 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
14
14
return ;
15
15
}
16
16
17
- if !tcx. consider_optimizing ( || {
18
- format ! ( "MultipleReturnTerminators {:?} " , body. source. def_id( ) )
19
- } ) {
20
- return ;
21
- }
22
-
23
17
// find basic blocks with no statement and a return terminator
24
18
let mut bbs_simple_returns = BitSet :: new_empty ( body. basic_blocks ( ) . len ( ) ) ;
19
+ let def_id = body. source . def_id ( ) ;
25
20
let bbs = body. basic_blocks_mut ( ) ;
26
21
for idx in bbs. indices ( ) {
27
22
if bbs[ idx] . statements . is_empty ( )
@@ -32,6 +27,10 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
32
27
}
33
28
34
29
for bb in bbs {
30
+ if !tcx. consider_optimizing ( || format ! ( "MultipleReturnTerminators {:?} " , def_id) ) {
31
+ break ;
32
+ }
33
+
35
34
if let TerminatorKind :: Goto { target } = bb. terminator ( ) . kind {
36
35
if bbs_simple_returns. contains ( target) {
37
36
bb. terminator_mut ( ) . kind = TerminatorKind :: Return ;
Original file line number Diff line number Diff line change @@ -11,10 +11,6 @@ pub struct RemoveUnneededDrops;
11
11
12
12
impl < ' tcx > MirPass < ' tcx > for RemoveUnneededDrops {
13
13
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
14
- if !tcx. consider_optimizing ( || format ! ( "RemoveUnneededDrops {:?} " , body. source. def_id( ) ) ) {
15
- return ;
16
- }
17
-
18
14
trace ! ( "Running RemoveUnneededDrops on {:?}" , body. source) ;
19
15
let mut opt_finder = RemoveUnneededDropsOptimizationFinder {
20
16
tcx,
@@ -25,6 +21,12 @@ impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
25
21
opt_finder. visit_body ( body) ;
26
22
let should_simplify = !opt_finder. optimizations . is_empty ( ) ;
27
23
for ( loc, target) in opt_finder. optimizations {
24
+ if !tcx
25
+ . consider_optimizing ( || format ! ( "RemoveUnneededDrops {:?} " , body. source. def_id( ) ) )
26
+ {
27
+ break ;
28
+ }
29
+
28
30
let terminator = body. basic_blocks_mut ( ) [ loc. block ] . terminator_mut ( ) ;
29
31
debug ! ( "SUCCESS: replacing `drop` with goto({:?})" , target) ;
30
32
terminator. kind = TerminatorKind :: Goto { target } ;
Original file line number Diff line number Diff line change @@ -18,12 +18,6 @@ impl MirPass<'_> for UnreachablePropagation {
18
18
return ;
19
19
}
20
20
21
- if !tcx
22
- . consider_optimizing ( || format ! ( "UnreachablePropagation {:?} " , body. source. def_id( ) ) )
23
- {
24
- return ;
25
- }
26
-
27
21
let mut unreachable_blocks = FxHashSet :: default ( ) ;
28
22
let mut replacements = FxHashMap :: default ( ) ;
29
23
@@ -56,6 +50,12 @@ impl MirPass<'_> for UnreachablePropagation {
56
50
57
51
let replaced = !replacements. is_empty ( ) ;
58
52
for ( bb, terminator_kind) in replacements {
53
+ if !tcx. consider_optimizing ( || {
54
+ format ! ( "UnreachablePropagation {:?} " , body. source. def_id( ) )
55
+ } ) {
56
+ break ;
57
+ }
58
+
59
59
body. basic_blocks_mut ( ) [ bb] . terminator_mut ( ) . kind = terminator_kind;
60
60
}
61
61
You can’t perform that action at this time.
0 commit comments