LLVM  3.7.0
Public Member Functions | Static 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:
[legend]
Collaboration diagram for llvm::BranchProbabilityInfo:
[legend]

Public Member Functions

 BranchProbabilityInfo ()
 
void getAnalysisUsage (AnalysisUsage &AU) const override
 getAnalysisUsage - This function should be overriden by passes that need analysis information to do their job. More...
 
bool runOnFunction (Function &F) override
 runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass. More...
 
void releaseMemory () override
 releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memory when it is no longer needed. More...
 
void print (raw_ostream &OS, const Module *M=nullptr) const override
 print - Print out the internal state of the pass. More...
 
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...
 
uint32_t getEdgeWeight (const BasicBlock *Src, succ_const_iterator Dst) const
 
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 override
 createPrinterPass - Get a function printer pass. More...
 
void assignPassManager (PMStack &PMS, PassManagerType T) override
 Find appropriate Function Pass Manager or Call Graph Pass Manager in the PM Stack and add self into that manager. More...
 
PassManagerType getPotentialPassManagerType () const override
 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
 getPassName - Return a nice clean name for a pass. More...
 
AnalysisID getPassID () const
 getPassID - Return the PassID number that corresponds to this pass. More...
 
virtual bool doInitialization (Module &)
 doInitialization - Virtual method overridden by subclasses to do any necessary initialization before any pass is run. More...
 
virtual bool doFinalization (Module &)
 doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes have run. More...
 
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 * getAdjustedAnalysisPointer (AnalysisID ID)
 getAdjustedAnalysisPointer - This method is used when a pass implements an analysis interface through multiple inheritance. More...
 
virtual ImmutablePassgetAsImmutablePass ()
 
virtual PMDataManagergetAsPMDataManager ()
 
virtual void verifyAnalysis () const
 verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis information. More...
 
virtual void dumpPassStructure (unsigned Offset=0)
 
template<typename AnalysisType >
AnalysisType * getAnalysisIfAvailable () const
 getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information that might be around, for example to update it. More...
 
bool mustPreserveAnalysisID (char &AID) const
 mustPreserveAnalysisID - This method serves the same function as getAnalysisIfAvailable, but works if you just have an AnalysisID. More...
 
template<typename AnalysisType >
AnalysisType & getAnalysis () const
 getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information that they claim to use by overriding the getAnalysisUsage function. More...
 
template<typename AnalysisType >
AnalysisType & getAnalysis (Function &F)
 getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information that they claim to use by overriding the getAnalysisUsage function. More...
 
template<typename AnalysisType >
AnalysisType & getAnalysisID (AnalysisID PI) const
 
template<typename AnalysisType >
AnalysisType & getAnalysisID (AnalysisID PI, Function &F)
 

Static Public Member Functions

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

Static Public Attributes

static char ID = 0
 

Additional Inherited Members

- Protected Member Functions inherited from llvm::FunctionPass
bool skipOptnoneFunction (const Function &F) const
 skipOptnoneFunction - This function has Attribute::OptimizeNone and most transformation passes should skip it. More...
 

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 40 of file BranchProbabilityInfo.h.

Constructor & Destructor Documentation

llvm::BranchProbabilityInfo::BranchProbabilityInfo ( )
inline

Member Function Documentation

void BranchProbabilityInfo::getAnalysisUsage ( AnalysisUsage ) const
overridevirtual

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 507 of file BranchProbabilityInfo.cpp.

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

static uint32_t llvm::BranchProbabilityInfo::getBranchWeightStackProtector ( bool  IsLikely)
inlinestatic

Definition at line 117 of file BranchProbabilityInfo.h.

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

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

Get the raw edge weight 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.

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 615 of file BranchProbabilityInfo.cpp.

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

Referenced by llvm::FastISel::fastEmitBranch(), getEdgeProbability(), getEdgeWeight(), 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.

This returns the sum of all raw edge weights from Src to Dst.

Definition at line 633 of file BranchProbabilityInfo.cpp.

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

uint32_t BranchProbabilityInfo::getEdgeWeight ( const BasicBlock Src,
succ_const_iterator  Dst 
) const
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 585 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 579 of file BranchProbabilityInfo.cpp.

References getEdgeProbability().

Referenced by printEdgeProbability().

void BranchProbabilityInfo::print ( raw_ostream O,
const Module M = nullptr 
) const
overridevirtual

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 550 of file BranchProbabilityInfo.cpp.

References llvm::Function::begin(), llvm::Function::end(), printEdgeProbability(), llvm::SI, 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 680 of file BranchProbabilityInfo.cpp.

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

Referenced by print().

void BranchProbabilityInfo::releaseMemory ( )
overridevirtual

releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memory when it is no longer needed.

The default behavior of passes is to hold onto memory for the entire duration of their lifetime (which is the entire compile time). For pipelined passes, this is not a big deal because that memory gets recycled every time the pass is invoked on another program unit. For IP passes, it is more important to free memory when it is unused.

Optionally implement this function to release pass memory when it is no longer used.

Reimplemented from llvm::Pass.

Definition at line 546 of file BranchProbabilityInfo.cpp.

References llvm::SmallVectorImpl< T >::clear().

bool BranchProbabilityInfo::runOnFunction ( Function F)
overridevirtual

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

Implements llvm::FunctionPass.

Definition at line 512 of file BranchProbabilityInfo.cpp.

References llvm::dbgs(), DEBUG, F(), llvm::Function::getEntryBlock(), llvm::Value::getName(), and llvm::post_order().

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

Set the raw edge weight for a given edge.

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

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!

Definition at line 651 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 42 of file BranchProbabilityInfo.h.


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