use hir::map::DefPathData;
use mir::{Mir, Promoted};
use ty::TyCtxt;
-use ty::maps::Multi;
-use ty::steal::Steal;
use std::cell::Ref;
use std::rc::Rc;
use syntax::ast::NodeId;
/// application of a pass to a def-id.
pub type PassId = (MirSuite, MirPassIndex, DefId);
-/// The most generic sort of MIR pass. You only want to implement this
-/// rather general trait if you are doing an interprocedural pass that
-/// may inspect and affect the MIR of many def-ids. Otherwise, prefer
-/// the more steamlined `DefIdPass` or `MirPass`.
-pub trait Pass {
- fn name<'a>(&'a self) -> Cow<'a, str> {
- default_name::<Self>()
- }
-
- fn run_pass<'a, 'tcx: 'a>(&self, mir_cx: &MirCtxt<'a, 'tcx>)
- -> Multi<PassId, &'tcx Steal<Mir<'tcx>>>;
-}
-
/// A streamlined trait that you can implement to create an
/// intraprocedural pass; the pass will be invoked to process the MIR
/// with the given `def_id`. This lets you do things before we fetch
fn run_pass<'a, 'tcx: 'a>(&self, mir_cx: &MirCtxt<'a, 'tcx>) -> Mir<'tcx>;
}
-impl<T: DefIdPass> Pass for T {
- fn name<'a>(&'a self) -> Cow<'a, str> {
- DefIdPass::name(self)
- }
-
- fn run_pass<'a, 'tcx: 'a>(&self, mir_cx: &MirCtxt<'a, 'tcx>)
- -> Multi<PassId, &'tcx Steal<Mir<'tcx>>> {
- Multi::from(mir_cx.tcx().alloc_steal_mir(DefIdPass::run_pass(self, mir_cx)))
- }
-}
-
/// A streamlined trait that you can implement to create a pass; the
/// 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`.
#[derive(Clone)]
pub struct Passes {
pass_hooks: Vec<Rc<PassHook>>,
- suites: Vec<Vec<Rc<Pass>>>,
+ suites: Vec<Vec<Rc<DefIdPass>>>,
}
/// The number of "pass suites" that we have:
}
/// Pushes a built-in pass.
- pub fn push_pass<T: Pass + 'static>(&mut self, suite: MirSuite, pass: T) {
+ pub fn push_pass<T: DefIdPass + 'static>(&mut self, suite: MirSuite, pass: T) {
self.suites[suite.0].push(Rc::new(pass));
}
self.suites[suite.0].len()
}
- pub fn pass(&self, suite: MirSuite, pass: MirPassIndex) -> &Pass {
+ pub fn pass(&self, suite: MirSuite, pass: MirPassIndex) -> &DefIdPass {
&*self.suites[suite.0][pass.0]
}
passes.push_pass(MIR_OPTIMIZED, mir::transform::simplify::SimplifyCfg::new("elaborate-drops"));
// No lifetime analysis based on borrowing can be done from here on out.
- passes.push_pass(MIR_OPTIMIZED, mir::transform::inline::Inline);
+ // TODO passes.push_pass(MIR_OPTIMIZED, mir::transform::inline::Inline);
passes.push_pass(MIR_OPTIMIZED, mir::transform::instcombine::InstCombine);
passes.push_pass(MIR_OPTIMIZED, mir::transform::deaggregator::Deaggregator);
passes.push_pass(MIR_OPTIMIZED, mir::transform::copy_prop::CopyPropagation);
use rustc::dep_graph::DepNode;
use rustc::mir::*;
-use rustc::mir::transform::{MirCtxt, MirSource, Pass, PassId};
+use rustc::mir::transform::{MirCtxt, MirSource, PassId};
use rustc::mir::visit::*;
use rustc::traits;
use rustc::ty::{self, Ty, TyCtxt};
pub struct Inline;
+pub trait Pass {
+ fn run_pass<'a, 'tcx: 'a>(&self, mir_cx: &MirCtxt<'a, 'tcx>)
+ -> Multi<PassId, &'tcx Steal<Mir<'tcx>>>;
+}
+
impl Pass for Inline {
fn run_pass<'a, 'tcx: 'a>(&self, mir_cx: &MirCtxt<'a, 'tcx>)
-> Multi<PassId, &'tcx Steal<Mir<'tcx>>> {
let mir = pass.run_pass(&mir_ctxt);
- let key = &(suite, pass_num, def_id);
for hook in passes.hooks() {
- for (&(_, _, k), v) in mir.iter(key) {
- let v = &v.borrow();
- hook.on_mir_pass(&mir_ctxt, Some((k, v)));
- }
+ hook.on_mir_pass(&mir_ctxt, Some((def_id, &mir)));
}
- mir
+ Multi::from(tcx.alloc_steal_mir(mir))
}
struct MirCtxtImpl<'a, 'tcx: 'a> {