LLVM
8.0.1
|
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 > |
Static Public Member Functions | |
static BranchProbability | getBranchProbStackProtector (bool IsLikely) |
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.
Definition at line 142 of file BranchProbabilityInfo.h.
using llvm::BranchProbabilityInfo::SccHeaderMaps = std::vector<SccHeaderMap> |
Definition at line 143 of file BranchProbabilityInfo.h.
using llvm::BranchProbabilityInfo::SccMap = DenseMap<const BasicBlock *, int> |
Definition at line 141 of file BranchProbabilityInfo.h.
|
default |
Referenced by BranchProbabilityInfo().
|
inline |
Definition at line 57 of file BranchProbabilityInfo.h.
References calculate().
|
inline |
Definition at line 62 of file BranchProbabilityInfo.h.
References BranchProbabilityInfo(), and operator=().
|
delete |
void BranchProbabilityInfo::calculate | ( | const Function & | F, |
const LoopInfo & | LI, | ||
const TargetLibraryInfo * | TLI = nullptr |
||
) |
Definition at line 932 of file BranchProbabilityInfo.cpp.
References assert(), llvm::dbgs(), llvm::StringRef::equals(), F(), llvm::Function::getEntryBlock(), llvm::Value::getName(), LLVM_DEBUG, llvm::post_order(), print(), PrintBranchProb, PrintBranchProbFuncName, llvm::scc_begin(), and llvm::BranchProbabilityInfo::SccInfo::SccNums.
Referenced by BranchProbabilityInfo(), getBranchProbStackProtector(), llvm::OptimizationRemarkEmitter::OptimizationRemarkEmitter(), and llvm::BranchProbabilityAnalysis::run().
void BranchProbabilityInfo::eraseBlock | ( | const BasicBlock * | BB | ) |
Forget analysis results for the given basic block.
Definition at line 924 of file BranchProbabilityInfo.cpp.
Referenced by getBranchProbStackProtector(), and llvm::SplitIndirectBrCriticalEdges().
|
inlinestatic |
Definition at line 129 of file BranchProbabilityInfo.h.
References calculate(), eraseBlock(), F(), and llvm::BranchProbability::getCompl().
Referenced by CreatePrologue(), and tryToElideArgumentCopy().
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().
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().
BranchProbability BranchProbabilityInfo::getEdgeProbability | ( | const BasicBlock * | Src, |
succ_const_iterator | Dst | ||
) | const |
Definition at line 876 of file BranchProbabilityInfo.cpp.
References getEdgeProbability(), and llvm::SuccIterator< InstructionT, BlockT >::getSuccessorIndex().
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
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=().
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().
|
delete |
Referenced by BranchProbabilityInfo().
|
inline |
Definition at line 70 of file BranchProbabilityInfo.h.
References getEdgeProbability(), getHotSucc(), isEdgeHot(), print(), printEdgeProbability(), releaseMemory(), and setEdgeProbability().
void BranchProbabilityInfo::print | ( | raw_ostream & | OS | ) | const |
Definition at line 819 of file BranchProbabilityInfo.cpp.
References assert(), isEdgeHot(), printEdgeProbability(), SI, llvm::succ_begin(), and llvm::succ_end().
Referenced by calculate(), llvm::BranchProbabilityInfoWrapperPass::getBPI(), operator=(), and llvm::BranchProbabilityPrinterPass::run().
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
Definition at line 913 of file BranchProbabilityInfo.cpp.
References getEdgeProbability(), llvm::Value::getName(), and isEdgeHot().
Referenced by operator=(), and print().
void BranchProbabilityInfo::releaseMemory | ( | ) |
Definition at line 815 of file BranchProbabilityInfo.cpp.
Referenced by llvm::BranchProbabilityInfoWrapperPass::getBPI(), and operator=().
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().