pub struct Block(pub Index);
Tuple Fields
0: Index
Implementations
sourceimpl 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>(&self, context: &'a mut Context) -> InstructionInserter<'a>
pub fn ins<'a>(&self, context: &'a mut Context) -> InstructionInserter<'a>
Create a new InstructionIterator
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 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.
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>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn get_succ_params(&self, context: &Context, succ: &Block) -> Vec<Value>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
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 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ⓘNotable traits for InstructionIteratorimpl Iterator for InstructionIterator type Item = Value;
pub fn instruction_iter(&self, context: &Context) -> InstructionIteratorⓘNotable traits for InstructionIteratorimpl Iterator for InstructionIterator type Item = Value;
Return an instruction iterator for each instruction in this block.