Skip to content

Commit b760023

Browse files
Limit block count
1 parent 731dbe3 commit b760023

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/librustc_mir/transform/dest_prop.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ use rustc_middle::mir::{
115115
};
116116
use rustc_middle::ty::{self, Ty, TyCtxt};
117117

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

120125
pub struct DestinationPropagation;
121126

@@ -160,6 +165,15 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
160165
);
161166
return;
162167
}
168+
if body.basic_blocks().len() > MAX_BLOCKS {
169+
warn!(
170+
"too many blocks in {:?} ({}, max is {}), not optimizing",
171+
source.def_id(),
172+
body.basic_blocks().len(),
173+
MAX_BLOCKS
174+
);
175+
return;
176+
}
163177

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

0 commit comments

Comments
 (0)