mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !tcx.consider_optimizing(|| {
|
|
||||||
format!("MultipleReturnTerminators {:?} ", body.source.def_id())
|
|
||||||
}) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// find basic blocks with no statement and a return terminator
|
// find basic blocks with no statement and a return terminator
|
||||||
let mut bbs_simple_returns = BitSet::new_empty(body.basic_blocks().len());
|
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();
|
let bbs = body.basic_blocks_mut();
|
||||||
for idx in bbs.indices() {
|
for idx in bbs.indices() {
|
||||||
if bbs[idx].statements.is_empty()
|
if bbs[idx].statements.is_empty()
|
||||||
@ -32,6 +27,10 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for bb in bbs {
|
for bb in bbs {
|
||||||
|
if !tcx.consider_optimizing(|| format!("MultipleReturnTerminators {:?} ", def_id)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if let TerminatorKind::Goto { target } = bb.terminator().kind {
|
if let TerminatorKind::Goto { target } = bb.terminator().kind {
|
||||||
if bbs_simple_returns.contains(target) {
|
if bbs_simple_returns.contains(target) {
|
||||||
bb.terminator_mut().kind = TerminatorKind::Return;
|
bb.terminator_mut().kind = TerminatorKind::Return;
|
||||||
|
@ -11,10 +11,6 @@ pub struct RemoveUnneededDrops;
|
|||||||
|
|
||||||
impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
|
impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
|
||||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
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);
|
trace!("Running RemoveUnneededDrops on {:?}", body.source);
|
||||||
let mut opt_finder = RemoveUnneededDropsOptimizationFinder {
|
let mut opt_finder = RemoveUnneededDropsOptimizationFinder {
|
||||||
tcx,
|
tcx,
|
||||||
@ -25,6 +21,12 @@ impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
|
|||||||
opt_finder.visit_body(body);
|
opt_finder.visit_body(body);
|
||||||
let should_simplify = !opt_finder.optimizations.is_empty();
|
let should_simplify = !opt_finder.optimizations.is_empty();
|
||||||
for (loc, target) in opt_finder.optimizations {
|
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();
|
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 };
|
||||||
|
@ -18,12 +18,6 @@ impl MirPass<'_> for UnreachablePropagation {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !tcx
|
|
||||||
.consider_optimizing(|| format!("UnreachablePropagation {:?} ", body.source.def_id()))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut unreachable_blocks = FxHashSet::default();
|
let mut unreachable_blocks = FxHashSet::default();
|
||||||
let mut replacements = FxHashMap::default();
|
let mut replacements = FxHashMap::default();
|
||||||
|
|
||||||
@ -56,6 +50,12 @@ impl MirPass<'_> for UnreachablePropagation {
|
|||||||
|
|
||||||
let replaced = !replacements.is_empty();
|
let replaced = !replacements.is_empty();
|
||||||
for (bb, terminator_kind) in replacements {
|
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;
|
body.basic_blocks_mut()[bb].terminator_mut().kind = terminator_kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user