LLVM API Documentation

llvm::BasicBlock Class Reference

LLVM Basic Block Representation. More...

#include <BasicBlock.h>

Inheritance diagram for llvm::BasicBlock:
[legend]
Collaboration diagram for llvm::BasicBlock:
[legend]

List of all members.

Public Types

typedef iplist< Instruction > InstListType
typedef InstListType::iterator iterator
 Instruction iterators...
typedef
InstListType::const_iterator 
const_iterator

Public Member Functions

 ~BasicBlock ()
const Function * getParent () const
Function * getParent ()
Instruction * use_back ()
const Instruction * use_back () const
TerminatorInst * getTerminator ()
const TerminatorInst * getTerminator () const
Instruction * getFirstNonPHI ()
const Instruction * getFirstNonPHI () const
void removeFromParent ()
void eraseFromParent ()
void moveBefore (BasicBlock *MovePos)
void moveAfter (BasicBlock *MovePos)
BasicBlock * getSinglePredecessor ()
const BasicBlock * getSinglePredecessor () const
BasicBlock * getUniquePredecessor ()
const BasicBlock * getUniquePredecessor () const
iterator begin ()
const_iterator begin () const
iterator end ()
const_iterator end () const
size_t size () const
bool empty () const
const Instruction & front () const
Instruction & front ()
const Instruction & back () const
Instruction & back ()
const InstListType & getInstList () const
InstListType & getInstList ()
void dropAllReferences ()
void removePredecessor (BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
BasicBlock * splitBasicBlock (iterator I, const std::string &BBName="")

Static Public Member Functions

static BasicBlock * Create (const std::string &Name="", Function *Parent=0, BasicBlock *InsertBefore=0)
static bool classof (const BasicBlock *)
 Methods for support type inquiry through isa, cast, and dyn_cast:.
static bool classof (const Value *V)
static unsigned getInstListOffset ()

Friends

class SymbolTableListTraits< BasicBlock, Function >


Detailed 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 TerminatorInst instruction. TerminatorInst's 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".

Definition at line 50 of file BasicBlock.h.


Member Typedef Documentation

Definition at line 53 of file BasicBlock.h.

typedef InstListType::iterator llvm::BasicBlock::iterator

Instruction iterators...

Definition at line 72 of file BasicBlock.h.

typedef InstListType::const_iterator llvm::BasicBlock::const_iterator

Definition at line 73 of file BasicBlock.h.


Constructor & Destructor Documentation

BasicBlock::~BasicBlock (  ) 

Definition at line 96 of file BasicBlock.cpp.

References dropAllReferences(), and getParent().


Member Function Documentation

static BasicBlock* llvm::BasicBlock::Create ( const std::string &  Name = "",
Function *  Parent = 0,
BasicBlock *  InsertBefore = 0 
) [inline, static]

Create - 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.

Definition at line 78 of file BasicBlock.h.

References llvm::ISD::BasicBlock, and Name.

Referenced by llvm::CloneBasicBlock(), LowerPartSelect(), LowerPartSet(), PerformHeapAllocSRoA(), llvm::JIT::runFunction(), llvm::UnifyFunctionExitNodes::runOnFunction(), splitBasicBlock(), llvm::SplitBlockPredecessors(), and llvm::SplitCriticalEdge().

const Function* llvm::BasicBlock::getParent (  )  const [inline]

Function* llvm::BasicBlock::getParent (  )  [inline]

Definition at line 87 of file BasicBlock.h.

Instruction* llvm::BasicBlock::use_back (  )  [inline]

use_back - Specialize the methods defined in Value, as we know that an BasicBlock can only be used by Instructions (specifically PHI and terms).

Reimplemented from llvm::Value.

Definition at line 91 of file BasicBlock.h.

References llvm::Value::use_begin().

const Instruction* llvm::BasicBlock::use_back (  )  const [inline]

Reimplemented from llvm::Value.

Definition at line 92 of file BasicBlock.h.

References llvm::Value::use_begin().

TerminatorInst * BasicBlock::getTerminator (  ) 

const TerminatorInst * BasicBlock::getTerminator (  )  const

Definition at line 142 of file BasicBlock.cpp.

References llvm::dyn_cast().

Instruction * BasicBlock::getFirstNonPHI (  ) 

Returns a pointer to the first instructon in this block that is not a PHINode instruction. When adding instruction 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.

Definition at line 147 of file BasicBlock.cpp.

References begin().

Referenced by getFirstNonPHI(), getJumpThreadDuplicationCost(), llvm::RSProfilers_std::IncrementCounterInBlock(), llvm::IncrementCounterInBlock(), OptimizeCmpExpression(), OptimizeNoopCopyExpression(), llvm::SimplifyCFG(), and TryToSinkInstruction().

const Instruction* llvm::BasicBlock::getFirstNonPHI (  )  const [inline]

Definition at line 107 of file BasicBlock.h.

References getFirstNonPHI().

void BasicBlock::removeFromParent (  ) 

removeFromParent - This method unlinks 'this' from the containing function, but does not delete it.

Definition at line 113 of file BasicBlock.cpp.

References llvm::Function::getBasicBlockList(), and getParent().

void BasicBlock::eraseFromParent (  ) 

eraseFromParent - This method unlinks 'this' from the containing function and deletes it.

Definition at line 117 of file BasicBlock.cpp.

References llvm::Function::getBasicBlockList(), and getParent().

Referenced by llvm::CloneAndPruneFunctionInto(), llvm::DeleteDeadBlock(), FoldBlockIntoPredecessor(), llvm::InlineFunction(), llvm::MergeBasicBlockIntoOnlyPred(), and llvm::MergeBlockIntoPredecessor().

void BasicBlock::moveBefore ( BasicBlock *  MovePos  ) 

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

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

Definition at line 123 of file BasicBlock.cpp.

References llvm::Function::getBasicBlockList(), and getParent().

void BasicBlock::moveAfter ( BasicBlock *  MovePos  ) 

moveAfter - Unlink this basic block from its current function and insert it into the function that MovePos lives in, right after MovePos.

moveAfter - Unlink this basic block from its current function and insert it into the function that MovePos lives in, right after MovePos.

Definition at line 130 of file BasicBlock.cpp.

References llvm::Function::getBasicBlockList(), and getParent().

BasicBlock * BasicBlock::getSinglePredecessor (  ) 

getSinglePredecessor - If this basic block has a single predecessor block, return the block, otherwise return a null pointer.

getSinglePredecessor - If this basic block has a single predecessor block, return the block, otherwise return a null pointer.

Definition at line 164 of file BasicBlock.cpp.

References E, PI, llvm::pred_begin(), and llvm::pred_end().

Referenced by CanPropagatePredecessorsForPHIs(), llvm::CloneAndPruneFunctionInto(), llvm::DeleteDeadBlock(), llvm::DemoteRegToStack(), FoldBlockIntoPredecessor(), getSinglePredecessor(), llvm::MergeBasicBlockIntoOnlyPred(), llvm::SimplifyCFG(), and llvm::SplitEdge().

const BasicBlock* llvm::BasicBlock::getSinglePredecessor (  )  const [inline]

Definition at line 133 of file BasicBlock.h.

References getSinglePredecessor().

BasicBlock * BasicBlock::getUniquePredecessor (  ) 

getUniquePredecessor - If this basic block has a unique predecessor block, return the 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).

getUniquePredecessor - If this basic block has a unique predecessor block, return the 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).

Definition at line 177 of file BasicBlock.cpp.

References E, PI, llvm::pred_begin(), and llvm::pred_end().

Referenced by llvm::findBBStopPoint(), and getUniquePredecessor().

const BasicBlock* llvm::BasicBlock::getUniquePredecessor (  )  const [inline]

Definition at line 143 of file BasicBlock.h.

References getUniquePredecessor().

iterator llvm::BasicBlock::begin (  )  [inline]

Instruction iterator methods

Definition at line 150 of file BasicBlock.h.

Referenced by llvm::AliasSetTracker::add(), AddPredecessorToBlock(), AddReachableCodeToWorklist(), ApproximateLoopSize(), BlockIsSimpleEnoughToThreadThrough(), llvm::Interpreter::callFunction(), CanPropagatePredecessorsForPHIs(), CheckForEscapingAllocas(), llvm::CloneAndPruneFunctionInto(), llvm::CloneBasicBlock(), llvm::CloneLoop(), llvm::CloneTrace(), CollapsePhi(), copyCatchInfo(), llvm::DemotePHIToStack(), llvm::DemoteRegToStack(), llvm::DominatorTree::dominates(), DominatesMergePoint(), dropAllReferences(), equals(), EvaluateFunction(), llvm::FindAvailableLoadedValue(), llvm::findBBStopPoint(), llvm::findStopPoint(), FoldCondBranchOnPHI(), llvm::FoldSingleEntryPHINodes(), FoldTwoEntryPHINode(), llvm::MemoryDependenceAnalysis::getDependency(), getFirstNonPHI(), llvm::MemoryDependenceAnalysis::getNonLocalCallDependency(), llvm::MemoryDependenceAnalysis::getNonLocalPointerDependency(), HandleInlinedInvoke(), HoistThenElseCodeToIf(), llvm::InlineFunction(), llvm::SCEVExpander::InsertBinop(), llvm::InsertProfilingInitCall(), isSafeToLoadUnconditionally(), isTrivialLoopExitBlockHelper(), LLVMGetFirstInstruction(), LLVMGetLastInstruction(), LLVMGetPreviousInstruction(), MarkAliveBlocks(), llvm::MergeBasicBlockIntoOnlyPred(), llvm::MergeBlockIntoPredecessor(), llvm::SparseSolver::Print(), removePredecessor(), ReplacePhiPred(), llvm::SimplifyCFG(), SimplifyCondBranchToCondBranch(), SimplifyCondBranchToTwoReturns(), SpeculativelyExecuteBB(), splitBasicBlock(), llvm::SplitBlockPredecessors(), llvm::SplitCriticalEdge(), llvm::SplitEdge(), SplitEdgeNicely(), TryToSimplifyUncondBranchFromEmptyBlock(), and llvm::SCEVExpander::visitAddRecExpr().

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

Definition at line 151 of file BasicBlock.h.

iterator llvm::BasicBlock::end (  )  [inline]

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

Definition at line 153 of file BasicBlock.h.

size_t llvm::BasicBlock::size (  )  const [inline]

Definition at line 155 of file BasicBlock.h.

Referenced by FoldValueComparisonIntoPredecessors(), and llvm::SimplifyCFG().

bool llvm::BasicBlock::empty (  )  const [inline]

Definition at line 156 of file BasicBlock.h.

Referenced by llvm::DeleteDeadBlock().

const Instruction& llvm::BasicBlock::front (  )  const [inline]

Instruction& llvm::BasicBlock::front (  )  [inline]

Definition at line 158 of file BasicBlock.h.

const Instruction& llvm::BasicBlock::back (  )  const [inline]

Instruction& llvm::BasicBlock::back (  )  [inline]

Definition at line 160 of file BasicBlock.h.

const InstListType& llvm::BasicBlock::getInstList (  )  const [inline]

InstListType& llvm::BasicBlock::getInstList (  )  [inline]

Definition at line 166 of file BasicBlock.h.

static bool llvm::BasicBlock::classof ( const BasicBlock *   )  [inline, static]

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

Definition at line 169 of file BasicBlock.h.

static bool llvm::BasicBlock::classof ( const Value *  V  )  [inline, static]

Reimplemented from llvm::Value.

Definition at line 170 of file BasicBlock.h.

References llvm::Value::BasicBlockVal, and llvm::Value::getValueID().

void BasicBlock::dropAllReferences (  ) 

dropAllReferences() - This function causes all the subinstructions to "let go" of all references that they 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.

Definition at line 157 of file BasicBlock.cpp.

References begin(), E, and end().

Referenced by ~BasicBlock().

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

removePredecessor - This method is used to notify a BasicBlock that the specified Predecessor of the block is no longer able to reach it. This is actually not used to update the Predecessor list, but is actually used to update the PHI nodes that reside in the block. Note that this should be called while the predecessor still refers to this block.

removePredecessor - This method is used to notify a BasicBlock that the specified Predecessor of the block is no longer able to reach it. This is actually not used to update the Predecessor list, but is actually used to update the PHI nodes that reside in the block. Note that this should be called while the predecessor still refers to this block.

Definition at line 197 of file BasicBlock.cpp.

References begin(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), front(), llvm::UndefValue::get(), llvm::PHINode::getIncomingBlock(), getInstList(), llvm::PHINode::getNumIncomingValues(), llvm::PHINode::hasConstantValue(), llvm::Value::hasNUsesOrMore(), II, llvm::pred_begin(), llvm::pred_end(), llvm::PHINode::removeIncomingValue(), and llvm::Value::replaceAllUsesWith().

Referenced by ChangeToCall(), ChangeToUnreachable(), llvm::ConstantFoldTerminator(), llvm::DeleteDeadBlock(), FoldCondBranchOnPHI(), FoldValueComparisonIntoPredecessors(), HandleInlinedInvoke(), llvm::RemoveSuccessor(), llvm::SimplifyCFG(), SimplifyCondBranchToTwoReturns(), SimplifyEqualityComparisonWithOnlyPredecessor(), llvm::SplitCriticalEdge(), and SplitEdgeNicely().

BasicBlock * BasicBlock::splitBasicBlock ( iterator  I,
const std::string &  BBName = "" 
)

splitBasicBlock - This splits a basic block into two at the specified instruction. 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 BasicBlock is returned. This function invalidates the specified iterator.

Note that this only works on well formed basic blocks (must have a terminator), and 'I' 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).

splitBasicBlock - This splits a basic block into two at the specified instruction. Note that all instructions BEFORE the specified iterator stay as part of the original basic block, an unconditional branch is added to the new BB, and the rest of the instructions in the BB are moved to the new BB, including the old terminator. This invalidates the iterator.

Note that this only works on well formed basic blocks (must have a terminator), and 'I' 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).

Definition at line 278 of file BasicBlock.cpp.

References begin(), llvm::BranchInst::Create(), Create(), llvm::dyn_cast(), E, end(), llvm::PHINode::getBasicBlockIndex(), getInstList(), getParent(), getTerminator(), II, llvm::next(), llvm::PHINode::setIncomingBlock(), llvm::succ_begin(), and llvm::succ_end().

Referenced by llvm::InlineFunction(), PerformHeapAllocSRoA(), and llvm::SplitBlock().

static unsigned llvm::BasicBlock::getInstListOffset (  )  [inline, static]

Definition at line 207 of file BasicBlock.h.

References InstList.

Referenced by llvm::ilist_traits< Instruction >::getListOffset().


Friends And Related Function Documentation

friend class SymbolTableListTraits< BasicBlock, Function > [friend]

Definition at line 59 of file BasicBlock.h.


The documentation for this class was generated from the following files: