Skip to content

Commit 1a01292

Browse files
committed
Add DSE optimization pass.
1 parent ef4c86e commit 1a01292

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

compiler/rustc_mir_transform/src/dead_store_elimination.rs

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ use rustc_middle::{
44
};
55
use smallvec::SmallVec;
66

7+
/// Loops over basic blocks and calls [`simple_local_dse`] for each, see there for more.
8+
pub struct SimpleLocalDse;
9+
10+
impl<'tcx> MirPass<'tcx> for SimpleLocalDse {
11+
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
12+
sess.mir_opt_level() >= 2
13+
}
14+
15+
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
16+
for bb in body.basic_blocks_mut() {
17+
simple_local_dse(bb, tcx);
18+
}
19+
}
20+
}
21+
722
/// This performs a very basic form of dead store elimintation on the basic block.
823
///
924
/// Essentially, we loop over the statements in reverse order. As we go, we maintain a list of

compiler/rustc_mir_transform/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
485485
&simplify_try::SimplifyArmIdentity,
486486
&simplify_try::SimplifyBranchSame,
487487
&dest_prop::DestinationPropagation,
488+
&dead_store_elimination::SimpleLocalDse,
488489
&o1(simplify_branches::SimplifyConstCondition::new("final")),
489490
&o1(remove_noop_landing_pads::RemoveNoopLandingPads),
490491
&o1(simplify::SimplifyCfg::new("final")),

0 commit comments

Comments
 (0)