Auto merge of #105121 - oli-obk:simpler-cheaper-dump_mir, r=nnethercote
Cheaper `dump_mir` take two alternative to #105083 r? `@nnethercote`
This commit is contained in:
commit
fd02567705
13 changed files with 60 additions and 110 deletions
|
@ -638,7 +638,7 @@ pub(super) fn dump_coverage_spanview<'tcx>(
|
|||
let def_id = mir_source.def_id();
|
||||
|
||||
let span_viewables = span_viewables(tcx, mir_body, basic_coverage_blocks, &coverage_spans);
|
||||
let mut file = create_dump_file(tcx, "html", None, pass_name, &0, mir_source)
|
||||
let mut file = create_dump_file(tcx, "html", false, pass_name, &0, mir_body)
|
||||
.expect("Unexpected error creating MIR spanview HTML file");
|
||||
let crate_name = tcx.crate_name(def_id.krate);
|
||||
let item_name = tcx.def_path(def_id).to_filename_friendly_no_crate();
|
||||
|
@ -739,7 +739,7 @@ pub(super) fn dump_coverage_graphviz<'tcx>(
|
|||
.join("\n ")
|
||||
));
|
||||
}
|
||||
let mut file = create_dump_file(tcx, "dot", None, pass_name, &0, mir_source)
|
||||
let mut file = create_dump_file(tcx, "dot", false, pass_name, &0, mir_body)
|
||||
.expect("Unexpected error creating BasicCoverageBlock graphviz DOT file");
|
||||
graphviz_writer
|
||||
.write_graphviz(tcx, &mut file)
|
||||
|
|
|
@ -787,7 +787,7 @@ fn dest_prop_mir_dump<'body, 'tcx>(
|
|||
round: usize,
|
||||
) {
|
||||
let mut reachable = None;
|
||||
dump_mir(tcx, None, "DestinationPropagation-dataflow", &round, body, |pass_where, w| {
|
||||
dump_mir(tcx, false, "DestinationPropagation-dataflow", &round, body, |pass_where, w| {
|
||||
let reachable = reachable.get_or_insert_with(|| traversal::reachable_as_bitset(body));
|
||||
|
||||
match pass_where {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! This pass just dumps MIR at a specified point.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
|
||||
|
@ -13,8 +12,8 @@ use rustc_session::config::{OutputFilenames, OutputType};
|
|||
pub struct Marker(pub &'static str);
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for Marker {
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
Cow::Borrowed(self.0)
|
||||
fn name(&self) -> &str {
|
||||
self.0
|
||||
}
|
||||
|
||||
fn run_pass(&self, _tcx: TyCtxt<'tcx>, _body: &mut Body<'tcx>) {}
|
||||
|
|
|
@ -1000,7 +1000,7 @@ fn create_generator_drop_shim<'tcx>(
|
|||
// unrelated code from the resume part of the function
|
||||
simplify::remove_dead_blocks(tcx, &mut body);
|
||||
|
||||
dump_mir(tcx, None, "generator_drop", &0, &body, |_, _| Ok(()));
|
||||
dump_mir(tcx, false, "generator_drop", &0, &body, |_, _| Ok(()));
|
||||
|
||||
body
|
||||
}
|
||||
|
@ -1171,7 +1171,7 @@ fn create_generator_resume_function<'tcx>(
|
|||
// unrelated code from the drop part of the function
|
||||
simplify::remove_dead_blocks(tcx, body);
|
||||
|
||||
dump_mir(tcx, None, "generator_resume", &0, body, |_, _| Ok(()));
|
||||
dump_mir(tcx, false, "generator_resume", &0, body, |_, _| Ok(()));
|
||||
}
|
||||
|
||||
fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock {
|
||||
|
@ -1394,14 +1394,14 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
|
|||
// This is expanded to a drop ladder in `elaborate_generator_drops`.
|
||||
let drop_clean = insert_clean_drop(body);
|
||||
|
||||
dump_mir(tcx, None, "generator_pre-elab", &0, body, |_, _| Ok(()));
|
||||
dump_mir(tcx, false, "generator_pre-elab", &0, body, |_, _| Ok(()));
|
||||
|
||||
// Expand `drop(generator_struct)` to a drop ladder which destroys upvars.
|
||||
// If any upvars are moved out of, drop elaboration will handle upvar destruction.
|
||||
// However we need to also elaborate the code generated by `insert_clean_drop`.
|
||||
elaborate_generator_drops(tcx, body);
|
||||
|
||||
dump_mir(tcx, None, "generator_post-transform", &0, body, |_, _| Ok(()));
|
||||
dump_mir(tcx, false, "generator_post-transform", &0, body, |_, _| Ok(()));
|
||||
|
||||
// Create a copy of our MIR and use it to create the drop shim for the generator
|
||||
let drop_shim = create_generator_drop_shim(tcx, &transform, gen_ty, body, drop_clean);
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use rustc_middle::mir::{self, Body, MirPhase, RuntimePhase};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::Session;
|
||||
|
@ -8,13 +6,9 @@ use crate::{validate, MirPass};
|
|||
|
||||
/// Just like `MirPass`, except it cannot mutate `Body`.
|
||||
pub trait MirLint<'tcx> {
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
fn name(&self) -> &str {
|
||||
let name = std::any::type_name::<Self>();
|
||||
if let Some(tail) = name.rfind(':') {
|
||||
Cow::from(&name[tail + 1..])
|
||||
} else {
|
||||
Cow::from(name)
|
||||
}
|
||||
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
|
||||
}
|
||||
|
||||
fn is_enabled(&self, _sess: &Session) -> bool {
|
||||
|
@ -32,7 +26,7 @@ impl<'tcx, T> MirPass<'tcx> for Lint<T>
|
|||
where
|
||||
T: MirLint<'tcx>,
|
||||
{
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
fn name(&self) -> &str {
|
||||
self.0.name()
|
||||
}
|
||||
|
||||
|
@ -55,7 +49,7 @@ impl<'tcx, T> MirPass<'tcx> for WithMinOptLevel<T>
|
|||
where
|
||||
T: MirPass<'tcx>,
|
||||
{
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
fn name(&self) -> &str {
|
||||
self.1.name()
|
||||
}
|
||||
|
||||
|
@ -146,10 +140,11 @@ fn run_passes_inner<'tcx>(
|
|||
}
|
||||
|
||||
body.phase = new_phase;
|
||||
body.pass_count = 0;
|
||||
|
||||
dump_mir_for_phase_change(tcx, body);
|
||||
if validate || new_phase == MirPhase::Runtime(RuntimePhase::Optimized) {
|
||||
validate_body(tcx, body, format!("after phase change to {}", new_phase));
|
||||
validate_body(tcx, body, format!("after phase change to {}", new_phase.name()));
|
||||
}
|
||||
|
||||
body.pass_count = 1;
|
||||
|
@ -166,11 +161,9 @@ pub fn dump_mir_for_pass<'tcx>(
|
|||
pass_name: &str,
|
||||
is_after: bool,
|
||||
) {
|
||||
let phase_index = body.phase.phase_index();
|
||||
|
||||
mir::dump_mir(
|
||||
tcx,
|
||||
Some(&format_args!("{:03}-{:03}", phase_index, body.pass_count)),
|
||||
true,
|
||||
pass_name,
|
||||
if is_after { &"after" } else { &"before" },
|
||||
body,
|
||||
|
@ -179,14 +172,6 @@ pub fn dump_mir_for_pass<'tcx>(
|
|||
}
|
||||
|
||||
pub fn dump_mir_for_phase_change<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
|
||||
let phase_index = body.phase.phase_index();
|
||||
|
||||
mir::dump_mir(
|
||||
tcx,
|
||||
Some(&format_args!("{:03}-000", phase_index)),
|
||||
&format!("{}", body.phase),
|
||||
&"after",
|
||||
body,
|
||||
|_, _| Ok(()),
|
||||
)
|
||||
assert_eq!(body.pass_count, 0);
|
||||
mir::dump_mir(tcx, true, body.phase.name(), &"after", body, |_, _| Ok(()))
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Vis
|
|||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use smallvec::SmallVec;
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
|
||||
pub struct SimplifyCfg {
|
||||
|
@ -57,8 +56,8 @@ pub fn simplify_cfg<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|||
}
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for SimplifyCfg {
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
Cow::Borrowed(&self.label)
|
||||
fn name(&self) -> &str {
|
||||
&self.label
|
||||
}
|
||||
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
|
|
|
@ -2,8 +2,6 @@ use crate::MirPass;
|
|||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// A pass that replaces a branch with a goto when its condition is known.
|
||||
pub struct SimplifyConstCondition {
|
||||
label: String,
|
||||
|
@ -16,8 +14,8 @@ impl SimplifyConstCondition {
|
|||
}
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for SimplifyConstCondition {
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
Cow::Borrowed(&self.label)
|
||||
fn name(&self) -> &str {
|
||||
&self.label
|
||||
}
|
||||
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue