Skip to content

Commit

Permalink
Count and report time taken by MIR passes
Browse files Browse the repository at this point in the history
  • Loading branch information
nagisa committed Sep 6, 2016
1 parent 5114f8a commit 0520698
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
17 changes: 9 additions & 8 deletions src/librustc/mir/transform.rs
Expand Up @@ -15,7 +15,9 @@ use mir::mir_map::MirMap;
use mir::repr::{Mir, Promoted};
use ty::TyCtxt;
use syntax::ast::NodeId;
use util::common::time;

use std::borrow::Cow;
use std::fmt;

/// Where a specific Mir comes from.
Expand Down Expand Up @@ -72,12 +74,12 @@ impl<'a, 'tcx> MirSource {
/// Various information about pass.
pub trait Pass {
// fn should_run(Session) to check if pass should run?
fn name(&self) -> &str {
fn name<'a>(&self) -> Cow<'static, str> {
let name = unsafe { ::std::intrinsics::type_name::<Self>() };
if let Some(tail) = name.rfind(":") {
&name[tail+1..]
Cow::from(&name[tail+1..])
} else {
name
Cow::from(name)
}
}
fn disambiguator<'a>(&'a self) -> Option<Box<fmt::Display+'a>> { None }
Expand Down Expand Up @@ -162,11 +164,10 @@ impl<'a, 'tcx> Passes {
}

pub fn run_passes(&mut self, tcx: TyCtxt<'a, 'tcx, 'tcx>, map: &mut MirMap<'tcx>) {
for pass in &mut self.plugin_passes {
pass.run_pass(tcx, map, &mut self.pass_hooks);
}
for pass in &mut self.passes {
pass.run_pass(tcx, map, &mut self.pass_hooks);
let Passes { ref mut passes, ref mut plugin_passes, ref mut pass_hooks } = *self;
for pass in plugin_passes.iter_mut().chain(passes.iter_mut()) {
time(tcx.sess.time_passes(), &*pass.name(),
|| pass.run_pass(tcx, map, pass_hooks));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/dump_mir.rs
Expand Up @@ -26,7 +26,7 @@ impl<'b, 'tcx> MirPass<'tcx> for Marker<'b> {
}

impl<'b> Pass for Marker<'b> {
fn name(&self) -> &str { self.0 }
fn name(&self) -> ::std::borrow::Cow<'static, str> { String::from(self.0).into() }
}

pub struct Disambiguator<'a> {
Expand Down Expand Up @@ -58,7 +58,7 @@ impl<'tcx> MirPassHook<'tcx> for DumpMir {
{
pretty::dump_mir(
tcx,
pass.name(),
&*pass.name(),
&Disambiguator {
pass: pass,
is_after: is_after
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/simplify_branches.rs
Expand Up @@ -62,5 +62,5 @@ impl<'l> Pass for SimplifyBranches<'l> {
}

// avoid calling `type_name` - it contains `<'static>`
fn name(&self) -> &str { "SimplifyBranches" }
fn name(&self) -> ::std::borrow::Cow<'static, str> { "SimplifyBranches".into() }
}
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/simplify_cfg.rs
Expand Up @@ -64,7 +64,7 @@ impl<'l> Pass for SimplifyCfg<'l> {
}

// avoid calling `type_name` - it contains `<'static>`
fn name(&self) -> &str { "SimplifyCfg" }
fn name(&self) -> ::std::borrow::Cow<'static, str> { "SimplifyCfg".into() }
}

pub struct CfgSimplifier<'a, 'tcx: 'a> {
Expand Down

0 comments on commit 0520698

Please sign in to comment.