Struct PhiNode
pub struct PhiNode { /* private fields */ }Expand description
A phi node that merges values from multiple control flow predecessors.
Placed at the beginning of basic blocks with multiple predecessors. Each phi
node has one PhiOperand per predecessor, linking the predecessor block
to the SSA variable providing the value along that edge.
§Invariants
- Each phi has at most one operand per predecessor (enforced by
set_operand) - The result variable is defined by this phi node at the block entry
- Phi nodes appear before all regular instructions in a block
§Examples
use analyssa::ir::{phi::{PhiNode, PhiOperand}, variable::{SsaVarId, VariableOrigin}};
let v1 = SsaVarId::from_index(0);
let v2 = SsaVarId::from_index(1);
let result = SsaVarId::from_index(2);
let mut phi = PhiNode::new(result, VariableOrigin::Local(0));
phi.add_operand(PhiOperand::new(v1, 1));
phi.add_operand(PhiOperand::new(v2, 2));
assert_eq!(phi.result(), result);
assert_eq!(phi.operand_count(), 2);Implementations§
Source§impl PhiNode
impl PhiNode
Sourcepub fn new(result: SsaVarId, origin: VariableOrigin) -> PhiNode
pub fn new(result: SsaVarId, origin: VariableOrigin) -> PhiNode
Creates a new phi node for the given variable origin.
The phi node is created with no operands - they must be added during SSA construction as predecessor blocks are processed.
§Arguments
result- The SSA variable that this phi node definesorigin- The original variable (Argument or Local) this phi merges
Sourcepub fn with_capacity(
result: SsaVarId,
origin: VariableOrigin,
predecessor_count: usize,
) -> PhiNode
pub fn with_capacity( result: SsaVarId, origin: VariableOrigin, predecessor_count: usize, ) -> PhiNode
Creates a new phi node with pre-allocated operand capacity.
Use this when the number of predecessors is known in advance to avoid reallocations.
§Arguments
result- The SSA variable that this phi node definesorigin- The original variable this phi mergespredecessor_count- Expected number of predecessor blocks
Sourcepub const fn origin(&self) -> VariableOrigin
pub const fn origin(&self) -> VariableOrigin
Returns the original variable origin this phi merges.
Sourcepub fn set_result(&mut self, var: SsaVarId)
pub fn set_result(&mut self, var: SsaVarId)
Sets the SSA variable defined by this phi node.
Used during SSA construction when renaming variables.
Sourcepub fn operands(&self) -> &[PhiOperand]
pub fn operands(&self) -> &[PhiOperand]
Returns the operands of this phi node.
Sourcepub fn operands_mut(&mut self) -> &mut Vec<PhiOperand>
pub fn operands_mut(&mut self) -> &mut Vec<PhiOperand>
Returns a mutable reference to the operands.
Sourcepub fn add_operand(&mut self, operand: PhiOperand)
pub fn add_operand(&mut self, operand: PhiOperand)
Adds an operand to this phi node.
Unchecked: this does not verify that the operand’s predecessor is a
real CFG predecessor, nor that no operand already names it. A phi with two
operands on one edge has no defined meaning — Self::operand_from
returns the first and discards the rest, while SCCP meets them all and
yields Bottom — and the verifier reports it as
VerifierError::DuplicatePhiOperand. Callers redirecting an existing
edge should use
SsaEditor::replace_phi_predecessor,
which reconciles the collision instead of creating one.
§Arguments
operand- The phi operand to add
Sourcepub fn operand_count(&self) -> usize
pub fn operand_count(&self) -> usize
Returns the number of operands.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this phi node has no operands.
A phi node with no operands is incomplete and should not appear in a fully-constructed SSA form.
Sourcepub fn operand_from(&self, predecessor: usize) -> Option<&PhiOperand>
pub fn operand_from(&self, predecessor: usize) -> Option<&PhiOperand>
Sourcepub fn used_variables(&self) -> impl Iterator<Item = SsaVarId>
pub fn used_variables(&self) -> impl Iterator<Item = SsaVarId>
Returns all the SSA variables used by this phi node.
This is useful for building def-use chains and liveness analysis.
Sourcepub fn retain_operands<F>(&mut self, pred: F)
pub fn retain_operands<F>(&mut self, pred: F)
Retains only operands whose predecessor satisfies the predicate.
Sourcepub fn set_origin(&mut self, origin: VariableOrigin)
pub fn set_origin(&mut self, origin: VariableOrigin)
Sets the origin of this phi node.
This is used during local variable optimization to update indices after unused locals are removed.
Sourcepub fn set_operand(&mut self, predecessor: usize, value: SsaVarId)
pub fn set_operand(&mut self, predecessor: usize, value: SsaVarId)
Sets the operand value for a specific predecessor.
If an operand from that predecessor already exists, it is updated. Otherwise, a new operand is added.
§Arguments
predecessor- The predecessor block indexvalue- The SSA variable value from that predecessor
Trait Implementations§
Source§impl Clone for PhiNode
impl Clone for PhiNode
Source§fn clone_from(&mut self, source: &PhiNode)
fn clone_from(&mut self, source: &PhiNode)
Overwrites self from source, reusing the existing operands
allocation.
Hand-written for the same reason as
SsaFunction::clone_from: the
derived Clone supplies only the default clone_from
(*self = source.clone()), which drops and reallocates the operand
vector on every call. Specializing here lets a whole-function snapshot’s
capacity reuse reach each phi’s operand list rather than stopping at the
owning block’s phi_nodes spine.
The exhaustive destructure is deliberate: adding a field makes this fail to compile rather than silently producing a stale-in-one-field clone.
Auto Trait Implementations§
impl Freeze for PhiNode
impl RefUnwindSafe for PhiNode
impl Send for PhiNode
impl Sync for PhiNode
impl Unpin for PhiNode
impl UnsafeUnpin for PhiNode
impl UnwindSafe for PhiNode
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more