Struct LiveVariables
pub struct LiveVariables { /* private fields */ }Expand description
Data flow analysis types.
Generic data flow analysis framework including reaching definitions, live variables, and constant propagation. Provides lattice-based analysis with configurable direction. Live variable analysis.
Computes which variables are live at each program point. A variable is live if its value may be used on some path from that point forward.
§Example
use analyssa::{
analysis::{
dataflow::{DataFlowSolver, LiveVariables},
SsaCfg,
},
ir::SsaVarId,
testing,
};
// Block 1 defines the loop counter phi; block 2 returns it.
let ssa = testing::loop_counter_fixture();
let graph = SsaCfg::from_ssa(&ssa);
let analysis = LiveVariables::new(&ssa);
let solver = DataFlowSolver::new(analysis);
let results = solver.solve(&ssa, &graph);
// The counter is live on entry to block 2, because block 2 returns it.
let counter = SsaVarId::from_index(1);
let live_in = results.in_state(2).unwrap();
assert!(live_in.variables().any(|var| var == counter));
// Nothing is live after the return terminator.
assert_eq!(results.out_state(2).unwrap().variables().count(), 0);Implementations§
Source§impl LiveVariables
impl LiveVariables
Sourcepub fn new<T>(ssa: &SsaFunction<T>) -> LiveVariableswhere
T: Target,
pub fn new<T>(ssa: &SsaFunction<T>) -> LiveVariableswhere
T: Target,
Creates a new live variables analysis for the given SSA function.
Sourcepub fn live_out(
&self,
block: usize,
out_state: &LivenessResult,
) -> LivenessResult
pub fn live_out( &self, block: usize, out_state: &LivenessResult, ) -> LivenessResult
Returns the values live on block’s outgoing edges.
Use this rather than the solver’s raw out_state. out_state is the
meet of the successors’ IN sets, and a value consumed only by a
successor’s phi never appears there: phi-operand uses are relocated into
the predecessor’s USE set, which feeds IN[pred], not OUT[pred]. The
value is genuinely live across the edge — the phi copy reads it — so raw
out_state under-approximates liveness, which is the unsafe direction
for a may-analysis and would let a register allocator reuse a live
register.
This computes OUT[B] = out_state(B) ∪ PhiUses(B), where PhiUses(B) is
every value some successor reads as a phi operand on an edge from B.
Sourcepub fn phi_out_set(&self, block: usize) -> Option<&BitSet>
pub fn phi_out_set(&self, block: usize) -> Option<&BitSet>
Returns the values a successor’s phi reads on block’s outgoing edges.
Sourcepub const fn num_variables(&self) -> usize
pub const fn num_variables(&self) -> usize
Returns the number of variables being tracked.
Trait Implementations§
Source§impl<T> DataFlowAnalysis<T> for LiveVariableswhere
T: Target,
impl<T> DataFlowAnalysis<T> for LiveVariableswhere
T: Target,
Source§type Lattice = LivenessResult
type Lattice = LivenessResult
Source§fn boundary(
&self,
_ssa: &SsaFunction<T>,
) -> <LiveVariables as DataFlowAnalysis<T>>::Lattice
fn boundary( &self, _ssa: &SsaFunction<T>, ) -> <LiveVariables as DataFlowAnalysis<T>>::Lattice
Source§fn initial(
&self,
_ssa: &SsaFunction<T>,
) -> <LiveVariables as DataFlowAnalysis<T>>::Lattice
fn initial( &self, _ssa: &SsaFunction<T>, ) -> <LiveVariables as DataFlowAnalysis<T>>::Lattice
Source§fn transfer(
&self,
block_id: usize,
_block: &SsaBlock<T>,
output: &<LiveVariables as DataFlowAnalysis<T>>::Lattice,
_ssa: &SsaFunction<T>,
) -> <LiveVariables as DataFlowAnalysis<T>>::Lattice
fn transfer( &self, block_id: usize, _block: &SsaBlock<T>, output: &<LiveVariables as DataFlowAnalysis<T>>::Lattice, _ssa: &SsaFunction<T>, ) -> <LiveVariables as DataFlowAnalysis<T>>::Lattice
Auto Trait Implementations§
impl Freeze for LiveVariables
impl RefUnwindSafe for LiveVariables
impl Send for LiveVariables
impl Sync for LiveVariables
impl Unpin for LiveVariables
impl UnsafeUnpin for LiveVariables
impl UnwindSafe for LiveVariables
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for T
impl<T> Downcast for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.