class BasicBlock

Declaration

class BasicBlock : public Value, public ilist_node_with_parent { /* full declaration omitted */ };

Description

LLVM Basic Block Representation This represents a single basic block in LLVM. A basic block is simply a container of instructions that execute sequentially. Basic blocks are Values because they are referenced by instructions such as branches and switch tables. The type of a BasicBlock is "Type::LabelTy" because the basic block represents a label to which a branch can jump. A well formed basic block is formed of a list of non-terminating instructions followed by a single terminator instruction. Terminator instructions may not occur in the middle of basic blocks, and must terminate the blocks. The BasicBlock class allows malformed basic blocks to occur because it may be useful in the intermediate stage of constructing or modifying a program. However, the verifier will ensure that basic blocks are "well formed".

Declared at: llvm/include/llvm/IR/BasicBlock.h:55

Inherits from: Value, ilist_node_with_parent

Member Variables

private llvm::BasicBlock::InstListType InstList
private llvm::Function* Parent

Inherited from Value:

protected SubclassOptionalData
protected NumUserOperands
protected IsUsedByMD
protected HasName
protected HasMetadata
protected HasHungOffUses
protected HasDescriptor
public static MaxAlignmentExponent = 32
public static MaximumAlignment = 1ULL << MaxAlignmentExponent

Method Overview

Inherited from Value:

Methods

void AdjustBlockAddressRefCount(int Amt)

Description

Increment the internal refcount of the number of BlockAddresses referencing this BasicBlock by \p Amt. This is almost always 0, sometimes one possibly, but almost never 2, and inconceivably 3 or more.

Declared at: llvm/include/llvm/IR/BasicBlock.h:560

Parameters

int Amt

BasicBlock(
    llvm::LLVMContext& C,
    const llvm::Twine& Name = "",
    llvm::Function* Parent = nullptr,
    llvm::BasicBlock* InsertBefore = nullptr)

Description

Constructor. If the function parameter is specified, the basic block is automatically inserted at either the end of the function (if InsertBefore is null), or before the specified basic block.

Declared at: llvm/include/llvm/IR/BasicBlock.h:74

Parameters

llvm::LLVMContext& C
const llvm::Twine& Name = ""
llvm::Function* Parent = nullptr
llvm::BasicBlock* InsertBefore = nullptr

BasicBlock(const llvm::BasicBlock&)

Declared at: llvm/include/llvm/IR/BasicBlock.h:79

Parameters

const llvm::BasicBlock&

static llvm::BasicBlock* Create(
    llvm::LLVMContext& Context,
    const llvm::Twine& Name = "",
    llvm::Function* Parent = nullptr,
    llvm::BasicBlock* InsertBefore = nullptr)

Description

Creates a new BasicBlock. If the Parent parameter is specified, the basic block is automatically inserted at either the end of the function (if InsertBefore is 0), or before the specified basic block.

Declared at: llvm/include/llvm/IR/BasicBlock.h:97

Parameters

llvm::LLVMContext& Context
const llvm::Twine& Name = ""
llvm::Function* Parent = nullptr
llvm::BasicBlock* InsertBefore = nullptr

inline llvm::Instruction& back()

Declared at: llvm/include/llvm/IR/BasicBlock.h:312

inline const llvm::Instruction& back() const

Declared at: llvm/include/llvm/IR/BasicBlock.h:311

inline llvm::BasicBlock::const_iterator begin()
    const

Declared at: llvm/include/llvm/IR/BasicBlock.h:298

inline llvm::BasicBlock::iterator begin()

Description

Instruction iterator methods

Declared at: llvm/include/llvm/IR/BasicBlock.h:297

bool canSplitPredecessors() const

Declared at: llvm/include/llvm/IR/BasicBlock.h:398

static bool classof(const llvm::Value* V)

Description

Methods for support type inquiry through isa, cast, and dyn_cast.

Declared at: llvm/include/llvm/IR/BasicBlock.h:376

Parameters

const llvm::Value* V

void dropAllReferences()

Description

Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining. This allows one to 'delete' a whole class at a time, even though there may be circular references... first all references are dropped, and all use counts go to zero. Then everything is delete'd for real. Note that no operations are valid on an object that has "dropped all references", except operator delete.

Declared at: llvm/include/llvm/IR/BasicBlock.h:388

inline bool empty() const

Declared at: llvm/include/llvm/IR/BasicBlock.h:308

inline llvm::BasicBlock::iterator end()

Declared at: llvm/include/llvm/IR/BasicBlock.h:299

inline llvm::BasicBlock::const_iterator end()
    const

Declared at: llvm/include/llvm/IR/BasicBlock.h:300

SymbolTableList<BasicBlock>::iterator
eraseFromParent()

Description

Unlink 'this' from the containing function and delete it.

Declared at: llvm/include/llvm/IR/BasicBlock.h:224

inline const llvm::Instruction& front() const

Declared at: llvm/include/llvm/IR/BasicBlock.h:309

inline llvm::Instruction& front()

Declared at: llvm/include/llvm/IR/BasicBlock.h:310

llvm::BasicBlock::BasicBlockBits
getBasicBlockBits() const

Description

Safely reinterpret the subclass data bits to a more useful form.

Declared at: llvm/include/llvm/IR/BasicBlock.h:539

llvm::LLVMContext& getContext() const

Description

Get the context in which this basic block lives.

Declared at: llvm/include/llvm/IR/BasicBlock.h:84

llvm::BasicBlock::iterator getFirstInsertionPt()

Declared at: llvm/include/llvm/IR/BasicBlock.h:194

llvm::BasicBlock::const_iterator
getFirstInsertionPt() const

Description

Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI instruction. In particular, it skips all PHIs and LandingPad instructions.

Declared at: llvm/include/llvm/IR/BasicBlock.h:193

const llvm::Instruction* getFirstNonPHI() const

Description

Returns a pointer to the first instruction in this block that is not a PHINode instruction. When adding instructions to the beginning of the basic block, they should be added before the returned value, not before the first instruction, which might be PHI. Returns 0 is there's no non-PHI instruction.

Declared at: llvm/include/llvm/IR/BasicBlock.h:162

llvm::Instruction* getFirstNonPHI()

Declared at: llvm/include/llvm/IR/BasicBlock.h:163

llvm::Instruction* getFirstNonPHIOrDbg(
    bool SkipPseudoOp = true)

Declared at: llvm/include/llvm/IR/BasicBlock.h:172

Parameters

bool SkipPseudoOp = true

const llvm::Instruction* getFirstNonPHIOrDbg(
    bool SkipPseudoOp = true) const

Description

Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic, or any pseudo operation if \c SkipPseudoOp is true.

Declared at: llvm/include/llvm/IR/BasicBlock.h:171

Parameters

bool SkipPseudoOp = true

llvm::Instruction* getFirstNonPHIOrDbgOrLifetime(
    bool SkipPseudoOp = true)

Declared at: llvm/include/llvm/IR/BasicBlock.h:183

Parameters

bool SkipPseudoOp = true

const llvm::Instruction*
getFirstNonPHIOrDbgOrLifetime(
    bool SkipPseudoOp = true) const

Description

Returns a pointer to the first instruction in this block that is not a PHINode, a debug intrinsic, or a lifetime intrinsic, or any pseudo operation if \c SkipPseudoOp is true.

Declared at: llvm/include/llvm/IR/BasicBlock.h:182

Parameters

bool SkipPseudoOp = true

const llvm::BasicBlock::InstListType&
getInstList() const

Description

Return the underlying instruction list container. Currently you need to access the underlying instruction list container directly if you want to modify it.

Declared at: llvm/include/llvm/IR/BasicBlock.h:364

llvm::BasicBlock::InstListType& getInstList()

Declared at: llvm/include/llvm/IR/BasicBlock.h:365

Optional<uint64_t> getIrrLoopHeaderWeight() const

Declared at: llvm/include/llvm/IR/BasicBlock.h:488

const llvm::LandingPadInst* getLandingPadInst()
    const

Description

Return the landingpad instruction associated with the landing pad.

Declared at: llvm/include/llvm/IR/BasicBlock.h:475

llvm::LandingPadInst* getLandingPadInst()

Declared at: llvm/include/llvm/IR/BasicBlock.h:476

llvm::Module* getModule()

Declared at: llvm/include/llvm/IR/BasicBlock.h:112

const llvm::Module* getModule() const

Description

Return the module owning the function this basic block belongs to, or nullptr if the function does not have a module. Note: this is undefined behavior if the block does not have a parent.

Declared at: llvm/include/llvm/IR/BasicBlock.h:111

const llvm::Function* getParent() const

Description

Return the enclosing method, or null if none.

Declared at: llvm/include/llvm/IR/BasicBlock.h:104

llvm::Function* getParent()

Declared at: llvm/include/llvm/IR/BasicBlock.h:105

llvm::CallInst* getPostdominatingDeoptimizeCall()

Declared at: llvm/include/llvm/IR/BasicBlock.h:142

const llvm::CallInst*
getPostdominatingDeoptimizeCall() const

Description

Returns the call instruction calling @ llvm.experimental.deoptimize that is present either in current basic block or in block that is a unique successor to current block, if such call is present. Otherwise, returns null.

Declared at: llvm/include/llvm/IR/BasicBlock.h:141

const llvm::BasicBlock* getSinglePredecessor()
    const

Description

Return the predecessor of this block if it has a single predecessor block. Otherwise return a null pointer.

Declared at: llvm/include/llvm/IR/BasicBlock.h:244

llvm::BasicBlock* getSinglePredecessor()

Declared at: llvm/include/llvm/IR/BasicBlock.h:245

const llvm::BasicBlock* getSingleSuccessor() const

Description

Return the successor of this block if it has a single successor. Otherwise return a null pointer. This method is analogous to getSinglePredecessor above.

Declared at: llvm/include/llvm/IR/BasicBlock.h:272

llvm::BasicBlock* getSingleSuccessor()

Declared at: llvm/include/llvm/IR/BasicBlock.h:273

static llvm::BasicBlock::InstListType
    llvm::BasicBlock::*
    getSublistAccess(llvm::Instruction*)

Description

Returns a pointer to a member of the instruction list.

Declared at: llvm/include/llvm/IR/BasicBlock.h:368

Parameters

llvm::Instruction*

const llvm::CallInst*
getTerminatingDeoptimizeCall() const

Description

Returns the call instruction calling @ llvm.experimental.deoptimize prior to the terminating return instruction of this basic block, if such a call is present. Otherwise, returns null.

Declared at: llvm/include/llvm/IR/BasicBlock.h:132

llvm::CallInst* getTerminatingDeoptimizeCall()

Declared at: llvm/include/llvm/IR/BasicBlock.h:133

const llvm::CallInst* getTerminatingMustTailCall()
    const

Description

Returns the call instruction marked 'musttail' prior to the terminating return instruction of this basic block, if such a call is present. Otherwise, returns null.

Declared at: llvm/include/llvm/IR/BasicBlock.h:150

llvm::CallInst* getTerminatingMustTailCall()

Declared at: llvm/include/llvm/IR/BasicBlock.h:151

const llvm::Instruction* getTerminator() const

Description

Returns the terminator instruction if the block is well formed or null if the block is not well formed.

Declared at: llvm/include/llvm/IR/BasicBlock.h:119

llvm::Instruction* getTerminator()

Declared at: llvm/include/llvm/IR/BasicBlock.h:124

llvm::BasicBlock* getUniquePredecessor()

Declared at: llvm/include/llvm/IR/BasicBlock.h:257

const llvm::BasicBlock* getUniquePredecessor()
    const

Description

Return the predecessor of this block if it has a unique predecessor block. Otherwise return a null pointer. Note that unique predecessor doesn't mean single edge, there can be multiple edges from the unique predecessor to this block (for example a switch statement with multiple cases having the same destination).

Declared at: llvm/include/llvm/IR/BasicBlock.h:256

const llvm::BasicBlock* getUniqueSuccessor() const

Description

Return the successor of this block if it has a unique successor. Otherwise return a null pointer. This method is analogous to getUniquePredecessor above.

Declared at: llvm/include/llvm/IR/BasicBlock.h:282

llvm::BasicBlock* getUniqueSuccessor()

Declared at: llvm/include/llvm/IR/BasicBlock.h:283

llvm::ValueSymbolTable* getValueSymbolTable()

Description

Returns a pointer to the symbol table if one exists.

Declared at: llvm/include/llvm/IR/BasicBlock.h:373

bool hasAddressTaken() const

Description

Returns true if there are any uses of this basic block other than direct branches, switches, etc. to it.

Declared at: llvm/include/llvm/IR/BasicBlock.h:449

bool hasNPredecessors(unsigned int N) const

Description

Return true if this block has exactly N predecessors.

Declared at: llvm/include/llvm/IR/BasicBlock.h:263

Parameters

unsigned int N

bool hasNPredecessorsOrMore(unsigned int N) const

Description

Return true if this block has N predecessors or more.

Declared at: llvm/include/llvm/IR/BasicBlock.h:266

Parameters

unsigned int N

void insertInto(
    llvm::Function* Parent,
    llvm::BasicBlock* InsertBefore = nullptr)

Description

Insert unlinked basic block into a function. Inserts an unlinked basic block into \c Parent. If \c InsertBefore is provided, inserts before that basic block, otherwise inserts at the end.

Declared at: llvm/include/llvm/IR/BasicBlock.h:240

Parameters

llvm::Function* Parent
llvm::BasicBlock* InsertBefore = nullptr

iterator_range<filter_iterator<
    BasicBlock::iterator,
    std::function<bool(Instruction&)>>>
instructionsWithoutDebug(bool SkipPseudoOp = true)

Description

Return an iterator range over the instructions in the block, skipping any debug instructions. Skip and any pseudo operations as well if \c SkipPseudoOp is true.

Declared at: llvm/include/llvm/IR/BasicBlock.h:211

Parameters

bool SkipPseudoOp = true

iterator_range<filter_iterator<
    BasicBlock::const_iterator,
    std::function<bool(const Instruction&)>>>
instructionsWithoutDebug(
    bool SkipPseudoOp = true) const

Description

Return a const iterator range over the instructions in the block, skipping any debug instructions. Skip any pseudo operations as well if \c SkipPseudoOp is true.

Declared at: llvm/include/llvm/IR/BasicBlock.h:204

Parameters

bool SkipPseudoOp = true

void invalidateOrders()

Description

Mark instruction ordering invalid. Done on every instruction insert.

Declared at: llvm/include/llvm/IR/BasicBlock.h:496

bool isEHPad() const

Description

Return true if this basic block is an exception handling block.

Declared at: llvm/include/llvm/IR/BasicBlock.h:466

bool isEntryBlock() const

Description

Return true if this is the entry block of the containing function. This method can only be used on blocks that have a parent function.

Declared at: llvm/include/llvm/IR/BasicBlock.h:486

bool isInstrOrderValid() const

Description

Returns true if the Order field of child Instructions is valid.

Declared at: llvm/include/llvm/IR/BasicBlock.h:491

bool isLandingPad() const

Description

Return true if this basic block is a landing pad. Being a ``landing pad'' means that the basic block is the destination of the 'unwind' edge of an invoke instruction.

Declared at: llvm/include/llvm/IR/BasicBlock.h:472

bool isLegalToHoistInto() const

Description

Return true if it is legal to hoist instructions into this block.

Declared at: llvm/include/llvm/IR/BasicBlock.h:482

void moveAfter(llvm::BasicBlock* MovePos)

Description

Unlink this basic block from its current function and insert it right after \p MovePos in the function \p MovePos lives in.

Declared at: llvm/include/llvm/IR/BasicBlock.h:232

Parameters

llvm::BasicBlock* MovePos

void moveBefore(llvm::BasicBlock* MovePos)

Description

Unlink this basic block from its current function and insert it into the function that \p MovePos lives in, right before \p MovePos.

Declared at: llvm/include/llvm/IR/BasicBlock.h:228

Parameters

llvm::BasicBlock* MovePos

iterator_range<llvm::BasicBlock::phi_iterator>
phis()

Declared at: llvm/include/llvm/IR/BasicBlock.h:358

iterator_range<
    llvm::BasicBlock::const_phi_iterator>
phis() const

Description

Returns a range that iterates over the phis in the basic block. Note that this cannot be used with basic blocks that have no terminator.

Declared at: llvm/include/llvm/IR/BasicBlock.h:355

void print(
    llvm::raw_ostream& OS,
    llvm::AssemblyAnnotationWriter* AAW = nullptr,
    bool ShouldPreserveUseListOrder = false,
    bool IsForDebug = false) const

Description

Print the basic block to an output stream with an optional AssemblyAnnotationWriter.

Declared at: llvm/include/llvm/IR/BasicBlock.h:290

Parameters

llvm::raw_ostream& OS
llvm::AssemblyAnnotationWriter* AAW = nullptr
bool ShouldPreserveUseListOrder = false
bool IsForDebug = false

inline llvm::BasicBlock::const_reverse_iterator
rbegin() const

Declared at: llvm/include/llvm/IR/BasicBlock.h:303

inline llvm::BasicBlock::reverse_iterator rbegin()

Declared at: llvm/include/llvm/IR/BasicBlock.h:302

void removeFromParent()

Description

Unlink 'this' from the containing function, but do not delete it.

Declared at: llvm/include/llvm/IR/BasicBlock.h:219

void removePredecessor(
    llvm::BasicBlock* Pred,
    bool KeepOneInputPHIs = false)

Description

Update PHI nodes in this BasicBlock before removal of predecessor \p Pred. Note that this function does not actually remove the predecessor. If \p KeepOneInputPHIs is true then don't remove PHIs that are left with zero or one incoming values, and don't simplify PHIs with all incoming values the same.

Declared at: llvm/include/llvm/IR/BasicBlock.h:396

Parameters

llvm::BasicBlock* Pred
bool KeepOneInputPHIs = false

inline llvm::BasicBlock::const_reverse_iterator
rend() const

Declared at: llvm/include/llvm/IR/BasicBlock.h:305

inline llvm::BasicBlock::reverse_iterator rend()

Declared at: llvm/include/llvm/IR/BasicBlock.h:304

void renumberInstructions()

Description

Renumber instructions and mark the ordering as valid.

Declared at: llvm/include/llvm/IR/BasicBlock.h:504

void replacePhiUsesWith(llvm::BasicBlock* Old,
                        llvm::BasicBlock* New)

Description

Update all phi nodes in this basic block to refer to basic block \p New instead of basic block \p Old.

Declared at: llvm/include/llvm/IR/BasicBlock.h:455

Parameters

llvm::BasicBlock* Old
llvm::BasicBlock* New

void replaceSuccessorsPhiUsesWith(
    llvm::BasicBlock* Old,
    llvm::BasicBlock* New)

Description

Update all phi nodes in this basic block's successors to refer to basic block \p New instead of basic block \p Old.

Declared at: llvm/include/llvm/IR/BasicBlock.h:459

Parameters

llvm::BasicBlock* Old
llvm::BasicBlock* New

void replaceSuccessorsPhiUsesWith(
    llvm::BasicBlock* New)

Description

Update all phi nodes in this basic block's successors to refer to basic block \p New instead of to it.

Declared at: llvm/include/llvm/IR/BasicBlock.h:463

Parameters

llvm::BasicBlock* New

void setBasicBlockBits(
    llvm::BasicBlock::BasicBlockBits AsBits)

Description

Reinterpret our subclass bits and store them back into Value.

Declared at: llvm/include/llvm/IR/BasicBlock.h:549

Parameters

llvm::BasicBlock::BasicBlockBits AsBits

void setParent(llvm::Function* parent)

Declared at: llvm/include/llvm/IR/BasicBlock.h:67

Parameters

llvm::Function* parent

void setValueSubclassData(unsigned short D)

Description

Shadow Value::setValueSubclassData with a private forwarding method so that any future subclasses cannot accidentally use it.

Declared at: llvm/include/llvm/IR/BasicBlock.h:569

Parameters

unsigned short D

inline size_t size() const

Declared at: llvm/include/llvm/IR/BasicBlock.h:307

filter_iterator<
    BasicBlock::const_iterator,
    std::function<bool(const Instruction&)>>::
    difference_type
    sizeWithoutDebug() const

Description

Return the size of the basic block ignoring debug instructions

Declared at: llvm/include/llvm/IR/BasicBlock.h:216

llvm::BasicBlock* splitBasicBlock(
    llvm::BasicBlock::iterator I,
    const llvm::Twine& BBName = "",
    bool Before = false)

Description

Split the basic block into two basic blocks at the specified instruction. If \p Before is true, splitBasicBlockBefore handles the block splitting. Otherwise, execution proceeds as described below. Note that all instructions BEFORE the specified iterator stay as part of the original basic block, an unconditional branch is added to the original BB, and the rest of the instructions in the BB are moved to the new BB, including the old terminator. The newly formed basic block is returned. This function invalidates the specified iterator. Note that this only works on well formed basic blocks (must have a terminator), and \p 'I' must not be the end of instruction list (which must not be the end of instruction list (which would cause a degenerate basic block to be formed, having a terminator inside of the basic block). Also note that this doesn't preserve any passes. To split blocks while keeping loop information consistent, use the SplitBlock utility function.

Declared at: llvm/include/llvm/IR/BasicBlock.h:418

Parameters

llvm::BasicBlock::iterator I
const llvm::Twine& BBName = ""
bool Before = false

llvm::BasicBlock* splitBasicBlock(
    llvm::Instruction* I,
    const llvm::Twine& BBName = "",
    bool Before = false)

Declared at: llvm/include/llvm/IR/BasicBlock.h:420

Parameters

llvm::Instruction* I
const llvm::Twine& BBName = ""
bool Before = false

llvm::BasicBlock* splitBasicBlockBefore(
    llvm::BasicBlock::iterator I,
    const llvm::Twine& BBName = "")

Description

Split the basic block into two basic blocks at the specified instruction and insert the new basic blocks as the predecessor of the current block. This function ensures all instructions AFTER and including the specified iterator \p I are part of the original basic block. All Instructions BEFORE the iterator \p I are moved to the new BB and an unconditional branch is added to the new BB. The new basic block is returned. Note that this only works on well formed basic blocks (must have a terminator), and \p 'I' must not be the end of instruction list (which must not be the end of instruction list (which would cause a degenerate basic block to be formed, having a terminator inside of the basic block). \p 'I' cannot be a iterator for a PHINode cannot be a iterator for a PHINode with multiple incoming blocks. Also note that this doesn't preserve any passes. To split blocks while keeping loop information consistent, use the SplitBlockBefore utility function.

Declared at: llvm/include/llvm/IR/BasicBlock.h:442

Parameters

llvm::BasicBlock::iterator I
const llvm::Twine& BBName = ""

llvm::BasicBlock* splitBasicBlockBefore(
    llvm::Instruction* I,
    const llvm::Twine& BBName = "")

Declared at: llvm/include/llvm/IR/BasicBlock.h:443

Parameters

llvm::Instruction* I
const llvm::Twine& BBName = ""

void validateInstrOrdering() const

Description

Asserts that instruction order numbers are marked invalid, or that they are in ascending order. This is constant time if the ordering is invalid, and linear in the number of instructions if the ordering is valid. Callers should be careful not to call this in ways that make common operations O(n^2). For example, it takes O(n) time to assign order numbers to instructions, so the order should be validated no more than once after each ordering to ensure that transforms have the same algorithmic complexity when asserts are enabled as when they are disabled.

Declared at: llvm/include/llvm/IR/BasicBlock.h:514

~BasicBlock()

Declared at: llvm/include/llvm/IR/BasicBlock.h:81