1
Fork 0

remove Pass and (temporarily) drop Inline

This commit is contained in:
Niko Matsakis 2017-05-01 12:47:00 -04:00
parent 69c8f9dd25
commit c253df5249
4 changed files with 12 additions and 37 deletions

View file

@ -15,8 +15,6 @@ use hir::def_id::DefId;
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;
@ -135,19 +133,6 @@ pub trait PassHook {
/// 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
@ -160,17 +145,6 @@ pub trait DefIdPass {
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`.
@ -210,7 +184,7 @@ impl<T: MirPass> DefIdPass for T {
#[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:
@ -238,7 +212,7 @@ impl<'a, 'tcx> Passes {
}
/// 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));
}
@ -251,7 +225,7 @@ impl<'a, 'tcx> Passes {
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]
}

View file

@ -928,7 +928,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
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);

View file

@ -18,7 +18,7 @@ use rustc_data_structures::graph;
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};
@ -45,6 +45,11 @@ const UNKNOWN_SIZE_COST: usize = 10;
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>>> {

View file

@ -70,15 +70,11 @@ fn mir_pass<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, '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> {