Skip to content

Commit

Permalink
Profile MIR passes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed May 15, 2023
1 parent 2913ad6 commit addc727
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
/// pass will be named after the type, and it will consist of a main
/// loop that goes over each available MIR and applies `run_pass`.
pub trait MirPass<'tcx> {
fn name(&self) -> &str {
fn name(&self) -> &'static str {
let name = std::any::type_name::<Self>();
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/dump_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_session::config::OutputType;
pub struct Marker(pub &'static str);

impl<'tcx> MirPass<'tcx> for Marker {
fn name(&self) -> &str {
fn name(&self) -> &'static str {
self.0
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir_transform/src/pass_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{validate, MirPass};

/// Just like `MirPass`, except it cannot mutate `Body`.
pub trait MirLint<'tcx> {
fn name(&self) -> &str {
fn name(&self) -> &'static str {
let name = std::any::type_name::<Self>();
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
}
Expand All @@ -26,7 +26,7 @@ impl<'tcx, T> MirPass<'tcx> for Lint<T>
where
T: MirLint<'tcx>,
{
fn name(&self) -> &str {
fn name(&self) -> &'static str {
self.0.name()
}

Expand All @@ -49,7 +49,7 @@ impl<'tcx, T> MirPass<'tcx> for WithMinOptLevel<T>
where
T: MirPass<'tcx>,
{
fn name(&self) -> &str {
fn name(&self) -> &'static str {
self.1.name()
}

Expand Down Expand Up @@ -121,7 +121,7 @@ fn run_passes_inner<'tcx>(
validate_body(tcx, body, format!("before pass {}", name));
}

pass.run_pass(tcx, body);
tcx.sess.time(name, || pass.run_pass(tcx, body));

if dump_enabled {
dump_mir_for_pass(tcx, body, &name, true);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn simplify_cfg<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
}

impl<'tcx> MirPass<'tcx> for SimplifyCfg {
fn name(&self) -> &str {
fn name(&self) -> &'static str {
&self.name()
}

Expand Down

0 comments on commit addc727

Please sign in to comment.