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

LLVMContext & getContext () const
 getContext - Get the context in which this basic block lives.
 ~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 ()
ValueSymbolTable * getValueSymbolTable ()
 getValueSymbolTable() - returns pointer to symbol table (if any)
void dropAllReferences ()
void removePredecessor (BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
BasicBlock * splitBasicBlock (iterator I, const Twine &BBName="")

Static Public Member Functions

static BasicBlock * Create (LLVMContext &Context, const Twine &Name="", Function *Parent=0, BasicBlock *InsertBefore=0)
static iplist< Instruction >
BasicBlock::* 
getSublistAccess (Instruction *)
 getSublistAccess() - returns pointer to member of instruction list
static bool classof (const BasicBlock *)
 Methods for support type inquiry through isa, cast, and dyn_cast:.
static bool classof (const Value *V)

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 67 of file BasicBlock.h.


Member Typedef Documentation

Definition at line 71 of file BasicBlock.h.

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

Instruction iterators...

Definition at line 93 of file BasicBlock.h.

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

Definition at line 94 of file BasicBlock.h.


Constructor & Destructor Documentation

BasicBlock::~BasicBlock (  ) 

Definition at line 60 of file BasicBlock.cpp.

References dropAllReferences(), and getParent().


Member Function Documentation

LLVMContext & BasicBlock::getContext (  )  const

static BasicBlock* llvm::BasicBlock::Create ( LLVMContext &  Context,
const Twine &  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 99 of file BasicBlock.h.

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

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

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

getParent - Return the enclosing method, or null if none

Definition at line 107 of file BasicBlock.h.

Referenced by CheckForEscapingAllocas(), llvm::CloneBasicBlock(), llvm::CloneLoop(), llvm::ConstantFoldTerminator(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateAggregateRet(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateGlobalString(), llvm::DemotePHIToStack(), llvm::DemoteRegToStack(), eraseFromParent(), FoldCondBranchOnPHI(), FoldValueComparisonIntoPredecessors(), llvm::CallSite::getCaller(), getCommonReturnValue(), llvm::MemoryDependenceAnalysis::getDependency(), llvm::ProfileInfo::getExecutionCount(), llvm::Trace::getFunction(), llvm::InlineCostAnalyzer::getInlineCost(), llvm::MemoryDependenceAnalysis::getNonLocalCallDependency(), getValueSymbolTable(), HandleInlinedInvoke(), llvm::InlineFunction(), llvm::BasicInlinerImpl::inlineFunctions(), isDynamicConstant(), llvm::SelectionDAGLowering::isExportableFromCurrentBlock(), isInTailCallPosition(), llvm::AllocaInst::isStaticAlloca(), LLVMGetNextBasicBlock(), LLVMGetPreviousBasicBlock(), LLVMInsertBasicBlockInContext(), LowerToBSwap(), moveAfter(), moveBefore(), PerformHeapAllocSRoA(), llvm::Value::print(), removeFromParent(), llvm::RemoveSuccessor(), ReplaceCallWith(), llvm::SimplifyCFG(), SimplifyCondBranchToCondBranch(), splitBasicBlock(), llvm::DominanceFrontier::splitBlock(), llvm::SplitBlockPredecessors(), llvm::SplitCriticalEdge(), SplitEdgeNicely(), TryToSinkInstruction(), UpdateCallGraphAfterInlining(), and ~BasicBlock().

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

Definition at line 108 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 nodes and terminators).

Reimplemented from llvm::Value.

Definition at line 113 of file BasicBlock.h.

References llvm::Value::use_begin().

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

Reimplemented from llvm::Value.

Definition at line 114 of file BasicBlock.h.

References llvm::Value::use_begin().

TerminatorInst * BasicBlock::getTerminator (  ) 

const TerminatorInst * BasicBlock::getTerminator (  )  const

Definition at line 106 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 111 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 129 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 77 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 81 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 87 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 94 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 128 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(), llvm::SplitEdge(), and TryToSimplifyUncondBranchFromEmptyBlock().

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

Definition at line 155 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 141 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 165 of file BasicBlock.h.

References getUniquePredecessor().

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

Instruction iterator methods

Definition at line 172 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::CopyPrecedingStopPoint(), llvm::DeleteDeadPHIs(), llvm::DemotePHIToStack(), llvm::DemoteRegToStack(), llvm::DominatorTree::dominates(), DominatesMergePoint(), dropAllReferences(), equals(), EvaluateFunction(), llvm::FindAvailableLoadedValue(), llvm::findBBStopPoint(), llvm::findStopPoint(), FoldCondBranchOnPHI(), llvm::FoldSingleEntryPHINodes(), FoldTwoEntryPHINode(), llvm::Loop::getCanonicalInductionVariable(), llvm::MemoryDependenceAnalysis::getDependency(), getFirstNonPHI(), llvm::MemoryDependenceAnalysis::getNonLocalCallDependency(), llvm::MemoryDependenceAnalysis::getNonLocalPointerDependency(), HandleInlinedInvoke(), HoistThenElseCodeToIf(), llvm::InlineFunction(), llvm::InsertProfilingInitCall(), llvm::Loop::isLCSSAForm(), llvm::isSafeToLoadUnconditionally(), isTerminatorFirstRelevantInsn(), isTrivialLoopExitBlockHelper(), LLVMGetFirstInstruction(), LLVMGetLastInstruction(), LLVMGetPreviousInstruction(), MarkAliveBlocks(), llvm::MergeBasicBlockIntoOnlyPred(), llvm::MergeBlockIntoPredecessor(), llvm::SparseSolver::Print(), llvm::MSILWriter::printBasicBlock(), llvm::MSILWriter::printBranchToBlock(), llvm::MSILWriter::printPHICopy(), PushLoopPHIs(), removePredecessor(), ReplacePhiPred(), llvm::SimplifyCFG(), SimplifyCondBranchToCondBranch(), llvm::SparseSolver::Solve(), SpeculativelyExecuteBB(), splitBasicBlock(), llvm::SplitBlockPredecessors(), llvm::SplitCriticalEdge(), llvm::SplitEdge(), SplitEdgeNicely(), and TryToSimplifyUncondBranchFromEmptyBlock().

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

Definition at line 173 of file BasicBlock.h.

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

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

Definition at line 175 of file BasicBlock.h.

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

Definition at line 177 of file BasicBlock.h.

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

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

Definition at line 178 of file BasicBlock.h.

Referenced by llvm::DeleteDeadBlock().

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

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

Definition at line 180 of file BasicBlock.h.

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

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

Definition at line 182 of file BasicBlock.h.

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

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

Definition at line 188 of file BasicBlock.h.

static iplist<Instruction> BasicBlock::* llvm::BasicBlock::getSublistAccess ( Instruction *   )  [inline, static]

getSublistAccess() - returns pointer to member of instruction list

Definition at line 191 of file BasicBlock.h.

ValueSymbolTable * BasicBlock::getValueSymbolTable (  ) 

getValueSymbolTable() - returns pointer to symbol table (if any)

Definition at line 26 of file BasicBlock.cpp.

References F, and getParent().

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

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

Definition at line 199 of file BasicBlock.h.

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

Reimplemented from llvm::Value.

Definition at line 200 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 121 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 161 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 Twine &  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 242 of file BasicBlock.cpp.

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

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


Friends And Related Function Documentation

friend class SymbolTableListTraits< BasicBlock, Function > [friend]

Definition at line 77 of file BasicBlock.h.


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