pub struct Block(pub DefaultKey);
Tuple Fields§
§0: DefaultKey
Implementations§
Source§impl Block
impl Block
Sourcepub fn new(
context: &mut Context<'_>,
function: Function,
label: Option<String>,
) -> Block
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.
Sourcepub fn get_function(&self, context: &Context<'_>) -> Function
pub fn get_function(&self, context: &Context<'_>) -> Function
Get the parent function for this block.
Sourcepub fn append<'a, 'eng>(
&self,
context: &'a mut Context<'eng>,
) -> InstructionInserter<'a, 'eng>
pub fn append<'a, 'eng>( &self, context: &'a mut Context<'eng>, ) -> InstructionInserter<'a, 'eng>
Create a new InstructionInserter
to more easily append instructions to this block.
Sourcepub fn get_label(&self, context: &Context<'_>) -> String
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.
Sourcepub fn set_label(&self, context: &mut Context<'_>, new_label: Option<Label>)
pub fn set_label(&self, context: &mut Context<'_>, new_label: Option<Label>)
Set the label of this block. If the label isn’t unique it will be made so.
Sourcepub fn num_instructions(&self, context: &Context<'_>) -> usize
pub fn num_instructions(&self, context: &Context<'_>) -> usize
Get the number of instructions in this block.
Sourcepub fn get_arg(&self, context: &Context<'_>, index: usize) -> Option<Value>
pub fn get_arg(&self, context: &Context<'_>, index: usize) -> Option<Value>
Get the i’th block arg.
Sourcepub fn num_predecessors(&self, context: &Context<'_>) -> usize
pub fn num_predecessors(&self, context: &Context<'_>) -> usize
Get the number of predecessor blocks, i.e., blocks which branch to this one.
Sourcepub fn new_arg(&self, context: &mut Context<'_>, ty: Type) -> usize
pub fn new_arg(&self, context: &mut Context<'_>, ty: Type) -> usize
Add a new block argument of type ty
. Returns its index.
pub fn set_arg(&self, context: &mut Context<'_>, arg: Value)
Sourcepub fn add_arg(&self, context: &mut Context<'_>, arg: Value)
pub fn add_arg(&self, context: &mut Context<'_>, arg: Value)
Add a block argument, asserts that arg
is suitable here.
Sourcepub fn arg_iter<'a>(
&'a self,
context: &'a Context<'_>,
) -> impl Iterator<Item = &Value>
pub fn arg_iter<'a>( &'a self, context: &'a Context<'_>, ) -> impl Iterator<Item = &Value>
Get an iterator over this block’s args.
Sourcepub fn pred_iter<'a>(
&'a self,
context: &'a Context<'_>,
) -> impl Iterator<Item = &Block>
pub fn pred_iter<'a>( &'a self, context: &'a Context<'_>, ) -> impl Iterator<Item = &Block>
Get an iterator over this block’s predecessor blocks.
Sourcepub fn add_pred(&self, context: &mut Context<'_>, from_block: &Block)
pub fn add_pred(&self, context: &mut Context<'_>, from_block: &Block)
Add from_block
to the set of predecessors of this block.
Sourcepub fn remove_pred(&self, context: &mut Context<'_>, from_block: &Block)
pub fn remove_pred(&self, context: &mut Context<'_>, from_block: &Block)
Remove from_block
from the set of predecessors of this block.
Sourcepub fn replace_pred(
&self,
context: &mut Context<'_>,
old_source: &Block,
new_source: &Block,
)
pub fn replace_pred( &self, context: &mut Context<'_>, old_source: &Block, new_source: &Block, )
Replace a old_source
with new_source
as a predecessor.
Sourcepub fn get_instruction_at(
&self,
context: &Context<'_>,
pos: usize,
) -> Option<Value>
pub fn get_instruction_at( &self, context: &Context<'_>, pos: usize, ) -> Option<Value>
Get instruction at position pos
.
Returns None
if block is empty or if pos
is out of bounds.
Sourcepub fn get_terminator<'a>(
&self,
context: &'a Context<'_>,
) -> Option<&'a Instruction>
pub fn get_terminator<'a>( &self, context: &'a Context<'_>, ) -> Option<&'a Instruction>
Get a reference to the final instruction in the block, provided it is a terminator.
Returns None
if the final instruction is not a terminator. This can only happen during IR
generation when the block is still being populated.
Sourcepub fn get_terminator_mut<'a>(
&self,
context: &'a mut Context<'_>,
) -> Option<&'a mut Instruction>
pub fn get_terminator_mut<'a>( &self, context: &'a mut Context<'_>, ) -> Option<&'a mut Instruction>
Get a mutable reference to the final instruction in the block, provided it is a terminator.
Returns None
if the final instruction is not a terminator. This can only happen during IR
generation when the block is still being populated.
Sourcepub fn get_succ_params(&self, context: &Context<'_>, succ: &Block) -> Vec<Value>
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.
Sourcepub fn get_succ_params_mut<'a>(
&'a self,
context: &'a mut Context<'_>,
succ: &Block,
) -> Option<&'a mut Vec<Value>>
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.
Sourcepub fn is_terminated_by_return_or_revert(&self, context: &Context<'_>) -> bool
pub fn is_terminated_by_return_or_revert(&self, context: &Context<'_>) -> bool
Return whether this block is already terminated by non-branching instructions, means with instructions that cause either revert, or local or context returns. Those instructions are: InstOp::Ret, FuelVmInstruction::Retd, FuelVmInstruction::JmpMem, and FuelVmInstruction::Revert).
Sourcepub fn replace_values(
&self,
context: &mut Context<'_>,
replace_map: &FxHashMap<Value, Value>,
)
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
.
Sourcepub fn remove_instruction(&self, context: &mut Context<'_>, instr_val: Value)
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.
Sourcepub fn remove_instruction_at(&self, context: &mut Context<'_>, pos: usize)
pub fn remove_instruction_at(&self, context: &mut Context<'_>, pos: usize)
Remove an instruction at position pos
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.
Sourcepub fn remove_last_instruction(&self, context: &mut Context<'_>)
pub fn remove_last_instruction(&self, context: &mut Context<'_>)
Remove the last instruction in the block.
NOTE: The caller must be very careful if removing the terminator.
Sourcepub fn remove_instructions<T: Fn(Value) -> bool>(
&self,
context: &mut Context<'_>,
pred: T,
)
pub fn remove_instructions<T: Fn(Value) -> bool>( &self, context: &mut Context<'_>, pred: T, )
Remove instructions from block that satisfy a given predicate.
Sourcepub fn take_body(&self, context: &mut Context<'_>, new_insts: Vec<Value>)
pub fn take_body(&self, context: &mut Context<'_>, new_insts: Vec<Value>)
Clear the current instruction list and take the one provided.
Sourcepub fn prepend_instructions(&self, context: &mut Context<'_>, insts: Vec<Value>)
pub fn prepend_instructions(&self, context: &mut Context<'_>, insts: Vec<Value>)
Insert instruction(s) at the beginning of the block.
Sourcepub fn replace_instruction(
&self,
context: &mut Context<'_>,
old_instr_val: Value,
new_instr_val: Value,
replace_uses: bool,
) -> Result<(), IrError>
pub fn replace_instruction( &self, context: &mut Context<'_>, old_instr_val: Value, new_instr_val: Value, replace_uses: bool, ) -> 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 if replace_uses
is set.
Sourcepub fn split_at(
&self,
context: &mut Context<'_>,
split_idx: usize,
) -> (Block, Block)
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.
Sourcepub fn instruction_iter(&self, context: &Context<'_>) -> InstructionIterator ⓘ
pub fn instruction_iter(&self, context: &Context<'_>) -> InstructionIterator ⓘ
Return an instruction iterator for each instruction in this block.
Trait Implementations§
Source§impl DebugWithContext for Block
impl DebugWithContext for Block
fn fmt_with_context<'a, 'c>( &'a self, formatter: &mut Formatter<'_>, context: &'c Context<'_>, ) -> Result
fn with_context<'a, 'c, 'eng>( &'a self, context: &'c Context<'eng>, ) -> WithContext<'a, 'c, 'eng, Self>
impl Copy for Block
impl Eq for Block
impl StructuralPartialEq for Block
Auto Trait Implementations§
impl Freeze for Block
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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 T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.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<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> StorageAsMut for T
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,
Source§impl<T> StorageAsRef for T
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> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.