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 FunctiongetParent () const
FunctiongetParent ()
Instructionuse_back ()
const Instructionuse_back () const
TerminatorInstgetTerminator ()
const TerminatorInstgetTerminator () const
InstructiongetFirstNonPHI ()
const InstructiongetFirstNonPHI () const
void removeFromParent ()
void eraseFromParent ()
void moveBefore (BasicBlock *MovePos)
void moveAfter (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 ()
void dropAllReferences ()
void removePredecessor (BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
BasicBlocksplitBasicBlock (iterator I, const std::string &BBName="")

Static Public Member Functions

static BasicBlockCreate (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 52 of file BasicBlock.h.


Member Typedef Documentation

Definition at line 55 of file BasicBlock.h.

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

Instruction iterators...

Definition at line 74 of file BasicBlock.h.

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

Definition at line 75 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 80 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 89 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 93 of file BasicBlock.h.

References llvm::Value::use_begin().

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

Reimplemented from llvm::Value.

Definition at line 94 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 109 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(), FoldBlockIntoPredecessor(), llvm::InlineFunction(), 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(), getParent(), and I.

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::DemoteRegToStack(), FoldBlockIntoPredecessor(), getSinglePredecessor(), llvm::SimplifyCFG(), and llvm::SplitEdge().

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

Definition at line 135 of file BasicBlock.h.

References getSinglePredecessor().

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

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

Definition at line 143 of file BasicBlock.h.

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

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

Definition at line 145 of file BasicBlock.h.

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

Definition at line 147 of file BasicBlock.h.

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

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

Definition at line 148 of file BasicBlock.h.

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

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

Definition at line 150 of file BasicBlock.h.

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

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

Definition at line 152 of file BasicBlock.h.

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

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

Definition at line 158 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 161 of file BasicBlock.h.

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

Reimplemented from llvm::Value.

Definition at line 162 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, end(), and I.

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 178 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(), 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 259 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 199 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 61 of file BasicBlock.h.


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



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.