mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
move checks later into optimization passes
This commit is contained in:
parent
1e524fb36c
commit
b556690c53
@ -14,14 +14,9 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
|
||||
return;
|
||||
}
|
||||
|
||||
if !tcx.consider_optimizing(|| {
|
||||
format!("MultipleReturnTerminators {:?} ", body.source.def_id())
|
||||
}) {
|
||||
return;
|
||||
}
|
||||
|
||||
// find basic blocks with no statement and a return terminator
|
||||
let mut bbs_simple_returns = BitSet::new_empty(body.basic_blocks().len());
|
||||
let def_id = body.source.def_id();
|
||||
let bbs = body.basic_blocks_mut();
|
||||
for idx in bbs.indices() {
|
||||
if bbs[idx].statements.is_empty()
|
||||
@ -32,6 +27,10 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
|
||||
}
|
||||
|
||||
for bb in bbs {
|
||||
if !tcx.consider_optimizing(|| format!("MultipleReturnTerminators {:?} ", def_id)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if let TerminatorKind::Goto { target } = bb.terminator().kind {
|
||||
if bbs_simple_returns.contains(target) {
|
||||
bb.terminator_mut().kind = TerminatorKind::Return;
|
||||
|
@ -11,10 +11,6 @@ pub struct RemoveUnneededDrops;
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
if !tcx.consider_optimizing(|| format!("RemoveUnneededDrops {:?} ", body.source.def_id())) {
|
||||
return;
|
||||
}
|
||||
|
||||
trace!("Running RemoveUnneededDrops on {:?}", body.source);
|
||||
let mut opt_finder = RemoveUnneededDropsOptimizationFinder {
|
||||
tcx,
|
||||
@ -25,6 +21,12 @@ impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
|
||||
opt_finder.visit_body(body);
|
||||
let should_simplify = !opt_finder.optimizations.is_empty();
|
||||
for (loc, target) in opt_finder.optimizations {
|
||||
if !tcx
|
||||
.consider_optimizing(|| format!("RemoveUnneededDrops {:?} ", body.source.def_id()))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
let terminator = body.basic_blocks_mut()[loc.block].terminator_mut();
|
||||
debug!("SUCCESS: replacing `drop` with goto({:?})", target);
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
|
@ -18,12 +18,6 @@ impl MirPass<'_> for UnreachablePropagation {
|
||||
return;
|
||||
}
|
||||
|
||||
if !tcx
|
||||
.consider_optimizing(|| format!("UnreachablePropagation {:?} ", body.source.def_id()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let mut unreachable_blocks = FxHashSet::default();
|
||||
let mut replacements = FxHashMap::default();
|
||||
|
||||
@ -56,6 +50,12 @@ impl MirPass<'_> for UnreachablePropagation {
|
||||
|
||||
let replaced = !replacements.is_empty();
|
||||
for (bb, terminator_kind) in replacements {
|
||||
if !tcx.consider_optimizing(|| {
|
||||
format!("UnreachablePropagation {:?} ", body.source.def_id())
|
||||
}) {
|
||||
break;
|
||||
}
|
||||
|
||||
body.basic_blocks_mut()[bb].terminator_mut().kind = terminator_kind;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user