BasicBlock

Struct BasicBlock 

Source
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: usize

Implementations§

Source§

impl BasicBlock

Source

pub fn new(name: String, ir_builder: ObjPtr<IRBuilder>) -> Self

Source

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.

Source

pub fn is_empty(&self) -> bool

Returns True if the BasicBlock is empty.

Source

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.

Source

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.

Source

pub fn push_back(&mut self, inst: InstPtr)

Appends a new instruction to the end of the BasicBlock.

Source

pub fn push_front(&mut self, inst: InstPtr)

Appends a new instruction to the beginning of the BasicBlock.

Source

pub fn is_entry(&self) -> bool

Returns True if the BasicBlock is the function entry BasicBlock.

Source

pub fn is_exit(&self) -> bool

Returns True if the BasicBlock is the function exit BasicBlock.

Source

pub fn get_pred_bb(&self) -> &Vec<BBPtr>

Gets the predecessor BasicBlock of the BasicBlock.

Source

pub fn get_succ_bb(&self) -> &Vec<BBPtr>

Gets the successor BasicBlock of the BasicBlock.

Source

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!

Source

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.

Source

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.

Source

pub fn remove_pred_bb(&mut self, pred: BBPtr)

Remove a predecessor of this block.

Source

pub fn replace_pred_bb(&mut self, from: BBPtr, to: BBPtr)

Replace a predecessor of this block.

Source

pub fn replace_succ_bb_only(&mut self, from: BBPtr, to: BBPtr)

Replace successor with given mapping. TODO: rename me

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn iter(&self) -> BasicBlockIterator

Returns a iterator of the BasicBlock. The iterator yields the InstPtr of the BasicBlock except the head instruction.

Source

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.

Source

pub fn gen_llvm_ir(&self) -> String

Trait Implementations§

Source§

impl Display for BasicBlock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Extend<InstPtr> for BasicBlock

Source§

fn extend<T: IntoIterator<Item = InstPtr>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Ord for BasicBlock

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for BasicBlock

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for BasicBlock

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for BasicBlock

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.