Skip to content

Commit

Permalink
Limit block count
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Jun 24, 2020
1 parent 731dbe3 commit b760023
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/librustc_mir/transform/dest_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ use rustc_middle::mir::{
};
use rustc_middle::ty::{self, Ty, TyCtxt};

// Empirical measurements have resulted in some observations:
// - Running on a body with a single block and 500 locals takes barely any time
// - Running on a body with ~400 blocks and ~300 relevant locals takes "too long"
// ...so we just limit both to somewhat reasonable-ish looking values.
const MAX_LOCALS: usize = 500;
const MAX_BLOCKS: usize = 250;

pub struct DestinationPropagation;

Expand Down Expand Up @@ -160,6 +165,15 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
);
return;
}
if body.basic_blocks().len() > MAX_BLOCKS {
warn!(
"too many blocks in {:?} ({}, max is {}), not optimizing",
source.def_id(),
body.basic_blocks().len(),
MAX_BLOCKS
);
return;
}

let mut conflicts = Conflicts::build(tcx, body, source, &relevant_locals);

Expand Down

0 comments on commit b760023

Please sign in to comment.