11
11
use borrow_check:: nll:: type_check;
12
12
use build;
13
13
use rustc:: hir:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
14
- use rustc:: mir:: { Mir , Promoted } ;
14
+ use rustc:: mir:: { Mir , MirPhase , Promoted } ;
15
15
use rustc:: ty:: TyCtxt ;
16
16
use rustc:: ty:: query:: Providers ;
17
17
use rustc:: ty:: steal:: Steal ;
@@ -155,53 +155,69 @@ pub trait MirPass {
155
155
mir : & mut Mir < ' tcx > ) ;
156
156
}
157
157
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
+
161
172
let source = MirSource {
162
- def_id : $def_id ,
163
- promoted
173
+ def_id,
174
+ promoted,
164
175
} ;
165
176
let mut index = 0 ;
166
177
let mut run_pass = |pass : & dyn MirPass | {
167
178
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) ,
169
180
& pass. name ( ) , source, mir, is_after) ;
170
181
} ;
171
182
run_hooks ( mir, index, false ) ;
172
- pass. run_pass ( $ tcx, source, mir) ;
183
+ pass. run_pass ( tcx, source, mir) ;
173
184
run_hooks ( mir, index, true ) ;
174
185
175
186
index += 1 ;
176
187
} ;
177
- $( run_pass ( & $pass) ; ) *
188
+
189
+ for pass in passes {
190
+ run_pass ( * pass) ;
191
+ }
192
+
193
+ mir. phase = mir_phase;
178
194
} ;
179
195
180
- run_passes ( & mut $ mir, None ) ;
196
+ run_passes ( mir, None ) ;
181
197
182
- for ( index, promoted_mir) in $ mir. promoted . iter_enumerated_mut ( ) {
198
+ for ( index, promoted_mir) in mir. promoted . iter_enumerated_mut ( ) {
183
199
run_passes ( promoted_mir, Some ( index) ) ;
184
200
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( ) )
187
203
}
188
- } }
204
+ }
189
205
190
206
fn mir_const < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> & ' tcx Steal < Mir < ' tcx > > {
191
207
// Unsafety check uses the raw mir, so make sure it is run
192
208
let _ = tcx. unsafety_check_result ( def_id) ;
193
209
194
210
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 , & [
196
212
// Remove all `EndRegion` statements that are not involved in borrows.
197
- cleanup_post_borrowck:: CleanEndRegions ,
213
+ & cleanup_post_borrowck:: CleanEndRegions ,
198
214
199
215
// 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
+ ] ) ;
205
221
tcx. alloc_steal_mir ( mir)
206
222
}
207
223
@@ -214,11 +230,11 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
214
230
}
215
231
216
232
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 , & [
218
234
// 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
+ ] ) ;
222
238
tcx. alloc_steal_mir ( mir)
223
239
}
224
240
@@ -232,59 +248,59 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
232
248
}
233
249
234
250
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 , & [
236
252
// 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 ,
240
256
// Remove all `AscribeUserType` statements.
241
- cleanup_post_borrowck:: CleanAscribeUserType ,
257
+ & cleanup_post_borrowck:: CleanAscribeUserType ,
242
258
// Remove all `FakeRead` statements and the borrows that are only
243
259
// 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" ) ,
246
262
247
263
// 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 ,
251
267
// AddValidation needs to run after ElaborateDrops and before EraseRegions, and it needs
252
268
// an AllCallEdges pass right before it.
253
- add_call_guards:: AllCallEdges ,
254
- add_validation:: AddValidation ,
269
+ & add_call_guards:: AllCallEdges ,
270
+ & add_validation:: AddValidation ,
255
271
// AddMovesForPackedDrops needs to run after drop
256
272
// elaboration.
257
- add_moves_for_packed_drops:: AddMovesForPackedDrops ,
273
+ & add_moves_for_packed_drops:: AddMovesForPackedDrops ,
258
274
259
- simplify:: SimplifyCfg :: new( "elaborate-drops" ) ,
275
+ & simplify:: SimplifyCfg :: new ( "elaborate-drops" ) ,
260
276
261
277
// No lifetime analysis based on borrowing can be done from here on out.
262
278
263
279
// From here on out, regions are gone.
264
- erase_regions:: EraseRegions ,
280
+ & erase_regions:: EraseRegions ,
265
281
266
- lower_128bit:: Lower128Bit ,
282
+ & lower_128bit:: Lower128Bit ,
267
283
268
284
269
285
// Optimizations begin.
270
- uniform_array_move_out:: RestoreSubsliceArrayMoveOut ,
271
- inline:: Inline ,
286
+ & uniform_array_move_out:: RestoreSubsliceArrayMoveOut ,
287
+ & inline:: Inline ,
272
288
273
289
// Lowering generator control-flow and variables
274
290
// 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
+ ] ) ;
289
305
tcx. alloc_mir ( mir)
290
306
}
0 commit comments