Skip to main content

Ssa

Struct Ssa 

Source
pub struct Ssa { /* private fields */ }
Expand description

The state of an SSA construction over one function.

Implementations§

Source§

impl Ssa

Source

pub fn new(address: Type) -> Ssa

A construction over a function whose pointers are as wide as that integer type.

The width is here because of one case: reading a variable that nothing has written, in a block nothing branches to. C says the value is indeterminate and spec/08-ir.md section 8.4 says it is unspecified but stable, so this hands back a zero, and a zero of pointer type is an integer zero cast to one.

Source

pub fn write(&mut self, var: Var, block: Block, value: Value)

Records that a variable holds a value from here to the end of the block.

Source

pub fn read( &mut self, func: &mut Func, var: Var, block: Block, ty: Type, ) -> Value

The value a variable holds at this point in a block, which is the whole algorithm.

The type is what a parameter would be given if one has to be made. It is passed in rather than remembered per variable because the caller has it in hand and a variable whose type this had to store would be a variable this had to be told about first. A variable read at two types is a variable read wrong, and what comes back is whatever the first read decided.

What comes back may be a parameter that Ssa::finish later takes out. Putting it into the function is safe, because finish rewrites everything the function holds. Remembering it on the side and comparing it to something afterwards is not.

§Panics

Panics if the function has no entry block, which can only happen when nothing has been built into it yet.

Source

pub fn branch(&mut self, func: &Func, inst: Inst)

Records the edges a terminator makes, which is what tells this the shape of the CFG.

Every terminator has to be handed over, and before the block it goes to is sealed. A branch this was not told about is a predecessor that will be missed, and the parameter that should have collected a value from it will be short an argument, which is something the verifier says out loud rather than something that goes quiet.

§Panics

Panics if the instruction is not in a block.

Source

pub fn seal(&mut self, func: &mut Func, block: Block)

Says that a block has all the predecessors it is going to have.

§Panics

Panics if the block has already been sealed.

Source

pub fn is_sealed(&self, block: Block) -> bool

Whether a block has been told it has all its predecessors.

Source

pub fn finish(self, func: &mut Func)

Applies everything that was worked out and drops what turned out to be redundant.

Until this runs the function is correct but wordy: a parameter that stands for one value is still a parameter, and the branches still pass it. This resolves every operand of every instruction and every argument of every branch once, and then takes the parameters out along with the arguments that fed them.

Trait Implementations§

Source§

impl Debug for Ssa

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Ssa

§

impl RefUnwindSafe for Ssa

§

impl Send for Ssa

§

impl Sync for Ssa

§

impl Unpin for Ssa

§

impl UnsafeUnpin for Ssa

§

impl UnwindSafe for Ssa

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.