Skip to content

Commit 44afedf

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

File tree

14 files changed

+545
-77
lines changed

14 files changed

+545
-77
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

+18
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ impl<'tcx> LocalPaths<'tcx> {
134134
}
135135
}
136136
}
137+
138+
/// Add a new local to the given `mir` (which is assumed to be the
139+
/// one `self` was created from) and record a new path for it.
140+
pub fn create_and_record_new_local(&mut self,
141+
mir: &mut Mir<'tcx>,
142+
decl: LocalDecl<'tcx>)
143+
-> Local {
144+
let path = self.data.push(PathData {
145+
ty: decl.ty,
146+
last_descendant: PathId::new(0),
147+
accessed: true
148+
});
149+
self.data[path].last_descendant = path;
150+
151+
let local = mir.local_decls.push(decl);
152+
assert_eq!(self.locals.push(path), local);
153+
local
154+
}
137155
}
138156

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

src/librustc_mir/transform/mod.rs

+2-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);
@@ -262,12 +263,12 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
262263

263264
instcombine::InstCombine,
264265
deaggregator::Deaggregator,
266+
unify_places::UnifyPlaces,
265267
copy_prop::CopyPropagation,
266268
remove_noop_landing_pads::RemoveNoopLandingPads,
267269
simplify::SimplifyCfg::new("final"),
268270
simplify::SimplifyLocals,
269271

270-
generator::StateTransform,
271272
add_call_guards::CriticalCallEdges,
272273
dump_mir::Marker("PreTrans"),
273274
];

0 commit comments

Comments
 (0)