add optimization fuel checks to some mir passes
This commit is contained in:
parent
f5230fbf76
commit
78a37f888a
@ -89,6 +89,10 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !tcx.consider_optimizing(|| format!("ConstantPropagation {:?} {:?}", def_id, hir_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if it's even possible to satisfy the 'where' clauses
|
// Check if it's even possible to satisfy the 'where' clauses
|
||||||
// for this item.
|
// for this item.
|
||||||
// This branch will never be taken for any normal function.
|
// This branch will never be taken for any normal function.
|
||||||
|
@ -46,6 +46,10 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
|
|||||||
let should_cleanup = !opts_to_apply.is_empty();
|
let should_cleanup = !opts_to_apply.is_empty();
|
||||||
|
|
||||||
for opt_to_apply in opts_to_apply {
|
for opt_to_apply in opts_to_apply {
|
||||||
|
if !tcx.consider_optimizing(|| format!("EarlyOtherwiseBranch {:?}", &opt_to_apply)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
trace!("SUCCESS: found optimization possibility to apply: {:?}", &opt_to_apply);
|
trace!("SUCCESS: found optimization possibility to apply: {:?}", &opt_to_apply);
|
||||||
|
|
||||||
let statements_before =
|
let statements_before =
|
||||||
|
@ -20,6 +20,13 @@ pub struct InstCombine;
|
|||||||
|
|
||||||
impl<'tcx> MirPass<'tcx> for InstCombine {
|
impl<'tcx> MirPass<'tcx> for InstCombine {
|
||||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||||
|
// Check for fuel here before gathering the optimization list. If we're out of fuel,
|
||||||
|
// we don't want to take the time to pass over the MIR only to find optimizations
|
||||||
|
// we won't run.
|
||||||
|
if !tcx.consider_optimizing(|| format!("InstCombine {:?} ", body.source.def_id())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// First, find optimization opportunities. This is done in a pre-pass to keep the MIR
|
// First, find optimization opportunities. This is done in a pre-pass to keep the MIR
|
||||||
// read-only so that we can do global analyses on the MIR in the process (e.g.
|
// read-only so that we can do global analyses on the MIR in the process (e.g.
|
||||||
// `Place::ty()`).
|
// `Place::ty()`).
|
||||||
|
@ -43,8 +43,13 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let param_env = tcx.param_env(body.source.def_id());
|
let param_env = tcx.param_env(body.source.def_id());
|
||||||
|
let def_id = body.source.def_id();
|
||||||
let (bbs, local_decls) = body.basic_blocks_and_local_decls_mut();
|
let (bbs, local_decls) = body.basic_blocks_and_local_decls_mut();
|
||||||
'outer: for bb_idx in bbs.indices() {
|
'outer: for bb_idx in bbs.indices() {
|
||||||
|
if !tcx.consider_optimizing(|| format!("MatchBranchSimplification {:?} ", def_id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let (discr, val, switch_ty, first, second) = match bbs[bb_idx].terminator().kind {
|
let (discr, val, switch_ty, first, second) = match bbs[bb_idx].terminator().kind {
|
||||||
TerminatorKind::SwitchInt {
|
TerminatorKind::SwitchInt {
|
||||||
discr: ref discr @ (Operand::Copy(_) | Operand::Move(_)),
|
discr: ref discr @ (Operand::Copy(_) | Operand::Move(_)),
|
||||||
|
@ -14,6 +14,12 @@ 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 bbs = body.basic_blocks_mut();
|
let bbs = body.basic_blocks_mut();
|
||||||
|
@ -38,18 +38,22 @@ impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let def_id = body.source.def_id();
|
||||||
let returned_local = match local_eligible_for_nrvo(body) {
|
let returned_local = match local_eligible_for_nrvo(body) {
|
||||||
Some(l) => l,
|
Some(l) => l,
|
||||||
None => {
|
None => {
|
||||||
debug!("`{:?}` was ineligible for NRVO", body.source.def_id());
|
debug!("`{:?}` was ineligible for NRVO", def_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if !tcx.consider_optimizing(|| format!("RenameReturnPlace {:?}", def_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"`{:?}` was eligible for NRVO, making {:?} the return place",
|
"`{:?}` was eligible for NRVO, making {:?} the return place",
|
||||||
body.source.def_id(),
|
def_id, returned_local
|
||||||
returned_local
|
|
||||||
);
|
);
|
||||||
|
|
||||||
RenameToReturnPlace { tcx, to_rename: returned_local }.visit_body(body);
|
RenameToReturnPlace { tcx, to_rename: returned_local }.visit_body(body);
|
||||||
|
@ -60,6 +60,10 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !tcx.consider_optimizing(|| format!("PromoteTemps {:?} ", body.source.def_id())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let mut rpo = traversal::reverse_postorder(body);
|
let mut rpo = traversal::reverse_postorder(body);
|
||||||
let ccx = ConstCx::new(tcx, body);
|
let ccx = ConstCx::new(tcx, body);
|
||||||
let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo);
|
let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo);
|
||||||
|
@ -11,6 +11,10 @@ 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,
|
||||||
|
@ -18,6 +18,12 @@ 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();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user