LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Attributes | List of all members
llvm::BranchProbabilityInfo Class Reference

Analysis pass providing branch probability information. More...

#include <BranchProbabilityInfo.h>

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

Public Member Functions

 BranchProbabilityInfo ()
 
void getAnalysisUsage (AnalysisUsage &AU) const
 
bool runOnFunction (Function &F)
 
void print (raw_ostream &OS, const Module *M=0) const
 
BranchProbability getEdgeProbability (const BasicBlock *Src, unsigned IndexInSuccessors) const
 Get an edge's probability, relative to other out-edges of the Src. More...
 
BranchProbability getEdgeProbability (const BasicBlock *Src, const BasicBlock *Dst) const
 Get the probability of going from Src to Dst. More...
 
bool isEdgeHot (const BasicBlock *Src, const BasicBlock *Dst) const
 Test if an edge is hot relative to other out-edges of the Src. More...
 
BasicBlockgetHotSucc (BasicBlock *BB) const
 Retrieve the hot successor of a block if one exists. More...
 
raw_ostreamprintEdgeProbability (raw_ostream &OS, const BasicBlock *Src, const BasicBlock *Dst) const
 Print an edge's probability. More...
 
uint32_t getEdgeWeight (const BasicBlock *Src, unsigned IndexInSuccessors) const
 Get the raw edge weight calculated for the edge. More...
 
uint32_t getEdgeWeight (const BasicBlock *Src, const BasicBlock *Dst) const
 Get the raw edge weight calculated for the block pair. More...
 
void setEdgeWeight (const BasicBlock *Src, unsigned IndexInSuccessors, uint32_t Weight)
 Set the raw edge weight for a given edge. More...
 
- Public Member Functions inherited from llvm::FunctionPass
 FunctionPass (char &pid)
 
PasscreatePrinterPass (raw_ostream &O, const std::string &Banner) const
 createPrinterPass - Get a function printer pass. More...
 
virtual void assignPassManager (PMStack &PMS, PassManagerType T)
 
virtual PassManagerType getPotentialPassManagerType () const
 Return what kind of Pass Manager can manage this pass. More...
 
- Public Member Functions inherited from llvm::Pass
 Pass (PassKind K, char &pid)
 
virtual ~Pass ()
 
PassKind getPassKind () const
 
virtual const char * getPassName () const
 
AnalysisID getPassID () const
 getPassID - Return the PassID number that corresponds to this pass. More...
 
virtual bool doInitialization (Module &)
 
virtual bool doFinalization (Module &)
 
void dump () const
 
virtual void preparePassManager (PMStack &)
 Check if available pass managers are suitable for this pass or not. More...
 
void setResolver (AnalysisResolver *AR)
 
AnalysisResolvergetResolver () const
 
virtual void releaseMemory ()
 
virtual void * getAdjustedAnalysisPointer (AnalysisID ID)
 
virtual ImmutablePassgetAsImmutablePass ()
 
virtual PMDataManagergetAsPMDataManager ()
 
virtual void verifyAnalysis () const
 
virtual void dumpPassStructure (unsigned Offset=0)
 
template<typename AnalysisType >
AnalysisType * getAnalysisIfAvailable () const
 
bool mustPreserveAnalysisID (char &AID) const
 
template<typename AnalysisType >
AnalysisType & getAnalysis () const
 
template<typename AnalysisType >
AnalysisType & getAnalysis (Function &F)
 
template<typename AnalysisType >
AnalysisType & getAnalysisID (AnalysisID PI) const
 
template<typename AnalysisType >
AnalysisType & getAnalysisID (AnalysisID PI, Function &F)
 

Static Public Attributes

static char ID = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from llvm::Pass
static const PassInfolookupPassInfo (const void *TI)
 
static const PassInfolookupPassInfo (StringRef Arg)
 
static PasscreatePass (AnalysisID ID)
 

Detailed Description

Analysis pass providing branch probability information.

This is a function analysis pass which provides information on the relative probabilities of each "edge" in the function's CFG where such an edge is defined by a pair (PredBlock and an index in the successors). The probability of an edge from one block is always relative to the probabilities of other edges from the block. The probabilites of all edges from a block sum to exactly one (100%). We use a pair (PredBlock and an index in the successors) to uniquely identify an edge, since we can have multiple edges from Src to Dst. As an example, we can have a switch which jumps to Dst with value 0 and value 10.

Definition at line 39 of file BranchProbabilityInfo.h.

Constructor & Destructor Documentation

llvm::BranchProbabilityInfo::BranchProbabilityInfo ( )
inline

Member Function Documentation

void BranchProbabilityInfo::getAnalysisUsage ( AnalysisUsage ) const
virtual

getAnalysisUsage - This function should be overriden by passes that need analysis information to do their job. If a pass specifies that it uses a particular analysis result to this function, it can then use the getAnalysis<AnalysisType>() function, below.

Reimplemented from llvm::Pass.

Definition at line 480 of file BranchProbabilityInfo.cpp.

References llvm::AnalysisUsage::addRequired(), and llvm::AnalysisUsage::setPreservesAll().

BranchProbability BranchProbabilityInfo::getEdgeProbability ( const BasicBlock Src,
unsigned  IndexInSuccessors 
) const

Get an edge's probability, relative to other out-edges of the Src.

Get an edge's probability, relative to other out-edges from Src.

This routine provides access to the fractional probability between zero (0%) and one (100%) of this edge executing, relative to other edges leaving the 'Src' block. The returned probability is never zero, and can only be one if the source block has only one successor.

Definition at line 622 of file BranchProbabilityInfo.cpp.

References getEdgeWeight(), and N.

Referenced by isEdgeHot(), and printEdgeProbability().

BranchProbability BranchProbabilityInfo::getEdgeProbability ( const BasicBlock Src,
const BasicBlock Dst 
) const

Get the probability of going from Src to Dst.

It returns the sum of all probabilities for edges from Src to Dst.

Get the probability of going from Src to Dst. It returns the sum of all probabilities for edges from Src to Dst.

Definition at line 632 of file BranchProbabilityInfo.cpp.

References getEdgeWeight(), and N.

uint32_t BranchProbabilityInfo::getEdgeWeight ( const BasicBlock Src,
unsigned  IndexInSuccessors 
) const

Get the raw edge weight calculated for the edge.

This returns the raw edge weight. It is guaranteed to fall between 1 and UINT32_MAX. Note that the raw edge weight is not meaningful in isolation. This interface should be very carefully, and primarily by routines that are updating the analysis by later calling setEdgeWeight.

Get the raw edge weight for the edge. If can't find it, return DEFAULT_WEIGHT value. Here an edge is specified using PredBlock and an index to the successors.

Definition at line 584 of file BranchProbabilityInfo.cpp.

References llvm::SmallVectorTemplateCommon< T >::end(), and I.

Referenced by getEdgeProbability(), and getHotSucc().

uint32_t BranchProbabilityInfo::getEdgeWeight ( const BasicBlock Src,
const BasicBlock Dst 
) const

Get the raw edge weight calculated for the block pair.

This returns the sum of all raw edge weights from Src to Dst. It is guaranteed to fall between 1 and UINT32_MAX.

Get the raw edge weight calculated for the block pair. This returns the sum of all raw edge weights from Src to Dst.

Definition at line 597 of file BranchProbabilityInfo.cpp.

References llvm::SmallVectorTemplateCommon< T >::end(), I, llvm::succ_begin(), and llvm::succ_end().

BasicBlock * BranchProbabilityInfo::getHotSucc ( BasicBlock BB) const

Retrieve the hot successor of a block if one exists.

Given a basic block, look through its successors and if one exists for which

See Also
isEdgeHot would return true, return that successor block.

Definition at line 554 of file BranchProbabilityInfo.cpp.

References getEdgeWeight(), I, llvm::succ_begin(), and llvm::succ_end().

bool BranchProbabilityInfo::isEdgeHot ( const BasicBlock Src,
const BasicBlock Dst 
) const

Test if an edge is hot relative to other out-edges of the Src.

Check whether this edge out of the source block is 'hot'. We define hot as having a relative probability >= 80%.

Definition at line 548 of file BranchProbabilityInfo.cpp.

References getEdgeProbability().

Referenced by printEdgeProbability().

void BranchProbabilityInfo::print ( raw_ostream O,
const Module M = 0 
) const
virtual

print - Print out the internal state of the pass. This is called by Analyze to print out the contents of an analysis. Otherwise it is not necessary to implement this method. Beware that the module pointer MAY be null. This automatically forwards to a virtual function that does not provide the Module* in case the analysis doesn't need it it can just be ignored.

Reimplemented from llvm::Pass.

Definition at line 519 of file BranchProbabilityInfo.cpp.

References llvm::Function::begin(), llvm::Function::end(), printEdgeProbability(), llvm::succ_begin(), and llvm::succ_end().

raw_ostream & BranchProbabilityInfo::printEdgeProbability ( raw_ostream OS,
const BasicBlock Src,
const BasicBlock Dst 
) const

Print an edge's probability.

Retrieves an edge's probability similarly to

See Also
getEdgeProbability, but then prints that probability to the provided stream. That stream is then returned.

Definition at line 641 of file BranchProbabilityInfo.cpp.

References getEdgeProbability(), llvm::Value::getName(), and isEdgeHot().

Referenced by print().

bool BranchProbabilityInfo::runOnFunction ( Function F)
virtual

runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.

Implements llvm::FunctionPass.

Definition at line 485 of file BranchProbabilityInfo.cpp.

References llvm::dbgs(), DEBUG, F(), llvm::Function::getEntryBlock(), I, llvm::po_begin(), and llvm::po_end().

void BranchProbabilityInfo::setEdgeWeight ( const BasicBlock Src,
unsigned  IndexInSuccessors,
uint32_t  Weight 
)

Set the raw edge weight for a given edge.

This allows a pass to explicitly set the edge weight for an edge. It can be used when updating the CFG to update and preserve the branch probability information. Read the implementation of how these edge weights are calculated carefully before using!

Set the edge weight for a given edge specified by PredBlock and an index to the successors.

Definition at line 612 of file BranchProbabilityInfo.cpp.

References llvm::dbgs(), DEBUG, and llvm::Value::getName().

Member Data Documentation

branch Branch Probability true char BranchProbabilityInfo::ID = 0
static

Definition at line 41 of file BranchProbabilityInfo.h.


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