1
1
//! Performs various peephole optimizations.
2
2
3
- use crate :: simplify:: combine_duplicate_switch_targets ;
3
+ use crate :: simplify:: simplify_duplicate_switch_targets ;
4
4
use crate :: MirPass ;
5
5
use rustc_hir:: Mutability ;
6
6
use rustc_middle:: mir:: * ;
@@ -10,15 +10,15 @@ use rustc_middle::ty::{self, ParamEnv, SubstsRef, Ty, TyCtxt};
10
10
use rustc_span:: symbol:: Symbol ;
11
11
use rustc_target:: abi:: FieldIdx ;
12
12
13
- pub struct InstCombine ;
13
+ pub struct InstSimplify ;
14
14
15
- impl < ' tcx > MirPass < ' tcx > for InstCombine {
15
+ impl < ' tcx > MirPass < ' tcx > for InstSimplify {
16
16
fn is_enabled ( & self , sess : & rustc_session:: Session ) -> bool {
17
17
sess. mir_opt_level ( ) > 0
18
18
}
19
19
20
20
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
21
- let ctx = InstCombineContext {
21
+ let ctx = InstSimplifyContext {
22
22
tcx,
23
23
local_decls : & body. local_decls ,
24
24
param_env : tcx. param_env_reveal_all_normalized ( body. source . def_id ( ) ) ,
@@ -27,43 +27,43 @@ impl<'tcx> MirPass<'tcx> for InstCombine {
27
27
for statement in block. statements . iter_mut ( ) {
28
28
match statement. kind {
29
29
StatementKind :: Assign ( box ( _place, ref mut rvalue) ) => {
30
- ctx. combine_bool_cmp ( & statement. source_info , rvalue) ;
31
- ctx. combine_ref_deref ( & statement. source_info , rvalue) ;
32
- ctx. combine_len ( & statement. source_info , rvalue) ;
33
- ctx. combine_cast ( & statement. source_info , rvalue) ;
30
+ ctx. simplify_bool_cmp ( & statement. source_info , rvalue) ;
31
+ ctx. simplify_ref_deref ( & statement. source_info , rvalue) ;
32
+ ctx. simplify_len ( & statement. source_info , rvalue) ;
33
+ ctx. simplify_cast ( & statement. source_info , rvalue) ;
34
34
}
35
35
_ => { }
36
36
}
37
37
}
38
38
39
- ctx. combine_primitive_clone (
39
+ ctx. simplify_primitive_clone (
40
40
& mut block. terminator . as_mut ( ) . unwrap ( ) ,
41
41
& mut block. statements ,
42
42
) ;
43
- ctx. combine_intrinsic_assert (
43
+ ctx. simplify_intrinsic_assert (
44
44
& mut block. terminator . as_mut ( ) . unwrap ( ) ,
45
45
& mut block. statements ,
46
46
) ;
47
- combine_duplicate_switch_targets ( block. terminator . as_mut ( ) . unwrap ( ) ) ;
47
+ simplify_duplicate_switch_targets ( block. terminator . as_mut ( ) . unwrap ( ) ) ;
48
48
}
49
49
}
50
50
}
51
51
52
- struct InstCombineContext < ' tcx , ' a > {
52
+ struct InstSimplifyContext < ' tcx , ' a > {
53
53
tcx : TyCtxt < ' tcx > ,
54
54
local_decls : & ' a LocalDecls < ' tcx > ,
55
55
param_env : ParamEnv < ' tcx > ,
56
56
}
57
57
58
- impl < ' tcx > InstCombineContext < ' tcx , ' _ > {
59
- fn should_combine ( & self , source_info : & SourceInfo , rvalue : & Rvalue < ' tcx > ) -> bool {
58
+ impl < ' tcx > InstSimplifyContext < ' tcx , ' _ > {
59
+ fn should_simplify ( & self , source_info : & SourceInfo , rvalue : & Rvalue < ' tcx > ) -> bool {
60
60
self . tcx . consider_optimizing ( || {
61
- format ! ( "InstCombine - Rvalue: {:?} SourceInfo: {:?}" , rvalue, source_info)
61
+ format ! ( "InstSimplify - Rvalue: {:?} SourceInfo: {:?}" , rvalue, source_info)
62
62
} )
63
63
}
64
64
65
65
/// Transform boolean comparisons into logical operations.
66
- fn combine_bool_cmp ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
66
+ fn simplify_bool_cmp ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
67
67
match rvalue {
68
68
Rvalue :: BinaryOp ( op @ ( BinOp :: Eq | BinOp :: Ne ) , box ( a, b) ) => {
69
69
let new = match ( op, self . try_eval_bool ( a) , self . try_eval_bool ( b) ) {
@@ -94,7 +94,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
94
94
_ => None ,
95
95
} ;
96
96
97
- if let Some ( new) = new && self . should_combine ( source_info, rvalue) {
97
+ if let Some ( new) = new && self . should_simplify ( source_info, rvalue) {
98
98
* rvalue = new;
99
99
}
100
100
}
@@ -109,14 +109,14 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
109
109
}
110
110
111
111
/// Transform "&(*a)" ==> "a".
112
- fn combine_ref_deref ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
112
+ fn simplify_ref_deref ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
113
113
if let Rvalue :: Ref ( _, _, place) = rvalue {
114
114
if let Some ( ( base, ProjectionElem :: Deref ) ) = place. as_ref ( ) . last_projection ( ) {
115
115
if rvalue. ty ( self . local_decls , self . tcx ) != base. ty ( self . local_decls , self . tcx ) . ty {
116
116
return ;
117
117
}
118
118
119
- if !self . should_combine ( source_info, rvalue) {
119
+ if !self . should_simplify ( source_info, rvalue) {
120
120
return ;
121
121
}
122
122
@@ -129,11 +129,11 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
129
129
}
130
130
131
131
/// Transform "Len([_; N])" ==> "N".
132
- fn combine_len ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
132
+ fn simplify_len ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
133
133
if let Rvalue :: Len ( ref place) = * rvalue {
134
134
let place_ty = place. ty ( self . local_decls , self . tcx ) . ty ;
135
135
if let ty:: Array ( _, len) = * place_ty. kind ( ) {
136
- if !self . should_combine ( source_info, rvalue) {
136
+ if !self . should_simplify ( source_info, rvalue) {
137
137
return ;
138
138
}
139
139
@@ -144,7 +144,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
144
144
}
145
145
}
146
146
147
- fn combine_cast ( & self , _source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
147
+ fn simplify_cast ( & self , _source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
148
148
if let Rvalue :: Cast ( kind, operand, cast_ty) = rvalue {
149
149
let operand_ty = operand. ty ( self . local_decls , self . tcx ) ;
150
150
if operand_ty == * cast_ty {
@@ -196,7 +196,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
196
196
}
197
197
}
198
198
199
- fn combine_primitive_clone (
199
+ fn simplify_primitive_clone (
200
200
& self ,
201
201
terminator : & mut Terminator < ' tcx > ,
202
202
statements : & mut Vec < Statement < ' tcx > > ,
@@ -239,7 +239,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
239
239
240
240
if !self . tcx . consider_optimizing ( || {
241
241
format ! (
242
- "InstCombine - Call: {:?} SourceInfo: {:?}" ,
242
+ "InstSimplify - Call: {:?} SourceInfo: {:?}" ,
243
243
( fn_def_id, fn_substs) ,
244
244
terminator. source_info
245
245
)
@@ -262,7 +262,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
262
262
terminator. kind = TerminatorKind :: Goto { target : destination_block } ;
263
263
}
264
264
265
- fn combine_intrinsic_assert (
265
+ fn simplify_intrinsic_assert (
266
266
& self ,
267
267
terminator : & mut Terminator < ' tcx > ,
268
268
_statements : & mut Vec < Statement < ' tcx > > ,
0 commit comments