pub struct Block(pub Index);
Tuple Fields§
§0: Index
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 ins<'a, 'eng>(
&self,
context: &'a mut Context<'eng>
) -> InstructionInserter<'a, 'eng>
pub fn ins<'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_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 block terminator.
Returns None
if block is empty.
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 mut reference to the block terminator.
Returns None
if block is empty.
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(&self, context: &Context<'_>) -> bool
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.
sourcepub fn is_terminated_by_ret_or_revert(&self, context: &Context<'_>) -> bool
pub fn is_terminated_by_ret_or_revert(&self, context: &Context<'_>) -> bool
Return whether this block is already terminated specifically by a Ret instruction.
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_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 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
) -> Result<(), IrError>
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.
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>
source§impl PartialEq<Block> for Block
impl PartialEq<Block> for Block
impl Copy for Block
impl Eq for Block
impl StructuralEq for Block
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> 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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
source§fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
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, Global>) -> Rc<dyn Any, Global>
fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
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.