Count and report time taken by MIR passes
This commit is contained in:
parent
5114f8a29b
commit
0520698be3
@ -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.
|
||||
@ -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 }
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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> {
|
||||
@ -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
|
||||
|
@ -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() }
|
||||
}
|
||||
|
@ -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> {
|
||||
|
Loading…
Reference in New Issue
Block a user