@@ -11,42 +11,59 @@ use rustc_span::symbol::Symbol;
1111use rustc_target:: abi:: FieldIdx ;
1212use rustc_target:: spec:: abi:: Abi ;
1313
14- pub struct InstSimplify ;
14+ pub enum InstSimplify {
15+ BeforeUnreachablePropagation ,
16+ Final ,
17+ }
1518
1619impl < ' tcx > MirPass < ' tcx > for InstSimplify {
20+ fn name ( & self ) -> & ' static str {
21+ match & self {
22+ InstSimplify :: BeforeUnreachablePropagation => {
23+ "InstSimplify-before-unreachable-propagation"
24+ }
25+ InstSimplify :: Final => "InstSimplify-final" ,
26+ }
27+ }
28+
1729 fn is_enabled ( & self , sess : & rustc_session:: Session ) -> bool {
1830 sess. mir_opt_level ( ) > 0
1931 }
2032
2133 fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
22- let ctx = InstSimplifyContext {
23- tcx ,
24- local_decls : & body . local_decls ,
25- param_env : tcx . param_env_reveal_all_normalized ( body . source . def_id ( ) ) ,
26- } ;
27- let preserve_ub_checks =
28- attr :: contains_name ( tcx. hir ( ) . krate_attrs ( ) , sym :: rustc_preserve_ub_checks ) ;
29- for block in body. basic_blocks . as_mut ( ) {
30- for statement in block . statements . iter_mut ( ) {
31- match statement . kind {
32- StatementKind :: Assign ( box ( _place , ref mut rvalue ) ) => {
33- if !preserve_ub_checks {
34- ctx . simplify_ub_check ( & statement . source_info , rvalue ) ;
35- }
36- ctx . simplify_bool_cmp ( & statement. source_info , rvalue ) ;
37- ctx . simplify_ref_deref ( & statement . source_info , rvalue) ;
38- ctx . simplify_len ( & statement . source_info , rvalue ) ;
39- ctx. simplify_cast ( rvalue) ;
34+ inst_simplify ( tcx , body ) ;
35+ }
36+ }
37+
38+ fn inst_simplify < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
39+ let ctx = InstSimplifyContext {
40+ tcx,
41+ local_decls : & body. local_decls ,
42+ param_env : tcx . param_env_reveal_all_normalized ( body . source . def_id ( ) ) ,
43+ } ;
44+ let preserve_ub_checks =
45+ attr :: contains_name ( tcx . hir ( ) . krate_attrs ( ) , sym :: rustc_preserve_ub_checks ) ;
46+ for block in body . basic_blocks . as_mut ( ) {
47+ for statement in block . statements . iter_mut ( ) {
48+ match statement. kind {
49+ StatementKind :: Assign ( box ( _place , ref mut rvalue) ) => {
50+ if !preserve_ub_checks {
51+ ctx. simplify_ub_check ( & statement . source_info , rvalue) ;
4052 }
41- _ => { }
53+ ctx. simplify_bool_cmp ( & statement. source_info , rvalue) ;
54+ ctx. simplify_ref_deref ( & statement. source_info , rvalue) ;
55+ ctx. simplify_len ( & statement. source_info , rvalue) ;
56+ ctx. simplify_cast ( rvalue) ;
4257 }
58+ _ => { }
4359 }
44-
45- ctx. simplify_primitive_clone ( block. terminator . as_mut ( ) . unwrap ( ) , & mut block. statements ) ;
46- ctx. simplify_intrinsic_assert ( block. terminator . as_mut ( ) . unwrap ( ) ) ;
47- ctx. simplify_nounwind_call ( block. terminator . as_mut ( ) . unwrap ( ) ) ;
48- simplify_duplicate_switch_targets ( block. terminator . as_mut ( ) . unwrap ( ) ) ;
4960 }
61+
62+ let terminator = block. terminator . as_mut ( ) . unwrap ( ) ;
63+ ctx. simplify_primitive_clone ( terminator, & mut block. statements ) ;
64+ ctx. simplify_intrinsic_assert ( terminator) ;
65+ ctx. simplify_nounwind_call ( terminator) ;
66+ simplify_duplicate_switch_targets ( terminator) ;
5067 }
5168}
5269
0 commit comments