1111use borrow_check:: nll:: type_check;
1212use build;
1313use rustc:: hir:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
14- use rustc:: mir:: { Mir , Promoted } ;
14+ use rustc:: mir:: { Mir , MirPhase , Promoted } ;
1515use rustc:: ty:: TyCtxt ;
1616use rustc:: ty:: query:: Providers ;
1717use rustc:: ty:: steal:: Steal ;
@@ -155,53 +155,69 @@ pub trait MirPass {
155155 mir : & mut Mir < ' tcx > ) ;
156156}
157157
158- pub macro run_passes( $tcx: ident, $mir: ident, $def_id: ident, $suite_index: expr; $( $pass: expr, ) * ) { {
159- let suite_index: usize = $suite_index;
160- let run_passes = |mir : & mut _ , promoted| {
158+ pub fn run_passes (
159+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
160+ mir : & mut Mir < ' tcx > ,
161+ def_id : DefId ,
162+ mir_phase : MirPhase ,
163+ passes : & [ & dyn MirPass ] ,
164+ ) {
165+ let phase_index = mir_phase. phase_index ( ) ;
166+
167+ let run_passes = |mir : & mut Mir < ' tcx > , promoted| {
168+ if mir. phase >= mir_phase {
169+ return ;
170+ }
171+
161172 let source = MirSource {
162- def_id : $def_id ,
163- promoted
173+ def_id,
174+ promoted,
164175 } ;
165176 let mut index = 0 ;
166177 let mut run_pass = |pass : & dyn MirPass | {
167178 let run_hooks = |mir : & _ , index, is_after| {
168- dump_mir:: on_mir_pass ( $ tcx, & format_args ! ( "{:03}-{:03}" , suite_index , index) ,
179+ dump_mir:: on_mir_pass ( tcx, & format_args ! ( "{:03}-{:03}" , phase_index , index) ,
169180 & pass. name ( ) , source, mir, is_after) ;
170181 } ;
171182 run_hooks ( mir, index, false ) ;
172- pass. run_pass ( $ tcx, source, mir) ;
183+ pass. run_pass ( tcx, source, mir) ;
173184 run_hooks ( mir, index, true ) ;
174185
175186 index += 1 ;
176187 } ;
177- $( run_pass ( & $pass) ; ) *
188+
189+ for pass in passes {
190+ run_pass ( * pass) ;
191+ }
192+
193+ mir. phase = mir_phase;
178194 } ;
179195
180- run_passes ( & mut $ mir, None ) ;
196+ run_passes ( mir, None ) ;
181197
182- for ( index, promoted_mir) in $ mir. promoted . iter_enumerated_mut ( ) {
198+ for ( index, promoted_mir) in mir. promoted . iter_enumerated_mut ( ) {
183199 run_passes ( promoted_mir, Some ( index) ) ;
184200
185- // Let's make sure we don't miss any nested instances
186- assert ! ( promoted_mir. promoted. is_empty( ) ) ;
201+ //Let's make sure we don't miss any nested instances
202+ assert ! ( promoted_mir. promoted. is_empty( ) )
187203 }
188- } }
204+ }
189205
190206fn mir_const < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> & ' tcx Steal < Mir < ' tcx > > {
191207 // Unsafety check uses the raw mir, so make sure it is run
192208 let _ = tcx. unsafety_check_result ( def_id) ;
193209
194210 let mut mir = tcx. mir_built ( def_id) . steal ( ) ;
195- run_passes ! [ tcx, mir, def_id, 0 ;
211+ run_passes ( tcx, & mut mir, def_id, MirPhase :: Const , & [
196212 // Remove all `EndRegion` statements that are not involved in borrows.
197- cleanup_post_borrowck:: CleanEndRegions ,
213+ & cleanup_post_borrowck:: CleanEndRegions ,
198214
199215 // What we need to do constant evaluation.
200- simplify:: SimplifyCfg :: new( "initial" ) ,
201- type_check:: TypeckMir ,
202- rustc_peek:: SanityCheck ,
203- uniform_array_move_out:: UniformArrayMoveOut ,
204- ] ;
216+ & simplify:: SimplifyCfg :: new ( "initial" ) ,
217+ & type_check:: TypeckMir ,
218+ & rustc_peek:: SanityCheck ,
219+ & uniform_array_move_out:: UniformArrayMoveOut ,
220+ ] ) ;
205221 tcx. alloc_steal_mir ( mir)
206222}
207223
@@ -214,11 +230,11 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
214230 }
215231
216232 let mut mir = tcx. mir_const ( def_id) . steal ( ) ;
217- run_passes ! [ tcx, mir, def_id, 1 ;
233+ run_passes ( tcx, & mut mir, def_id, MirPhase :: Validated , & [
218234 // What we need to run borrowck etc.
219- qualify_consts:: QualifyAndPromoteConstants ,
220- simplify:: SimplifyCfg :: new( "qualify-consts" ) ,
221- ] ;
235+ & qualify_consts:: QualifyAndPromoteConstants ,
236+ & simplify:: SimplifyCfg :: new ( "qualify-consts" ) ,
237+ ] ) ;
222238 tcx. alloc_steal_mir ( mir)
223239}
224240
@@ -232,59 +248,59 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
232248 }
233249
234250 let mut mir = tcx. mir_validated ( def_id) . steal ( ) ;
235- run_passes ! [ tcx, mir, def_id, 2 ;
251+ run_passes ( tcx, & mut mir, def_id, MirPhase :: Optimized , & [
236252 // Remove all things not needed by analysis
237- no_landing_pads:: NoLandingPads ,
238- simplify_branches:: SimplifyBranches :: new( "initial" ) ,
239- remove_noop_landing_pads:: RemoveNoopLandingPads ,
253+ & no_landing_pads:: NoLandingPads ,
254+ & simplify_branches:: SimplifyBranches :: new ( "initial" ) ,
255+ & remove_noop_landing_pads:: RemoveNoopLandingPads ,
240256 // Remove all `AscribeUserType` statements.
241- cleanup_post_borrowck:: CleanAscribeUserType ,
257+ & cleanup_post_borrowck:: CleanAscribeUserType ,
242258 // Remove all `FakeRead` statements and the borrows that are only
243259 // used for checking matches
244- cleanup_post_borrowck:: CleanFakeReadsAndBorrows ,
245- simplify:: SimplifyCfg :: new( "early-opt" ) ,
260+ & cleanup_post_borrowck:: CleanFakeReadsAndBorrows ,
261+ & simplify:: SimplifyCfg :: new ( "early-opt" ) ,
246262
247263 // These next passes must be executed together
248- add_call_guards:: CriticalCallEdges ,
249- elaborate_drops:: ElaborateDrops ,
250- no_landing_pads:: NoLandingPads ,
264+ & add_call_guards:: CriticalCallEdges ,
265+ & elaborate_drops:: ElaborateDrops ,
266+ & no_landing_pads:: NoLandingPads ,
251267 // AddValidation needs to run after ElaborateDrops and before EraseRegions, and it needs
252268 // an AllCallEdges pass right before it.
253- add_call_guards:: AllCallEdges ,
254- add_validation:: AddValidation ,
269+ & add_call_guards:: AllCallEdges ,
270+ & add_validation:: AddValidation ,
255271 // AddMovesForPackedDrops needs to run after drop
256272 // elaboration.
257- add_moves_for_packed_drops:: AddMovesForPackedDrops ,
273+ & add_moves_for_packed_drops:: AddMovesForPackedDrops ,
258274
259- simplify:: SimplifyCfg :: new( "elaborate-drops" ) ,
275+ & simplify:: SimplifyCfg :: new ( "elaborate-drops" ) ,
260276
261277 // No lifetime analysis based on borrowing can be done from here on out.
262278
263279 // From here on out, regions are gone.
264- erase_regions:: EraseRegions ,
280+ & erase_regions:: EraseRegions ,
265281
266- lower_128bit:: Lower128Bit ,
282+ & lower_128bit:: Lower128Bit ,
267283
268284
269285 // Optimizations begin.
270- uniform_array_move_out:: RestoreSubsliceArrayMoveOut ,
271- inline:: Inline ,
286+ & uniform_array_move_out:: RestoreSubsliceArrayMoveOut ,
287+ & inline:: Inline ,
272288
273289 // Lowering generator control-flow and variables
274290 // has to happen before we do anything else to them.
275- generator:: StateTransform ,
276-
277- instcombine:: InstCombine ,
278- const_prop:: ConstProp ,
279- simplify_branches:: SimplifyBranches :: new( "after-const-prop" ) ,
280- deaggregator:: Deaggregator ,
281- copy_prop:: CopyPropagation ,
282- remove_noop_landing_pads:: RemoveNoopLandingPads ,
283- simplify:: SimplifyCfg :: new( "final" ) ,
284- simplify:: SimplifyLocals ,
285-
286- add_call_guards:: CriticalCallEdges ,
287- dump_mir:: Marker ( "PreCodegen" ) ,
288- ] ;
291+ & generator:: StateTransform ,
292+
293+ & instcombine:: InstCombine ,
294+ & const_prop:: ConstProp ,
295+ & simplify_branches:: SimplifyBranches :: new ( "after-const-prop" ) ,
296+ & deaggregator:: Deaggregator ,
297+ & copy_prop:: CopyPropagation ,
298+ & remove_noop_landing_pads:: RemoveNoopLandingPads ,
299+ & simplify:: SimplifyCfg :: new ( "final" ) ,
300+ & simplify:: SimplifyLocals ,
301+
302+ & add_call_guards:: CriticalCallEdges ,
303+ & dump_mir:: Marker ( "PreCodegen" ) ,
304+ ] ) ;
289305 tcx. alloc_mir ( mir)
290306}
0 commit comments