mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
cleanup cfg after optimization
This commit is contained in:
parent
f472303a93
commit
b6f51d6d6a
@ -6,6 +6,8 @@ use rustc_middle::mir::visit::Visitor;
|
|||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
|
||||||
|
use super::simplify::simplify_cfg;
|
||||||
|
|
||||||
pub struct RemoveUnneededDrops;
|
pub struct RemoveUnneededDrops;
|
||||||
|
|
||||||
impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
|
impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
|
||||||
@ -18,11 +20,18 @@ impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
|
|||||||
def_id: source.def_id().expect_local(),
|
def_id: source.def_id().expect_local(),
|
||||||
};
|
};
|
||||||
opt_finder.visit_body(body);
|
opt_finder.visit_body(body);
|
||||||
|
let should_simplify = !opt_finder.optimizations.is_empty();
|
||||||
for (loc, target) in opt_finder.optimizations {
|
for (loc, target) in opt_finder.optimizations {
|
||||||
let terminator = body.basic_blocks_mut()[loc.block].terminator_mut();
|
let terminator = body.basic_blocks_mut()[loc.block].terminator_mut();
|
||||||
debug!("SUCCESS: replacing `drop` with goto({:?})", target);
|
debug!("SUCCESS: replacing `drop` with goto({:?})", target);
|
||||||
terminator.kind = TerminatorKind::Goto { target };
|
terminator.kind = TerminatorKind::Goto { target };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we applied optimizations, we potentially have some cfg to cleanup to
|
||||||
|
// make it easier for further passes
|
||||||
|
if should_simplify {
|
||||||
|
simplify_cfg(body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,10 +16,9 @@
|
|||||||
_3 = _1; // scope 0 at $DIR/remove_unneeded_drops.rs:3:10: 3:11
|
_3 = _1; // scope 0 at $DIR/remove_unneeded_drops.rs:3:10: 3:11
|
||||||
_2 = const (); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
_2 = const (); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
||||||
- drop(_3) -> bb1; // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
- drop(_3) -> bb1; // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
||||||
+ goto -> bb1; // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
- }
|
||||||
}
|
-
|
||||||
|
- bb1: {
|
||||||
bb1: {
|
|
||||||
StorageDead(_3); // scope 0 at $DIR/remove_unneeded_drops.rs:3:11: 3:12
|
StorageDead(_3); // scope 0 at $DIR/remove_unneeded_drops.rs:3:11: 3:12
|
||||||
StorageDead(_2); // scope 0 at $DIR/remove_unneeded_drops.rs:3:12: 3:13
|
StorageDead(_2); // scope 0 at $DIR/remove_unneeded_drops.rs:3:12: 3:13
|
||||||
_0 = const (); // scope 0 at $DIR/remove_unneeded_drops.rs:2:17: 4:2
|
_0 = const (); // scope 0 at $DIR/remove_unneeded_drops.rs:2:17: 4:2
|
||||||
|
@ -16,10 +16,9 @@
|
|||||||
_3 = _1; // scope 0 at $DIR/remove_unneeded_drops.rs:13:10: 13:11
|
_3 = _1; // scope 0 at $DIR/remove_unneeded_drops.rs:13:10: 13:11
|
||||||
_2 = const (); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
_2 = const (); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
||||||
- drop(_3) -> bb1; // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
- drop(_3) -> bb1; // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
||||||
+ goto -> bb1; // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
- }
|
||||||
}
|
-
|
||||||
|
- bb1: {
|
||||||
bb1: {
|
|
||||||
StorageDead(_3); // scope 0 at $DIR/remove_unneeded_drops.rs:13:11: 13:12
|
StorageDead(_3); // scope 0 at $DIR/remove_unneeded_drops.rs:13:11: 13:12
|
||||||
StorageDead(_2); // scope 0 at $DIR/remove_unneeded_drops.rs:13:12: 13:13
|
StorageDead(_2); // scope 0 at $DIR/remove_unneeded_drops.rs:13:12: 13:13
|
||||||
_0 = const (); // scope 0 at $DIR/remove_unneeded_drops.rs:12:36: 14:2
|
_0 = const (); // scope 0 at $DIR/remove_unneeded_drops.rs:12:36: 14:2
|
||||||
|
Loading…
Reference in New Issue
Block a user