Skip to content

Count and report time taken by MIR passes #36296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/librustc/mir/transform.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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