@@ -155,68 +155,68 @@ pub trait MirPass {
155
155
mir : & mut Mir < ' tcx > ) ;
156
156
}
157
157
158
- pub macro run_passes(
159
- $tcx: ident,
160
- $mir: ident,
161
- $def_id: ident,
162
- $mir_phase: expr;
163
- $( $pass: expr, ) *
164
- ) { {
165
- let phase_index = $mir_phase. phase_index ( ) ;
166
-
167
- let run_passes = |mir : & mut _ , promoted| {
168
- let mir: & mut Mir < ' _ > = mir;
169
-
170
- if mir. phase >= $mir_phase {
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
+ let phase_index = mir_phase. phase_index ( ) ;
165
+
166
+ let run_passes = |mir : & mut Mir < ' tcx > , promoted| {
167
+ if mir. phase >= mir_phase {
171
168
return ;
172
169
}
173
170
174
171
let source = MirSource {
175
- def_id : $def_id ,
176
- promoted
172
+ def_id,
173
+ promoted,
177
174
} ;
178
175
let mut index = 0 ;
179
176
let mut run_pass = |pass : & dyn MirPass | {
180
177
let run_hooks = |mir : & _ , index, is_after| {
181
- dump_mir:: on_mir_pass ( $ tcx, & format_args ! ( "{:03}-{:03}" , phase_index, index) ,
178
+ dump_mir:: on_mir_pass ( tcx, & format_args ! ( "{:03}-{:03}" , phase_index, index) ,
182
179
& pass. name ( ) , source, mir, is_after) ;
183
180
} ;
184
181
run_hooks ( mir, index, false ) ;
185
- pass. run_pass ( $ tcx, source, mir) ;
182
+ pass. run_pass ( tcx, source, mir) ;
186
183
run_hooks ( mir, index, true ) ;
187
184
188
185
index += 1 ;
189
186
} ;
190
- $( run_pass ( & $pass) ; ) *
191
187
192
- mir. phase = $mir_phase;
188
+ for pass in passes {
189
+ run_pass ( * pass) ;
190
+ }
191
+
192
+ mir. phase = mir_phase;
193
193
} ;
194
194
195
- run_passes ( & mut $ mir, None ) ;
195
+ run_passes ( mir, None ) ;
196
196
197
- for ( index, promoted_mir) in $ mir. promoted . iter_enumerated_mut ( ) {
197
+ for ( index, promoted_mir) in mir. promoted . iter_enumerated_mut ( ) {
198
198
run_passes ( promoted_mir, Some ( index) ) ;
199
199
200
- // Let's make sure we don't miss any nested instances
201
- assert ! ( promoted_mir. promoted. is_empty( ) ) ;
200
+ //Let's make sure we don't miss any nested instances
201
+ assert ! ( promoted_mir. promoted. is_empty( ) )
202
202
}
203
- } }
203
+ }
204
204
205
205
fn mir_const < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> & ' tcx Steal < Mir < ' tcx > > {
206
206
// Unsafety check uses the raw mir, so make sure it is run
207
207
let _ = tcx. unsafety_check_result ( def_id) ;
208
208
209
209
let mut mir = tcx. mir_built ( def_id) . steal ( ) ;
210
- run_passes ! [ tcx, mir, def_id, MirPhase :: Const ;
210
+ run_passes ( tcx, & mut mir, def_id, MirPhase :: Const , & [
211
211
// Remove all `EndRegion` statements that are not involved in borrows.
212
- cleanup_post_borrowck:: CleanEndRegions ,
212
+ & cleanup_post_borrowck:: CleanEndRegions ,
213
213
214
214
// What we need to do constant evaluation.
215
- simplify:: SimplifyCfg :: new( "initial" ) ,
216
- type_check:: TypeckMir ,
217
- rustc_peek:: SanityCheck ,
218
- uniform_array_move_out:: UniformArrayMoveOut ,
219
- ] ;
215
+ & simplify:: SimplifyCfg :: new ( "initial" ) ,
216
+ & type_check:: TypeckMir ,
217
+ & rustc_peek:: SanityCheck ,
218
+ & uniform_array_move_out:: UniformArrayMoveOut ,
219
+ ] ) ;
220
220
tcx. alloc_steal_mir ( mir)
221
221
}
222
222
@@ -229,11 +229,11 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
229
229
}
230
230
231
231
let mut mir = tcx. mir_const ( def_id) . steal ( ) ;
232
- run_passes ! [ tcx, mir, def_id, MirPhase :: Validated ;
232
+ run_passes ( tcx, & mut mir, def_id, MirPhase :: Validated , & [
233
233
// What we need to run borrowck etc.
234
- qualify_consts:: QualifyAndPromoteConstants ,
235
- simplify:: SimplifyCfg :: new( "qualify-consts" ) ,
236
- ] ;
234
+ & qualify_consts:: QualifyAndPromoteConstants ,
235
+ & simplify:: SimplifyCfg :: new ( "qualify-consts" ) ,
236
+ ] ) ;
237
237
tcx. alloc_steal_mir ( mir)
238
238
}
239
239
@@ -247,59 +247,59 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
247
247
}
248
248
249
249
let mut mir = tcx. mir_validated ( def_id) . steal ( ) ;
250
- run_passes ! [ tcx, mir, def_id, MirPhase :: Optimized ;
250
+ run_passes ( tcx, & mut mir, def_id, MirPhase :: Optimized , & [
251
251
// Remove all things not needed by analysis
252
- no_landing_pads:: NoLandingPads ,
253
- simplify_branches:: SimplifyBranches :: new( "initial" ) ,
254
- remove_noop_landing_pads:: RemoveNoopLandingPads ,
252
+ & no_landing_pads:: NoLandingPads ,
253
+ & simplify_branches:: SimplifyBranches :: new ( "initial" ) ,
254
+ & remove_noop_landing_pads:: RemoveNoopLandingPads ,
255
255
// Remove all `AscribeUserType` statements.
256
- cleanup_post_borrowck:: CleanAscribeUserType ,
256
+ & cleanup_post_borrowck:: CleanAscribeUserType ,
257
257
// Remove all `FakeRead` statements and the borrows that are only
258
258
// used for checking matches
259
- cleanup_post_borrowck:: CleanFakeReadsAndBorrows ,
260
- simplify:: SimplifyCfg :: new( "early-opt" ) ,
259
+ & cleanup_post_borrowck:: CleanFakeReadsAndBorrows ,
260
+ & simplify:: SimplifyCfg :: new ( "early-opt" ) ,
261
261
262
262
// These next passes must be executed together
263
- add_call_guards:: CriticalCallEdges ,
264
- elaborate_drops:: ElaborateDrops ,
265
- no_landing_pads:: NoLandingPads ,
263
+ & add_call_guards:: CriticalCallEdges ,
264
+ & elaborate_drops:: ElaborateDrops ,
265
+ & no_landing_pads:: NoLandingPads ,
266
266
// AddValidation needs to run after ElaborateDrops and before EraseRegions, and it needs
267
267
// an AllCallEdges pass right before it.
268
- add_call_guards:: AllCallEdges ,
269
- add_validation:: AddValidation ,
268
+ & add_call_guards:: AllCallEdges ,
269
+ & add_validation:: AddValidation ,
270
270
// AddMovesForPackedDrops needs to run after drop
271
271
// elaboration.
272
- add_moves_for_packed_drops:: AddMovesForPackedDrops ,
272
+ & add_moves_for_packed_drops:: AddMovesForPackedDrops ,
273
273
274
- simplify:: SimplifyCfg :: new( "elaborate-drops" ) ,
274
+ & simplify:: SimplifyCfg :: new ( "elaborate-drops" ) ,
275
275
276
276
// No lifetime analysis based on borrowing can be done from here on out.
277
277
278
278
// From here on out, regions are gone.
279
- erase_regions:: EraseRegions ,
279
+ & erase_regions:: EraseRegions ,
280
280
281
- lower_128bit:: Lower128Bit ,
281
+ & lower_128bit:: Lower128Bit ,
282
282
283
283
284
284
// Optimizations begin.
285
- uniform_array_move_out:: RestoreSubsliceArrayMoveOut ,
286
- inline:: Inline ,
285
+ & uniform_array_move_out:: RestoreSubsliceArrayMoveOut ,
286
+ & inline:: Inline ,
287
287
288
288
// Lowering generator control-flow and variables
289
289
// has to happen before we do anything else to them.
290
- generator:: StateTransform ,
291
-
292
- instcombine:: InstCombine ,
293
- const_prop:: ConstProp ,
294
- simplify_branches:: SimplifyBranches :: new( "after-const-prop" ) ,
295
- deaggregator:: Deaggregator ,
296
- copy_prop:: CopyPropagation ,
297
- remove_noop_landing_pads:: RemoveNoopLandingPads ,
298
- simplify:: SimplifyCfg :: new( "final" ) ,
299
- simplify:: SimplifyLocals ,
300
-
301
- add_call_guards:: CriticalCallEdges ,
302
- dump_mir:: Marker ( "PreCodegen" ) ,
303
- ] ;
290
+ & generator:: StateTransform ,
291
+
292
+ & instcombine:: InstCombine ,
293
+ & const_prop:: ConstProp ,
294
+ & simplify_branches:: SimplifyBranches :: new ( "after-const-prop" ) ,
295
+ & deaggregator:: Deaggregator ,
296
+ & copy_prop:: CopyPropagation ,
297
+ & remove_noop_landing_pads:: RemoveNoopLandingPads ,
298
+ & simplify:: SimplifyCfg :: new ( "final" ) ,
299
+ & simplify:: SimplifyLocals ,
300
+
301
+ & add_call_guards:: CriticalCallEdges ,
302
+ & dump_mir:: Marker ( "PreCodegen" ) ,
303
+ ] ) ;
304
304
tcx. alloc_mir ( mir)
305
305
}
0 commit comments