11//! Performs various peephole optimizations.
22
3- use crate :: simplify:: combine_duplicate_switch_targets ;
3+ use crate :: simplify:: simplify_duplicate_switch_targets ;
44use crate :: MirPass ;
55use rustc_hir:: Mutability ;
66use rustc_middle:: mir:: * ;
@@ -10,15 +10,15 @@ use rustc_middle::ty::{self, ParamEnv, SubstsRef, Ty, TyCtxt};
1010use rustc_span:: symbol:: Symbol ;
1111use rustc_target:: abi:: FieldIdx ;
1212
13- pub struct InstCombine ;
13+ pub struct InstSimplify ;
1414
15- impl < ' tcx > MirPass < ' tcx > for InstCombine {
15+ impl < ' tcx > MirPass < ' tcx > for InstSimplify {
1616 fn is_enabled ( & self , sess : & rustc_session:: Session ) -> bool {
1717 sess. mir_opt_level ( ) > 0
1818 }
1919
2020 fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
21- let ctx = InstCombineContext {
21+ let ctx = InstSimplifyContext {
2222 tcx,
2323 local_decls : & body. local_decls ,
2424 param_env : tcx. param_env_reveal_all_normalized ( body. source . def_id ( ) ) ,
@@ -27,43 +27,43 @@ impl<'tcx> MirPass<'tcx> for InstCombine {
2727 for statement in block. statements . iter_mut ( ) {
2828 match statement. kind {
2929 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) ;
3434 }
3535 _ => { }
3636 }
3737 }
3838
39- ctx. combine_primitive_clone (
39+ ctx. simplify_primitive_clone (
4040 & mut block. terminator . as_mut ( ) . unwrap ( ) ,
4141 & mut block. statements ,
4242 ) ;
43- ctx. combine_intrinsic_assert (
43+ ctx. simplify_intrinsic_assert (
4444 & mut block. terminator . as_mut ( ) . unwrap ( ) ,
4545 & mut block. statements ,
4646 ) ;
47- combine_duplicate_switch_targets ( block. terminator . as_mut ( ) . unwrap ( ) ) ;
47+ simplify_duplicate_switch_targets ( block. terminator . as_mut ( ) . unwrap ( ) ) ;
4848 }
4949 }
5050}
5151
52- struct InstCombineContext < ' tcx , ' a > {
52+ struct InstSimplifyContext < ' tcx , ' a > {
5353 tcx : TyCtxt < ' tcx > ,
5454 local_decls : & ' a LocalDecls < ' tcx > ,
5555 param_env : ParamEnv < ' tcx > ,
5656}
5757
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 {
6060 self . tcx . consider_optimizing ( || {
61- format ! ( "InstCombine - Rvalue: {:?} SourceInfo: {:?}" , rvalue, source_info)
61+ format ! ( "InstSimplify - Rvalue: {:?} SourceInfo: {:?}" , rvalue, source_info)
6262 } )
6363 }
6464
6565 /// 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 > ) {
6767 match rvalue {
6868 Rvalue :: BinaryOp ( op @ ( BinOp :: Eq | BinOp :: Ne ) , box ( a, b) ) => {
6969 let new = match ( op, self . try_eval_bool ( a) , self . try_eval_bool ( b) ) {
@@ -94,7 +94,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
9494 _ => None ,
9595 } ;
9696
97- if let Some ( new) = new && self . should_combine ( source_info, rvalue) {
97+ if let Some ( new) = new && self . should_simplify ( source_info, rvalue) {
9898 * rvalue = new;
9999 }
100100 }
@@ -109,14 +109,14 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
109109 }
110110
111111 /// 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 > ) {
113113 if let Rvalue :: Ref ( _, _, place) = rvalue {
114114 if let Some ( ( base, ProjectionElem :: Deref ) ) = place. as_ref ( ) . last_projection ( ) {
115115 if rvalue. ty ( self . local_decls , self . tcx ) != base. ty ( self . local_decls , self . tcx ) . ty {
116116 return ;
117117 }
118118
119- if !self . should_combine ( source_info, rvalue) {
119+ if !self . should_simplify ( source_info, rvalue) {
120120 return ;
121121 }
122122
@@ -129,11 +129,11 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
129129 }
130130
131131 /// 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 > ) {
133133 if let Rvalue :: Len ( ref place) = * rvalue {
134134 let place_ty = place. ty ( self . local_decls , self . tcx ) . ty ;
135135 if let ty:: Array ( _, len) = * place_ty. kind ( ) {
136- if !self . should_combine ( source_info, rvalue) {
136+ if !self . should_simplify ( source_info, rvalue) {
137137 return ;
138138 }
139139
@@ -144,7 +144,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
144144 }
145145 }
146146
147- fn combine_cast ( & self , _source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
147+ fn simplify_cast ( & self , _source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
148148 if let Rvalue :: Cast ( kind, operand, cast_ty) = rvalue {
149149 let operand_ty = operand. ty ( self . local_decls , self . tcx ) ;
150150 if operand_ty == * cast_ty {
@@ -196,7 +196,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
196196 }
197197 }
198198
199- fn combine_primitive_clone (
199+ fn simplify_primitive_clone (
200200 & self ,
201201 terminator : & mut Terminator < ' tcx > ,
202202 statements : & mut Vec < Statement < ' tcx > > ,
@@ -239,7 +239,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
239239
240240 if !self . tcx . consider_optimizing ( || {
241241 format ! (
242- "InstCombine - Call: {:?} SourceInfo: {:?}" ,
242+ "InstSimplify - Call: {:?} SourceInfo: {:?}" ,
243243 ( fn_def_id, fn_substs) ,
244244 terminator. source_info
245245 )
@@ -262,7 +262,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
262262 terminator. kind = TerminatorKind :: Goto { target : destination_block } ;
263263 }
264264
265- fn combine_intrinsic_assert (
265+ fn simplify_intrinsic_assert (
266266 & self ,
267267 terminator : & mut Terminator < ' tcx > ,
268268 _statements : & mut Vec < Statement < ' tcx > > ,
0 commit comments