LLVM API Documentation

llvm::BasicBlock Class Reference

LLVM Basic Block Representation. More...

#include <BasicBlock.h>

Inheritance diagram for llvm::BasicBlock:

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

Collaboration graph
[legend]
List of all members.

Public Types

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

Public Member Functions

 BasicBlock (const std::string &Name="", Function *Parent=0, BasicBlock *InsertBefore=0)
 ~BasicBlock ()
const FunctiongetParent () const
FunctiongetParent ()
BasicBlockgetNext ()
const BasicBlockgetNext () const
BasicBlockgetPrev ()
const BasicBlockgetPrev () const
TerminatorInstgetTerminator ()
const TerminatorInst *const getTerminator () const
InstructiongetFirstNonPHI ()
void removeFromParent ()
void eraseFromParent ()
void moveBefore (BasicBlock *MovePos)
BasicBlockgetSinglePredecessor ()
const BasicBlockgetSinglePredecessor () const
iterator begin ()
const_iterator begin () const
iterator end ()
const_iterator end () const
size_t size () const
bool empty () const
const Instructionfront () const
Instructionfront ()
const Instructionback () const
Instructionback ()
const InstListTypegetInstList () const
InstListTypegetInstList ()
virtual void print (std::ostream &OS) const
void print (std::ostream &OS, AssemblyAnnotationWriter *AAW) const
void dropAllReferences ()
void removePredecessor (BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
BasicBlocksplitBasicBlock (iterator I, const std::string &BBName="")

Static Public Member Functions

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


Member Typedef Documentation

typedef iplist<Instruction> llvm::BasicBlock::InstListType

Definition at line 51 of file BasicBlock.h.

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

Instruction iterators...

Definition at line 66 of file BasicBlock.h.

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

Definition at line 67 of file BasicBlock.h.


Constructor & Destructor Documentation

BasicBlock::BasicBlock ( const std::string &  Name = "",
Function Parent = 0,
BasicBlock InsertBefore = 0 
)

BasicBlock ctor - 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.

Definition at line 63 of file BasicBlock.cpp.

References llvm::LeakDetector::addGarbageObject(), and llvm::Function::getBasicBlockList().

BasicBlock::~BasicBlock (  ) 

Definition at line 82 of file BasicBlock.cpp.

References dropAllReferences(), and getParent().


Member Function Documentation

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

getParent - Return the enclosing method, or null if none

Definition at line 79 of file BasicBlock.h.

Referenced by CheckForEscapingAllocas(), llvm::CloneBasicBlock(), llvm::ConstantFoldTerminator(), createSlotMachine(), llvm::DemoteRegToStack(), eraseFromParent(), FoldCondBranchOnPHI(), FoldValueComparisonIntoPredecessors(), llvm::DSCallSite::getCaller(), llvm::CallSite::getCaller(), getCommonReturnValue(), getConstantEvolvingPHI(), llvm::ProfileInfo::getExecutionCount(), getFnForValue(), llvm::Trace::getFunction(), getModuleFromVal(), HandleInlinedInvoke(), IdenticalComplexInst(), llvm::InlineFunction(), llvm::X86TargetLowering::InsertAtEndOfBasicBlock(), llvm::PPCTargetLowering::InsertAtEndOfBasicBlock(), InsertCodeToShowFunctionExit(), InsertInstrumentationCall(), InsertPrintInst(), isDynamicConstant(), isIdenticalBinaryInst(), isIdenticalTernaryInst(), isUsedOutsideOfDefiningBlock(), moveBefore(), llvm::CallTargetFinder::print(), llvm::Instruction::print(), print(), PrintOps(), removeFromParent(), ReplaceCallWith(), ReplaceUsesOfBlockWith(), llvm::Inliner::runOnSCC(), llvm::BasicBlockPass::runPass(), llvm::Value::setName(), llvm::SimplifyCFG(), splitBasicBlock(), llvm::SplitCriticalEdge(), TryToSinkInstruction(), and ~BasicBlock().

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

Definition at line 80 of file BasicBlock.h.

BasicBlock* llvm::BasicBlock::getNext (  )  [inline]

Definition at line 83 of file BasicBlock.h.

References Next.

Referenced by ReleasePtrSeqNumbers(), splitBasicBlock(), and llvm::SplitCriticalEdge().

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

Definition at line 84 of file BasicBlock.h.

References Next.

BasicBlock* llvm::BasicBlock::getPrev (  )  [inline]

Definition at line 85 of file BasicBlock.h.

References Prev.

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

Definition at line 86 of file BasicBlock.h.

References Prev.

TerminatorInst * BasicBlock::getTerminator (  ) 

getTerminator() - If this is a well formed basic block, then this returns a pointer to the terminator instruction. If it is not, then you get a null pointer back.

Definition at line 115 of file BasicBlock.cpp.

Referenced by AddReachableCodeToWorklist(), ApproximateLoopSize(), BlockIsSimpleEnoughToThreadThrough(), llvm::CloneBasicBlock(), llvm::CloneFunctionInto(), llvm::ConstantFoldTerminator(), DominatesMergePoint(), FoldCondBranchOnPHI(), FoldTwoEntryPHINode(), llvm::ProfileInfoLoader::getBlockCounts(), llvm::ProfileInfoLoader::getEdgeCounts(), GetIfCondition(), HandleInlinedInvoke(), llvm::InlineFunction(), InsertCodeToShowFunctionExit(), isBlockSimpleEnough(), IsTrivialUnswitchCondition(), llvm::BytecodeReader::ParseInstructionList(), recBackEdge(), llvm::UnifyFunctionExitNodes::runOnFunction(), llvm::SimplifyCFG(), SimplifyEqualityComparisonWithOnlyPredecessor(), splitBasicBlock(), llvm::SplitCriticalEdge(), llvm::succ_begin(), llvm::succ_end(), TraceValuesAtBBExit(), and llvm::SCEVExpander::visitAddRecExpr().

const TerminatorInst *const BasicBlock::getTerminator (  )  const

Definition at line 120 of file BasicBlock.cpp.

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 125 of file BasicBlock.cpp.

References begin().

void BasicBlock::removeFromParent (  ) 

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

Definition at line 98 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 102 of file BasicBlock.cpp.

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

Referenced by llvm::InlineFunction(), and TryToSimplifyUncondBranchFromEmptyBlock().

void BasicBlock::moveBefore ( BasicBlock MovePos  ) 

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

Definition at line 109 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.

Definition at line 143 of file BasicBlock.cpp.

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

Referenced by CanPropagatePredecessorsForPHIs(), getSinglePredecessor(), and llvm::SimplifyCFG().

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

Definition at line 120 of file BasicBlock.h.

References getSinglePredecessor().

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

Instruction iterator methods

Definition at line 127 of file BasicBlock.h.

Referenced by llvm::AliasSetTracker::add(), AddPredecessorToBlock(), AddReachableCodeToWorklist(), ApproximateLoopSize(), BlockIsSimpleEnoughToThreadThrough(), llvm::Interpreter::callFunction(), CanPropagatePredecessorsForPHIs(), CheckForEscapingAllocas(), llvm::CloneAndPruneFunctionInto(), llvm::CloneBasicBlock(), llvm::CloneFunctionInto(), llvm::CloneTrace(), llvm::CloneTraceInto(), CollapsePhi(), DominatesMergePoint(), dropAllReferences(), EvaluateFunction(), FindPHIToPartitionLoops(), FoldCondBranchOnPHI(), FoldTwoEntryPHINode(), getFirstNonPHI(), HandleInlinedInvoke(), HoistThenElseCodeToIf(), llvm::SlotCalculator::incorporateFunction(), llvm::RSProfilers_std::IncrementCounterInBlock(), llvm::IncrementCounterInBlock(), llvm::InlineFunction(), InsertCodeToShowFunctionEntry(), InsertGEPComputeCode(), InsertInstrumentationCall(), llvm::InsertProfilingInitCall(), isBlockSimpleEnough(), isSafeToLoadUnconditionally(), isTrivialLoopExitBlockHelper(), IsTrivialUnswitchCondition(), LinkFunctionBody(), OptimizeNoopCopyExpression(), ReleasePtrSeqNumbers(), removePredecessor(), ReplacePhiPred(), ReplaceUsesOfBlockWith(), llvm::Inliner::runOnSCC(), llvm::SimplifyCFG(), llvm::SplitCriticalEdge(), TraceValuesAtBBExit(), TryToSimplifyUncondBranchFromEmptyBlock(), TryToSinkInstruction(), and llvm::Interpreter::visitCallSite().

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

Definition at line 128 of file BasicBlock.h.

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

Definition at line 129 of file BasicBlock.h.

Referenced by llvm::AliasSetTracker::add(), AddReachableCodeToWorklist(), ApproximateLoopSize(), llvm::BuildMI(), CheckForEscapingAllocas(), llvm::CloneAndPruneFunctionInto(), llvm::CloneBasicBlock(), llvm::CloneFunctionInto(), llvm::CloneTraceInto(), CollapsePhi(), dropAllReferences(), HandleInlinedInvoke(), llvm::SlotCalculator::incorporateFunction(), llvm::InlineFunction(), isTrivialLoopExitBlockHelper(), IsTrivialUnswitchCondition(), LinkFunctionBody(), ReleasePtrSeqNumbers(), ReplacePhiPred(), ReplaceUsesOfBlockWith(), llvm::Inliner::runOnSCC(), llvm::SimplifyCFG(), and splitBasicBlock().

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

Definition at line 130 of file BasicBlock.h.

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

Definition at line 132 of file BasicBlock.h.

Referenced by FoldValueComparisonIntoPredecessors(), isBlockSimpleEnough(), and llvm::BytecodeReader::ParseInstruction().

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

Definition at line 133 of file BasicBlock.h.

Referenced by llvm::SimplifyCFG().

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

Definition at line 134 of file BasicBlock.h.

Referenced by llvm::AliasAnalysis::canBasicBlockModify(), CanPropagatePredecessorsForPHIs(), isBlockSimpleEnough(), removePredecessor(), llvm::UnifyFunctionExitNodes::runOnFunction(), llvm::SimplifyCFG(), and TryToSimplifyUncondBranchFromEmptyBlock().

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

Definition at line 135 of file BasicBlock.h.

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

Definition at line 136 of file BasicBlock.h.

Referenced by llvm::AliasAnalysis::canBasicBlockModify(), and llvm::SimplifyCFG().

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

Definition at line 137 of file BasicBlock.h.

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

getInstList() - Return the underlying instruction list container. You need to access it directly if you want to modify it currently.

Definition at line 142 of file BasicBlock.h.

Referenced by AssociativeOpt(), llvm::CloneBasicBlock(), llvm::ConstantFoldTerminator(), llvm::ConvertExpressionToType(), llvm::BinaryOperator::create(), llvm::Instruction::eraseFromParent(), ErasePossiblyDeadInstructionTree(), FoldCondBranchOnPHI(), FoldTwoEntryPHINode(), HandleInlinedInvoke(), HoistThenElseCodeToIf(), llvm::InlineFunction(), llvm::Instruction::Instruction(), llvm::Instruction::moveBefore(), llvm::BytecodeReader::ParseInstruction(), RecursiveDelete(), llvm::Instruction::removeFromParent(), removePredecessor(), llvm::ReplaceInstWithInst(), llvm::UnifyFunctionExitNodes::runOnFunction(), llvm::SimplifyCFG(), splitBasicBlock(), and TryToSimplifyUncondBranchFromEmptyBlock().

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

Definition at line 143 of file BasicBlock.h.

virtual void llvm::BasicBlock::print ( std::ostream &  OS  )  const [inline, virtual]

print - Implement operator<< on Value...

Implements llvm::Value.

Definition at line 145 of file BasicBlock.h.

Referenced by llvm::MachineFunction::print(), and llvm::MachineBasicBlock::print().

void BasicBlock::print ( std::ostream &  OS,
AssemblyAnnotationWriter AAW 
) const

Definition at line 1299 of file AsmWriter.cpp.

References getParent(), and llvm::AssemblyWriter::write().

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

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

Definition at line 149 of file BasicBlock.h.

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

Reimplemented from llvm::Value.

Definition at line 150 of file BasicBlock.h.

References llvm::Value::BasicBlockVal, and V.

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

Definition at line 157 of file BasicBlock.cpp.

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

Referenced by llvm::ConstantFoldTerminator(), FoldCondBranchOnPHI(), FoldValueComparisonIntoPredecessors(), HandleInlinedInvoke(), llvm::RemoveSuccessor(), llvm::SimplifyCFG(), and SimplifyEqualityComparisonWithOnlyPredecessor().

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

Definition at line 238 of file BasicBlock.cpp.

References E, end(), llvm::PHINode::getBasicBlockIndex(), getInstList(), getNext(), getParent(), getTerminator(), II, llvm::PHINode::setIncomingBlock(), llvm::succ_begin(), and llvm::succ_end().

Referenced by HandleInlinedInvoke(), and llvm::InlineFunction().


Friends And Related Function Documentation

friend class SymbolTableListTraits< BasicBlock, Function, Function > [friend]

Definition at line 59 of file BasicBlock.h.


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