Skip to content

Commit

Permalink
rustc_mir: implement a "place unification" optimization (aka source/d…
Browse files Browse the repository at this point in the history
…estination propagation).
  • Loading branch information
eddyb committed Feb 1, 2018
1 parent a94d1e7 commit f88212c
Show file tree
Hide file tree
Showing 12 changed files with 548 additions and 75 deletions.
4 changes: 4 additions & 0 deletions src/librustc_mir/analysis/eventflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ impl<I: Idx> SparseBitSet<I> {
}
}

pub fn capacity(&self) -> usize {
self.map.len() * 128
}

pub fn contains(&self, index: I) -> bool {
let (key, mask) = key_and_mask(index);
self.map.get(&key).map_or(false, |bits| (bits & mask) != 0)
Expand Down
17 changes: 17 additions & 0 deletions src/librustc_mir/analysis/local_paths/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ impl<'tcx> LocalPaths<'tcx> {
}
}
}

/// Add a new local to the given `mir` (which is assumed to be the
/// one `self` was created from) and record a new path for it.
pub fn create_and_record_new_local(&mut self,
mir: &mut Mir<'tcx>,
decl: LocalDecl<'tcx>)
-> Local {
let path = self.data.push(PathData {
last_descendant: PathId::new(0),
ty: decl.ty
});
self.data[path].last_descendant = path;

let local = mir.local_decls.push(decl);
assert_eq!(self.locals.push(path), local);
local
}
}

pub struct Children<'a, 'tcx: 'a> {
Expand Down
8 changes: 7 additions & 1 deletion src/librustc_mir/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub mod copy_prop;
pub mod generator;
pub mod inline;
pub mod lower_128bit;
pub mod unify_places;

pub(crate) fn provide(providers: &mut Providers) {
self::qualify_consts::provide(providers);
Expand Down Expand Up @@ -255,14 +256,19 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx

// Optimizations begin.
inline::Inline,

// Lowering generator control-flow and variables
// has to happen before we do anything else to them.
generator::StateTransform,

instcombine::InstCombine,
deaggregator::Deaggregator,
unify_places::UnifyPlaces,
copy_prop::CopyPropagation,
remove_noop_landing_pads::RemoveNoopLandingPads,
simplify::SimplifyCfg::new("final"),
simplify::SimplifyLocals,

generator::StateTransform,
add_call_guards::CriticalCallEdges,
dump_mir::Marker("PreTrans"),
];
Expand Down
Loading

0 comments on commit f88212c

Please sign in to comment.