Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit aacb6b5

Browse files
committed
Merge branch 'enable-dcp'
2 parents 6d1fdaa + 7386a8b commit aacb6b5

File tree

4 files changed

+96
-260
lines changed

4 files changed

+96
-260
lines changed

compiler/rustc_mir_dataflow/src/value_analysis.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ impl Map {
720720
/// This is currently the only way to create a [`Map`]. The way in which the tracked places are
721721
/// chosen is an implementation detail and may not be relied upon (other than that their type
722722
/// are scalars).
723-
pub fn new<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, value_limit: Option<usize>) -> Self {
723+
pub fn new<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, place_limit: Option<usize>) -> Self {
724724
let mut map = Self {
725725
locals: IndexVec::new(),
726726
projections: FxHashMap::default(),
@@ -730,7 +730,7 @@ impl Map {
730730
inner_values_buffer: Vec::new(),
731731
};
732732
let exclude = excluded_locals(body);
733-
map.register(tcx, body, exclude, value_limit);
733+
map.register(tcx, body, exclude, place_limit);
734734
debug!("registered {} places ({} nodes in total)", map.value_count, map.places.len());
735735
map
736736
}
@@ -741,9 +741,9 @@ impl Map {
741741
tcx: TyCtxt<'tcx>,
742742
body: &Body<'tcx>,
743743
exclude: BitSet<Local>,
744-
value_limit: Option<usize>,
744+
place_limit: Option<usize>,
745745
) {
746-
let mut worklist = VecDeque::with_capacity(value_limit.unwrap_or(body.local_decls.len()));
746+
let mut worklist = VecDeque::with_capacity(place_limit.unwrap_or(body.local_decls.len()));
747747
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
748748

749749
// Start by constructing the places for each bare local.
@@ -766,8 +766,8 @@ impl Map {
766766
// `elem1` is either `Some(Variant(i))` or `None`.
767767
while let Some((mut place, elem1, elem2, ty)) = worklist.pop_front() {
768768
// The user requires a bound on the number of created values.
769-
if let Some(value_limit) = value_limit
770-
&& self.value_count >= value_limit
769+
if let Some(place_limit) = place_limit
770+
&& self.places.len() >= place_limit
771771
{
772772
break;
773773
}

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,18 @@ use crate::const_prop::throw_machine_stop_str;
2525

2626
// These constants are somewhat random guesses and have not been optimized.
2727
// If `tcx.sess.mir_opt_level() >= 4`, we ignore the limits (this can become very expensive).
28-
const BLOCK_LIMIT: usize = 100;
2928
const PLACE_LIMIT: usize = 100;
3029

3130
pub struct DataflowConstProp;
3231

3332
impl<'tcx> MirPass<'tcx> for DataflowConstProp {
3433
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
35-
sess.mir_opt_level() >= 3
34+
sess.mir_opt_level() >= 2
3635
}
3736

3837
#[instrument(skip_all level = "debug")]
3938
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4039
debug!(def_id = ?body.source.def_id());
41-
if tcx.sess.mir_opt_level() < 4 && body.basic_blocks.len() > BLOCK_LIMIT {
42-
debug!("aborted dataflow const prop due too many basic blocks");
43-
return;
44-
}
4540

4641
// We want to have a somewhat linear runtime w.r.t. the number of statements/terminators.
4742
// Let's call this number `n`. Dataflow analysis has `O(h*n)` transfer function

0 commit comments

Comments
 (0)