LLVM API Documentation

Public Member Functions | Static Public Attributes
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]

List of all members.

Public Member Functions

 BranchProbabilityInfo ()
void getAnalysisUsage (AnalysisUsage &AU) const override
bool runOnFunction (Function &F) override
void print (raw_ostream &OS, const Module *M=nullptr) const override
BranchProbability getEdgeProbability (const BasicBlock *Src, unsigned IndexInSuccessors) const
 Get an edge's probability, relative to other out-edges of the Src.
BranchProbability getEdgeProbability (const BasicBlock *Src, const BasicBlock *Dst) const
 Get the probability of going from Src to Dst.
bool isEdgeHot (const BasicBlock *Src, const BasicBlock *Dst) const
 Test if an edge is hot relative to other out-edges of the Src.
BasicBlockgetHotSucc (BasicBlock *BB) const
 Retrieve the hot successor of a block if one exists.
raw_ostreamprintEdgeProbability (raw_ostream &OS, const BasicBlock *Src, const BasicBlock *Dst) const
 Print an edge's probability.
uint32_t getEdgeWeight (const BasicBlock *Src, unsigned IndexInSuccessors) const
 Get the raw edge weight calculated for the edge.
uint32_t getEdgeWeight (const BasicBlock *Src, const BasicBlock *Dst) const
 Get the raw edge weight calculated for the block pair.
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.

Static Public Attributes

static char ID = 0

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


Member Function Documentation

void BranchProbabilityInfo::getAnalysisUsage ( AnalysisUsage ) const [override, 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 485 of file BranchProbabilityInfo.cpp.

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

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

References getEdgeWeight(), and N.

Referenced by isEdgeHot(), and printEdgeProbability().

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 644 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 591 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.

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

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

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

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

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

References getEdgeProbability().

Referenced by printEdgeProbability().

void BranchProbabilityInfo::print ( raw_ostream O,
const Module M = nullptr 
) const [override, 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 526 of file BranchProbabilityInfo.cpp.

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

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

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

Referenced by print().

bool BranchProbabilityInfo::runOnFunction ( Function F) [override, virtual]

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

Implements llvm::FunctionPass.

Definition at line 490 of file BranchProbabilityInfo.cpp.

References llvm::SmallPtrSetImplBase::clear(), llvm::dbgs(), DEBUG, llvm::SmallPtrSetImplBase::empty(), F(), llvm::Function::getEntryBlock(), llvm::Value::getName(), 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 624 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: