Skip to content

Commit f88212c

Browse files
committed
rustc_mir: implement a "place unification" optimization (aka source/destination propagation).
1 parent a94d1e7 commit f88212c

File tree

12 files changed

+548
-75
lines changed

12 files changed

+548
-75
lines changed

src/librustc_mir/analysis/eventflow.rs

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ impl<I: Idx> SparseBitSet<I> {
4242
}
4343
}
4444

45+
pub fn capacity(&self) -> usize {
46+
self.map.len() * 128
47+
}
48+
4549
pub fn contains(&self, index: I) -> bool {
4650
let (key, mask) = key_and_mask(index);
4751
self.map.get(&key).map_or(false, |bits| (bits & mask) != 0)

src/librustc_mir/analysis/local_paths/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,23 @@ impl<'tcx> LocalPaths<'tcx> {
109109
}
110110
}
111111
}
112+
113+
/// Add a new local to the given `mir` (which is assumed to be the
114+
/// one `self` was created from) and record a new path for it.
115+
pub fn create_and_record_new_local(&mut self,
116+
mir: &mut Mir<'tcx>,
117+
decl: LocalDecl<'tcx>)
118+
-> Local {
119+
let path = self.data.push(PathData {
120+
last_descendant: PathId::new(0),
121+
ty: decl.ty
122+
});
123+
self.data[path].last_descendant = path;
124+
125+
let local = mir.local_decls.push(decl);
126+
assert_eq!(self.locals.push(path), local);
127+
local
128+
}
112129
}
113130

114131
pub struct Children<'a, 'tcx: 'a> {

src/librustc_mir/transform/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub mod copy_prop;
4444
pub mod generator;
4545
pub mod inline;
4646
pub mod lower_128bit;
47+
pub mod unify_places;
4748

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

256257
// Optimizations begin.
257258
inline::Inline,
259+
260+
// Lowering generator control-flow and variables
261+
// has to happen before we do anything else to them.
262+
generator::StateTransform,
263+
258264
instcombine::InstCombine,
259265
deaggregator::Deaggregator,
266+
unify_places::UnifyPlaces,
260267
copy_prop::CopyPropagation,
261268
remove_noop_landing_pads::RemoveNoopLandingPads,
262269
simplify::SimplifyCfg::new("final"),
263270
simplify::SimplifyLocals,
264271

265-
generator::StateTransform,
266272
add_call_guards::CriticalCallEdges,
267273
dump_mir::Marker("PreTrans"),
268274
];

0 commit comments

Comments
 (0)