Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce new dataflow implementation for available locals, use in existing pass #78928

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2395,7 +2395,7 @@ impl<'tcx> UserTypeProjections {

/// Encodes the effect of a user-supplied type annotation on the
/// subcomponents of a pattern. The effect is determined by applying the
/// given list of proejctions to some underlying base type. Often,
/// given list of projections to some underlying base type. Often,
/// the projection element list `projs` is empty, in which case this
/// directly encodes a type in `base`. But in the case of complex patterns with
/// subpatterns and bindings, we want to apply only a *part* of the type to a variable,
Expand Down
16 changes: 16 additions & 0 deletions compiler/rustc_middle/src/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::mir::*;
use crate::ty::subst::Subst;
use crate::ty::{self, Ty, TyCtxt};
use rustc_hir as hir;
use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_target::abi::VariantIdx;

#[derive(Copy, Clone, Debug, TypeFoldable)]
Expand Down Expand Up @@ -208,6 +209,21 @@ impl<'tcx> Rvalue<'tcx> {
_ => RvalueInitializationState::Deep,
}
}

/// Returns all locals that participate in the Rvalue
pub fn participating_locals(&self, location: Location) -> impl Iterator<Item = Local> {
struct LocalVisitor(Vec<Local>);

impl<'tcx> Visitor<'tcx> for LocalVisitor {
fn visit_local(&mut self, local: &Local, _: PlaceContext, _: Location) {
self.0.push(*local);
}
}

let mut visitor = LocalVisitor(vec![]);
visitor.visit_rvalue(self, location);
visitor.0.into_iter()
}
}

impl<'tcx> Operand<'tcx> {
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_mir/src/dataflow/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ pub trait GenKill<T> {
self.kill(elem);
}
}

/// Returns whether `elem` is alive
fn is_alive(&self, elem: T) -> bool;
}

/// Stores a transfer function for a gen/kill problem.
Expand Down Expand Up @@ -450,6 +453,10 @@ impl<T: Idx> GenKill<T> for GenKillSet<T> {
self.kill.insert(elem);
self.gen.remove(elem);
}

fn is_alive(&self, elem: T) -> bool {
self.gen.contains(elem) && !self.kill.contains(elem)
}
}

impl<T: Idx> GenKill<T> for BitSet<T> {
Expand All @@ -460,6 +467,10 @@ impl<T: Idx> GenKill<T> for BitSet<T> {
fn kill(&mut self, elem: T) {
self.remove(elem);
}

fn is_alive(&self, elem: T) -> bool {
self.contains(elem)
}
}

impl<T: Idx> GenKill<T> for lattice::Dual<BitSet<T>> {
Expand All @@ -470,6 +481,10 @@ impl<T: Idx> GenKill<T> for lattice::Dual<BitSet<T>> {
fn kill(&mut self, elem: T) {
self.0.remove(elem);
}

fn is_alive(&self, elem: T) -> bool {
self.0.contains(elem)
}
}

// NOTE: DO NOT CHANGE VARIANT ORDER. The derived `Ord` impls rely on the current order.
Expand Down
Loading