Skip to content

Commit d56751c

Browse files
committed
Simplify pass manager's run_passes logic
1 parent aad14c7 commit d56751c

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

compiler/rustc_mir_transform/src/pass_manager.rs

+19-29
Original file line numberDiff line numberDiff line change
@@ -99,56 +99,46 @@ fn run_passes_inner<'tcx>(
9999
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
100100
trace!(?overridden_passes);
101101

102-
if validate {
103-
validate_body(tcx, body, format!("start of phase transition from {:?}", start_phase));
104-
}
105-
106102
for pass in passes {
107103
let name = pass.name();
108104

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));
124120

125121
if dump_enabled {
126122
dump_mir(tcx, body, start_phase, &name, cnt, false);
127123
}
128-
129-
pass.run_pass(tcx, body);
130-
124+
if is_enabled {
125+
pass.run_pass(tcx, body);
126+
}
131127
if dump_enabled {
132128
dump_mir(tcx, body, start_phase, &name, cnt, true);
133129
cnt += 1;
134130
}
135-
136131
if let Some(new_phase) = pass.phase_change() {
137132
if body.phase >= new_phase {
138133
panic!("Invalid MIR phase transition from {:?} to {:?}", body.phase, new_phase);
139134
}
140135

141136
body.phase = new_phase;
142137
}
143-
144138
if validate {
145-
validate_body(tcx, body, format!("after pass {}", pass.name()));
139+
validate_body(tcx, body, format!("after pass {}", name));
146140
}
147141
}
148-
149-
if validate || body.phase == MirPhase::Runtime(RuntimePhase::Optimized) {
150-
validate_body(tcx, body, format!("end of phase transition to {:?}", body.phase));
151-
}
152142
}
153143

154144
pub fn validate_body<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, when: String) {

0 commit comments

Comments
 (0)