LLVM  8.0.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
llvm::BranchProbabilityInfo Class Reference

Analysis providing branch probability information. More...

#include "llvm/Analysis/BranchProbabilityInfo.h"

Classes

struct  SccInfo
 

Public Types

using SccMap = DenseMap< const BasicBlock *, int >
 
using SccHeaderMap = DenseMap< const BasicBlock *, bool >
 
using SccHeaderMaps = std::vector< SccHeaderMap >
 

Public Member Functions

 BranchProbabilityInfo ()=default
 
 BranchProbabilityInfo (const Function &F, const LoopInfo &LI, const TargetLibraryInfo *TLI=nullptr)
 
 BranchProbabilityInfo (BranchProbabilityInfo &&Arg)
 
 BranchProbabilityInfo (const BranchProbabilityInfo &)=delete
 
BranchProbabilityInfooperator= (const BranchProbabilityInfo &)=delete
 
BranchProbabilityInfooperator= (BranchProbabilityInfo &&RHS)
 
void releaseMemory ()
 
void print (raw_ostream &OS) 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...
 
BranchProbability getEdgeProbability (const BasicBlock *Src, succ_const_iterator Dst) const
 
bool isEdgeHot (const BasicBlock *Src, const BasicBlock *Dst) const
 Test if an edge is hot relative to other out-edges of the Src. More...
 
const BasicBlockgetHotSucc (const 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...
 
void setEdgeProbability (const BasicBlock *Src, unsigned IndexInSuccessors, BranchProbability Prob)
 Set the raw edge probability for the given edge. More...
 
void calculate (const Function &F, const LoopInfo &LI, const TargetLibraryInfo *TLI=nullptr)
 
void eraseBlock (const BasicBlock *BB)
 Forget analysis results for the given basic block. More...
 

Static Public Member Functions

static BranchProbability getBranchProbStackProtector (bool IsLikely)
 

Detailed Description

Analysis providing branch probability information.

This is a function analysis 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 53 of file BranchProbabilityInfo.h.

Member Typedef Documentation

◆ SccHeaderMap

Definition at line 142 of file BranchProbabilityInfo.h.

◆ SccHeaderMaps

Definition at line 143 of file BranchProbabilityInfo.h.

◆ SccMap

Definition at line 141 of file BranchProbabilityInfo.h.

Constructor & Destructor Documentation

◆ BranchProbabilityInfo() [1/4]

llvm::BranchProbabilityInfo::BranchProbabilityInfo ( )
default

Referenced by BranchProbabilityInfo().

◆ BranchProbabilityInfo() [2/4]

llvm::BranchProbabilityInfo::BranchProbabilityInfo ( const Function F,
const LoopInfo LI,
const TargetLibraryInfo TLI = nullptr 
)
inline

Definition at line 57 of file BranchProbabilityInfo.h.

References calculate().

◆ BranchProbabilityInfo() [3/4]

llvm::BranchProbabilityInfo::BranchProbabilityInfo ( BranchProbabilityInfo &&  Arg)
inline

Definition at line 62 of file BranchProbabilityInfo.h.

References BranchProbabilityInfo(), and operator=().

◆ BranchProbabilityInfo() [4/4]

llvm::BranchProbabilityInfo::BranchProbabilityInfo ( const BranchProbabilityInfo )
delete

Member Function Documentation

◆ calculate()

void BranchProbabilityInfo::calculate ( const Function F,
const LoopInfo LI,
const TargetLibraryInfo TLI = nullptr 
)

◆ eraseBlock()

void BranchProbabilityInfo::eraseBlock ( const BasicBlock BB)

Forget analysis results for the given basic block.

Definition at line 924 of file BranchProbabilityInfo.cpp.

References E, and I.

Referenced by getBranchProbStackProtector(), and llvm::SplitIndirectBrCriticalEdges().

◆ getBranchProbStackProtector()

static BranchProbability llvm::BranchProbabilityInfo::getBranchProbStackProtector ( bool  IsLikely)
inlinestatic

◆ getEdgeProbability() [1/3]

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

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

Get the raw edge probability for the edge.

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.

If can't find it, return a default probability 1/N where N is the number of successors. Here an edge is specified using PredBlock and an index to the successors.

Definition at line 865 of file BranchProbabilityInfo.cpp.

References I, and llvm::succ_size().

Referenced by llvm::CFGMST< Edge, BBInfo >::buildEdges(), llvm::CodeExtractor::extractCodeRegion(), findUnwindDestinations(), getBranchHint(), getEdgeProbability(), getHotSucc(), isEdgeHot(), llvm::SelectionDAGBuilder::isExportableFromCurrentBlock(), operator=(), printEdgeProbability(), scaleCaseProbality(), llvm::SplitIndirectBrCriticalEdges(), tryToElideArgumentCopy(), and llvm::SelectionDAGBuilder::visitBitTestCase().

◆ getEdgeProbability() [2/3]

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

Get the probability of going from Src to Dst.

Get the raw edge probability calculated for the block pair.

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

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

Definition at line 884 of file BranchProbabilityInfo.cpp.

References E, llvm::BranchProbability::getZero(), I, llvm::succ_begin(), and llvm::succ_end().

◆ getEdgeProbability() [3/3]

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

◆ getHotSucc()

const BasicBlock * BranchProbabilityInfo::getHotSucc ( const 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 840 of file BranchProbabilityInfo.cpp.

References E, getEdgeProbability(), llvm::BranchProbability::getZero(), I, llvm::succ_begin(), and llvm::succ_end().

Referenced by operator=().

◆ isEdgeHot()

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

References getEdgeProbability().

Referenced by operator=(), print(), and printEdgeProbability().

◆ operator=() [1/2]

BranchProbabilityInfo& llvm::BranchProbabilityInfo::operator= ( const BranchProbabilityInfo )
delete

Referenced by BranchProbabilityInfo().

◆ operator=() [2/2]

BranchProbabilityInfo& llvm::BranchProbabilityInfo::operator= ( BranchProbabilityInfo &&  RHS)
inline

◆ print()

void BranchProbabilityInfo::print ( raw_ostream OS) const

◆ printEdgeProbability()

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

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

Referenced by operator=(), and print().

◆ releaseMemory()

void BranchProbabilityInfo::releaseMemory ( )

◆ setEdgeProbability()

void BranchProbabilityInfo::setEdgeProbability ( const BasicBlock Src,
unsigned  IndexInSuccessors,
BranchProbability  Prob 
)

Set the raw edge probability for the given edge.

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

This allows a pass to explicitly set the edge probability 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 probabilities are calculated carefully before using!

Definition at line 902 of file BranchProbabilityInfo.cpp.

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

Referenced by computeUnlikelySuccessors(), llvm::CodeExtractor::findInputsOutputs(), operator=(), and llvm::SplitIndirectBrCriticalEdges().


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