pub struct BasicBlock {
pub ir_builder: ObjPtr<IRBuilder>,
pub name: String,
pub id: usize,
pub depth: usize,
/* private fields */
}Expand description
The organization structure of the instructions inside the basic block is a double linked list. the last instruction must be br or ret.
Fields§
§ir_builder: ObjPtr<IRBuilder>§name: String§id: usize§depth: usizeImplementations§
Source§impl BasicBlock
impl BasicBlock
pub fn new(name: String, ir_builder: ObjPtr<IRBuilder>) -> Self
Sourcepub unsafe fn init_bb(bb: BBPtr, id: usize)
pub unsafe fn init_bb(bb: BBPtr, id: usize)
§Safety
Inits BasicBlock after memory allocation.
This is an ugly code that is a compromise in design. You should not call this function.
Sourcepub fn get_first_inst(&self) -> InstPtr
pub fn get_first_inst(&self) -> InstPtr
Gets first instruction in the BasicBlock.
§Panics
Please make sure the current basic block is not empty, otherwise it will panic.
Sourcepub fn get_last_inst(&self) -> InstPtr
pub fn get_last_inst(&self) -> InstPtr
Gets the last instruction in the BasicBlock.
§Panics
Please make sure the current basic block is not empty, otherwise it will panic.
Sourcepub fn push_back(&mut self, inst: InstPtr)
pub fn push_back(&mut self, inst: InstPtr)
Appends a new instruction to the end of the BasicBlock.
Sourcepub fn push_front(&mut self, inst: InstPtr)
pub fn push_front(&mut self, inst: InstPtr)
Appends a new instruction to the beginning of the BasicBlock.
Sourcepub fn is_entry(&self) -> bool
pub fn is_entry(&self) -> bool
Returns True if the BasicBlock is the function entry BasicBlock.
Sourcepub fn get_pred_bb(&self) -> &Vec<BBPtr> ⓘ
pub fn get_pred_bb(&self) -> &Vec<BBPtr> ⓘ
Gets the predecessor BasicBlock of the BasicBlock.
Sourcepub fn get_succ_bb(&self) -> &Vec<BBPtr> ⓘ
pub fn get_succ_bb(&self) -> &Vec<BBPtr> ⓘ
Gets the successor BasicBlock of the BasicBlock.
Sourcepub fn remove_self(&mut self)
pub fn remove_self(&mut self)
Remove current block. This removes self from successor’s predecessor list and phi operand.
§Panics
Please make sure this block is unreachable!
Sourcepub fn replace_entry(&mut self, entry: BBPtr, func: FunPtr)
pub fn replace_entry(&mut self, entry: BBPtr, func: FunPtr)
Replace preds => [ self -> ... ] => succs with preds => [ entry -> ... ] => succs. This:
- add preds to entry’s predecessor list
- remove preds from self’s predecessor list
- replaces self to entry in predecessor’s successor list
- replaces self to entry in function entry
§Safety
Entry should be different from self, and contain no “phi” instructions.
Sourcepub fn replace_exit(&mut self, exit: BBPtr)
pub fn replace_exit(&mut self, exit: BBPtr)
Replace preds => [ ... -> self ] => succs with preds => [ ... -> exit ] => succs. This:
- add succs to exit’s successor list
- remove succs from self’s successor list
- replaces self -> exit in successor’s predecessor list
- replaces self -> exit in successor’s phi operand
§Safety
Exit should be different from self.
Sourcepub fn remove_pred_bb(&mut self, pred: BBPtr)
pub fn remove_pred_bb(&mut self, pred: BBPtr)
Remove a predecessor of this block.
Sourcepub fn replace_pred_bb(&mut self, from: BBPtr, to: BBPtr)
pub fn replace_pred_bb(&mut self, from: BBPtr, to: BBPtr)
Replace a predecessor of this block.
Sourcepub fn replace_succ_bb_only(&mut self, from: BBPtr, to: BBPtr)
pub fn replace_succ_bb_only(&mut self, from: BBPtr, to: BBPtr)
Replace successor with given mapping. TODO: rename me
Sourcepub fn set_true_bb(&mut self, bb: BBPtr)
pub fn set_true_bb(&mut self, bb: BBPtr)
Sets which BasicBlock to jump to when the condition is true.
§Panics
Don’t replace existing true BasicBlock with this method.
Sourcepub fn set_false_bb(&mut self, bb: BBPtr)
pub fn set_false_bb(&mut self, bb: BBPtr)
Sets which BasicBlock to jump to when the condition is false.
§Panics
You should set the true BasicBlock before use this method.
Don’t replace existing false BasicBlock with this method.
Sourcepub fn remove_false_bb(&mut self)
pub fn remove_false_bb(&mut self)
Remove basic block to jump to when the condition is false. This will only execute when false bb exists.
Sourcepub fn remove_true_bb(&mut self)
pub fn remove_true_bb(&mut self)
Remove basic block to jump to when the condition is true. This will only execute when false bb exists.
Sourcepub fn iter(&self) -> BasicBlockIterator ⓘ
pub fn iter(&self) -> BasicBlockIterator ⓘ
Returns a iterator of the BasicBlock.
The iterator yields the InstPtr of the BasicBlock except the head instruction.
Sourcepub fn iter_rev(&self) -> BasicBlockIteratorRev ⓘ
pub fn iter_rev(&self) -> BasicBlockIteratorRev ⓘ
Returns a reverse iterator of the BasicBlock.
The iterator yields the InstPtr of the BasicBlock except the head instruction.
pub fn gen_llvm_ir(&self) -> String
Trait Implementations§
Source§impl Display for BasicBlock
impl Display for BasicBlock
Source§impl Extend<InstPtr> for BasicBlock
impl Extend<InstPtr> for BasicBlock
Source§fn extend<T: IntoIterator<Item = InstPtr>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = InstPtr>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Ord for BasicBlock
impl Ord for BasicBlock
Source§impl PartialEq for BasicBlock
impl PartialEq for BasicBlock
Source§impl PartialOrd for BasicBlock
impl PartialOrd for BasicBlock
impl Eq for BasicBlock
Auto Trait Implementations§
impl Freeze for BasicBlock
impl !RefUnwindSafe for BasicBlock
impl !Send for BasicBlock
impl !Sync for BasicBlock
impl Unpin for BasicBlock
impl !UnwindSafe for BasicBlock
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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<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 more