Skip to content

Commit

Permalink
Auto merge of #127036 - cjgillot:sparse-state, r=oli-obk
Browse files Browse the repository at this point in the history
Make jump threading state sparse

Continuation of #127024

Both dataflow const-prop and jump threading involve cloning the state vector a lot. This PR replaces the data structure by a sparse vector, considering:
- that jump threading state is typically very sparse (at most 1 or 2 set entries);
- that dataflow const-prop is disabled by default;
- that place/value map is very eager, and prone to creating an overly large state.

The first commit is shared with the previous PR to avoid needless conflicts.

r? `@oli-obk`
  • Loading branch information
bors committed Jul 3, 2024
2 parents 1cfd47f + 76244d4 commit 2b90614
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 80 deletions.
14 changes: 14 additions & 0 deletions compiler/rustc_mir_dataflow/src/framework/lattice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub trait MeetSemiLattice: Eq {
/// A set that has a "bottom" element, which is less than or equal to any other element.
pub trait HasBottom {
const BOTTOM: Self;

fn is_bottom(&self) -> bool;
}

/// A set that has a "top" element, which is greater than or equal to any other element.
Expand Down Expand Up @@ -114,6 +116,10 @@ impl MeetSemiLattice for bool {

impl HasBottom for bool {
const BOTTOM: Self = false;

fn is_bottom(&self) -> bool {
!self
}
}

impl HasTop for bool {
Expand Down Expand Up @@ -267,6 +273,10 @@ impl<T: Clone + Eq> MeetSemiLattice for FlatSet<T> {

impl<T> HasBottom for FlatSet<T> {
const BOTTOM: Self = Self::Bottom;

fn is_bottom(&self) -> bool {
matches!(self, Self::Bottom)
}
}

impl<T> HasTop for FlatSet<T> {
Expand All @@ -291,6 +301,10 @@ impl<T> MaybeReachable<T> {

impl<T> HasBottom for MaybeReachable<T> {
const BOTTOM: Self = MaybeReachable::Unreachable;

fn is_bottom(&self) -> bool {
matches!(self, Self::Unreachable)
}
}

impl<T: HasTop> HasTop for MaybeReachable<T> {
Expand Down
Loading

0 comments on commit 2b90614

Please sign in to comment.