Skip to content

Commit

Permalink
Remove the suite_index parameter of the run_passes!() macro
Browse files Browse the repository at this point in the history
This can be obtained via the `$mir_phase` value.
  • Loading branch information
wesleywiser committed Oct 23, 2018
1 parent 37e1d29 commit 895a4b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ pub enum MirPhase {
Optimized,
}

impl MirPhase {
/// Gets the index of the current MirPhase within the set of all MirPhases.
pub fn phase_index(&self) -> usize {
match self {
MirPhase::Build => 0,
MirPhase::Const => 1,
MirPhase::Validated => 2,
MirPhase::Optimized => 3,
}
}
}

/// Lowered representation of a single function.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Mir<'tcx> {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_mir/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ pub macro run_passes(
$tcx:ident,
$mir:ident,
$def_id:ident,
$suite_index:expr,
$mir_phase:expr;
$($pass:expr,)*
) {{
let suite_index: usize = $suite_index;
let phase_index = $mir_phase.phase_index();

let run_passes = |mir: &mut _, promoted| {
let mir: &mut Mir<'_> = mir;

Expand All @@ -178,7 +178,7 @@ pub macro run_passes(
let mut index = 0;
let mut run_pass = |pass: &dyn MirPass| {
let run_hooks = |mir: &_, index, is_after| {
dump_mir::on_mir_pass($tcx, &format_args!("{:03}-{:03}", suite_index, index),
dump_mir::on_mir_pass($tcx, &format_args!("{:03}-{:03}", phase_index, index),
&pass.name(), source, mir, is_after);
};
run_hooks(mir, index, false);
Expand Down Expand Up @@ -207,7 +207,7 @@ fn mir_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Stea
let _ = tcx.unsafety_check_result(def_id);

let mut mir = tcx.mir_built(def_id).steal();
run_passes![tcx, mir, def_id, 0, MirPhase::Const;
run_passes![tcx, mir, def_id, MirPhase::Const;
// Remove all `EndRegion` statements that are not involved in borrows.
cleanup_post_borrowck::CleanEndRegions,

Expand All @@ -229,7 +229,7 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
}

let mut mir = tcx.mir_const(def_id).steal();
run_passes![tcx, mir, def_id, 1, MirPhase::Validated;
run_passes![tcx, mir, def_id, MirPhase::Validated;
// What we need to run borrowck etc.
qualify_consts::QualifyAndPromoteConstants,
simplify::SimplifyCfg::new("qualify-consts"),
Expand All @@ -247,7 +247,7 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
}

let mut mir = tcx.mir_validated(def_id).steal();
run_passes![tcx, mir, def_id, 2, MirPhase::Optimized;
run_passes![tcx, mir, def_id, MirPhase::Optimized;
// Remove all things not needed by analysis
no_landing_pads::NoLandingPads,
simplify_branches::SimplifyBranches::new("initial"),
Expand Down

0 comments on commit 895a4b2

Please sign in to comment.