Struct sway_ir::block::Block

source ·
pub struct Block(pub Index);
Expand description

A wrapper around an ECS handle into the Context.

Tuple Fields§

§0: Index

Implementations§

source§

impl Block

source

pub fn new( context: &mut Context, function: Function, label: Option<String> ) -> Block

Return a new block handle.

Creates a new Block belonging to function in the context and returns its handle. label is optional and is used only when printing the IR.

source

pub fn get_function(&self, context: &Context) -> Function

Get the parent function for this block.

source

pub fn ins<'a>(&self, context: &'a mut Context) -> InstructionInserter<'a>

Create a new InstructionIterator to more easily append instructions to this block.

source

pub fn get_label(&self, context: &Context) -> String

Get the label of this block. If it wasn’t given one upon creation it will be a generated label.

source

pub fn num_instructions(&self, context: &Context) -> usize

Get the number of instructions in this block

source

pub fn get_arg(&self, context: &Context, index: usize) -> Option<Value>

Get the i’th block arg.

source

pub fn num_predecessors(&self, context: &Context) -> usize

Get the number of predecessor blocks, i.e., blocks which branch to this one.

source

pub fn new_arg(&self, context: &mut Context, ty: Type, by_ref: bool) -> usize

Add a new block argument of type ty. Returns its index.

source

pub fn add_arg(&self, context: &mut Context, arg: Value)

Add a block argument, asserts that arg is suitable here.

source

pub fn arg_iter<'a>( &'a self, context: &'a Context ) -> impl Iterator<Item = &Value>

Get an iterator over this block’s args.

source

pub fn num_args(&self, context: &Context) -> usize

How many args does this block have?

source

pub fn pred_iter<'a>( &'a self, context: &'a Context ) -> impl Iterator<Item = &Block>

Get an iterator over this block’s predecessor blocks.

source

pub fn add_pred(&self, context: &mut Context, from_block: &Block)

Add from_block to the set of predecessors of this block.

source

pub fn remove_pred(&self, context: &mut Context, from_block: &Block)

Remove from_block from the set of predecessors of this block.

source

pub fn replace_pred( &self, context: &mut Context, old_source: &Block, new_source: &Block )

Replace a old_source with new_source as a predecessor.

source

pub fn get_terminator<'a>(&self, context: &'a Context) -> Option<&'a Instruction>

Get a reference to the block terminator.

Returns None if block is empty.

source

pub fn get_terminator_mut<'a>( &self, context: &'a mut Context ) -> Option<&'a mut Instruction>

Get a mut reference to the block terminator.

Returns None if block is empty.

source

pub fn get_succ_params(&self, context: &Context, succ: &Block) -> Vec<Value>

For a particular successor (if it indeed is one), get the arguments passed.

source

pub fn get_succ_params_mut<'a>( &'a self, context: &'a mut Context, succ: &Block ) -> Option<&'a mut Vec<Value>>

For a particular successor (if it indeed is one), get a mut ref to parameters passed.

source

pub fn is_terminated(&self, context: &Context) -> bool

Return whether this block is already terminated. Checks if the final instruction, if it exists, is a terminator.

source

pub fn is_terminated_by_ret_or_revert(&self, context: &Context) -> bool

Return whether this block is already terminated specifically by a Ret instruction.

source

pub fn replace_values( &self, context: &mut Context, replace_map: &FxHashMap<Value, Value> )

Replace a value within this block.

For every instruction within the block, any reference to old_val is replaced with new_val.

source

pub fn remove_instruction(&self, context: &mut Context, instr_val: Value)

Remove an instruction from this block.

NOTE: We must be very careful! We mustn’t remove the phi or the terminator. Some extra checks should probably be performed here to avoid corruption! Ideally we use get a user/uses system implemented. Using Vec::remove() is also O(n) which we may want to avoid someday.

source

pub fn replace_instruction( &self, context: &mut Context, old_instr_val: Value, new_instr_val: Value ) -> Result<(), IrError>

Replace an instruction in this block with another. Will return a ValueNotFound on error. Any use of the old instruction value will also be replaced by the new value throughout the owning function.

source

pub fn split_at(&self, context: &mut Context, split_idx: usize) -> (Block, Block)

Split the block into two.

This will create a new block and move the instructions at and following split_idx to it. Returns both blocks.

source

pub fn instruction_iter(&self, context: &Context) -> InstructionIterator

Return an instruction iterator for each instruction in this block.

Trait Implementations§

source§

impl Clone for Block

source§

fn clone(&self) -> Block

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Block

source§

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

Formats the value using the given formatter. Read more
source§

impl DebugWithContext for Block

source§

fn fmt_with_context<'a, 'c>( &'a self, formatter: &mut Formatter<'_>, context: &'c Context ) -> Result

source§

fn with_context<'a, 'c>( &'a self, context: &'c Context ) -> WithContext<'a, 'c, Self>

source§

impl Hash for Block

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<Block> for Block

source§

fn eq(&self, other: &Block) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for Block

source§

impl Eq for Block

source§

impl StructuralEq for Block

source§

impl StructuralPartialEq for Block

Auto Trait Implementations§

§

impl RefUnwindSafe for Block

§

impl Send for Block

§

impl Sync for Block

§

impl Unpin for Block

§

impl UnwindSafe for Block

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast for Twhere T: Any,

source§

fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync + 'static>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
§

impl<T> StorageAsMut for T

§

fn storage<Type>(&mut self) -> StorageMut<'_, Self, Type>where Type: Mappable,

§

fn storage_as_mut<Type>(&mut self) -> StorageMut<'_, Self, Type>where Type: Mappable,

§

impl<T> StorageAsRef for T

§

fn storage<Type>(&self) -> StorageRef<'_, Self, Type>where Type: Mappable,

§

fn storage_as_ref<Type>(&self) -> StorageRef<'_, Self, Type>where Type: Mappable,

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V