@@ -99,56 +99,46 @@ fn run_passes_inner<'tcx>(
99
99
let overridden_passes = & tcx. sess . opts . unstable_opts . mir_enable_passes ;
100
100
trace ! ( ?overridden_passes) ;
101
101
102
- if validate {
103
- validate_body ( tcx, body, format ! ( "start of phase transition from {:?}" , start_phase) ) ;
104
- }
105
-
106
102
for pass in passes {
107
103
let name = pass. name ( ) ;
108
104
109
- if let Some ( ( _ , polarity ) ) = overridden_passes . iter ( ) . rev ( ) . find ( | ( s , _ ) | s == & * name ) {
110
- trace ! (
111
- pass = % name,
112
- "{} as requested by flag" ,
113
- if * polarity { "Running" } else { "Not running" } ,
114
- ) ;
115
- if ! polarity {
116
- continue ;
117
- }
118
- } else {
119
- if ! pass. is_enabled ( & tcx. sess ) {
120
- continue ;
121
- }
122
- }
123
- let dump_enabled = pass . is_mir_dump_enabled ( ) ;
105
+ // Gather information about what we should be doing for this pass
106
+ let overriden =
107
+ overridden_passes . iter ( ) . rev ( ) . find ( | ( s , _ ) | s == & * name) . map ( | ( _name , polarity ) | {
108
+ trace ! (
109
+ pass = %name ,
110
+ "{} as requested by flag" ,
111
+ if * polarity { "Running" } else { "Not running" } ,
112
+ ) ;
113
+ * polarity
114
+ } ) ;
115
+ let is_enabled = overriden . unwrap_or_else ( || pass. is_enabled ( & tcx. sess ) ) ;
116
+ let new_phase = pass . phase_change ( ) ;
117
+ let dump_enabled = ( is_enabled && pass . is_mir_dump_enabled ( ) ) || new_phase . is_some ( ) ;
118
+ let validate = ( validate && is_enabled )
119
+ || new_phase == Some ( MirPhase :: Runtime ( RuntimePhase :: Optimized ) ) ;
124
120
125
121
if dump_enabled {
126
122
dump_mir ( tcx, body, start_phase, & name, cnt, false ) ;
127
123
}
128
-
129
- pass. run_pass ( tcx, body) ;
130
-
124
+ if is_enabled {
125
+ pass. run_pass ( tcx, body) ;
126
+ }
131
127
if dump_enabled {
132
128
dump_mir ( tcx, body, start_phase, & name, cnt, true ) ;
133
129
cnt += 1 ;
134
130
}
135
-
136
131
if let Some ( new_phase) = pass. phase_change ( ) {
137
132
if body. phase >= new_phase {
138
133
panic ! ( "Invalid MIR phase transition from {:?} to {:?}" , body. phase, new_phase) ;
139
134
}
140
135
141
136
body. phase = new_phase;
142
137
}
143
-
144
138
if validate {
145
- validate_body ( tcx, body, format ! ( "after pass {}" , pass . name( ) ) ) ;
139
+ validate_body ( tcx, body, format ! ( "after pass {}" , name) ) ;
146
140
}
147
141
}
148
-
149
- if validate || body. phase == MirPhase :: Runtime ( RuntimePhase :: Optimized ) {
150
- validate_body ( tcx, body, format ! ( "end of phase transition to {:?}" , body. phase) ) ;
151
- }
152
142
}
153
143
154
144
pub fn validate_body < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > , when : String ) {
0 commit comments