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 add_phi(
&self,
context: &mut Context,
from_block: Block,
phi_value: Value
)
pub fn add_phi(
&self,
context: &mut Context,
from_block: Block,
phi_value: Value
)
Add a new phi entry to this block.
This indicates that if control flow comes from from_block
then the phi instruction should
use phi_value
.
sourcepub fn get_phi_val_coming_from(
&self,
context: &Context,
from_block: &Block
) -> Option<Value>
pub fn get_phi_val_coming_from(
&self,
context: &Context,
from_block: &Block
) -> Option<Value>
Get the value from the phi instruction which correlates to from_block
.
Returns None
if from_block
isn’t found.
sourcepub fn update_phi_source_block(
&self,
context: &mut Context,
old_source: Block,
new_source: Block
)
pub fn update_phi_source_block(
&self,
context: &mut Context,
old_source: Block,
new_source: Block
)
Replace a block reference in the phi instruction.
Any reference to old_source
will be replace with new_source
in the list of phi values.
sourcepub fn get_term_inst<'a>(&self, context: &'a Context) -> Option<&'a Instruction>
pub fn get_term_inst<'a>(&self, context: &'a Context) -> Option<&'a Instruction>
Get a reference to the block terminator.
Returns None
if block is empty.
sourcepub fn replace_value(
&self,
context: &mut Context,
old_val: Value,
new_val: Value
)
pub fn replace_value(
&self,
context: &mut Context,
old_val: Value,
new_val: 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.
Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more