50#define DEBUG_TYPE "branch-prob"
54 cl::desc(
"Print the branch probability info."));
58 cl::desc(
"The option to specify the name of the function "
59 "whose branch probability info is printed."));
62 "Branch Probability Analysis",
false,
true)
164class BPIConstruction {
166 BPIConstruction(BranchProbabilityInfo &BPI) : BPI(BPI) {}
167 void calculate(
const Function &
F,
const CycleInfo &CI,
168 const TargetLibraryInfo *TLI, DominatorTree *DT,
169 PostDominatorTree *PDT);
173 using LoopEdge = std::pair<const BasicBlock *, const BasicBlock *>;
178 bool isLoopEnteringEdge(
const LoopEdge &
Edge)
const;
182 bool isLoopExitingEdge(
const LoopEdge &
Edge)
const;
185 bool isLoopEnteringExitingEdge(
const LoopEdge &
Edge)
const;
188 SmallVectorImpl<const BasicBlock *> &Enters)
const;
192 std::optional<uint32_t> getEstimatedBlockWeight(
const BasicBlock *BB)
const;
197 std::optional<uint32_t> getEstimatedLoopWeight(CycleRef
C)
const;
201 std::optional<uint32_t> getEstimatedEdgeWeight(
const LoopEdge &
Edge)
const;
206 template <
class IterT>
207 std::optional<uint32_t>
208 getMaxEstimatedEdgeWeight(
const BasicBlock *SrcBB,
216 updateEstimatedBlockWeight(
const BasicBlock *BB, uint32_t BBWeight,
217 SmallVectorImpl<const BasicBlock *> &BlockWorkList,
218 SmallVectorImpl<const BasicBlock *> &LoopWorkList);
222 void propagateEstimatedBlockWeight(
223 const BasicBlock *BB, DominatorTree *DT, PostDominatorTree *PDT,
224 uint32_t BBWeight, SmallVectorImpl<const BasicBlock *> &WorkList,
225 SmallVectorImpl<const BasicBlock *> &LoopWorkList);
228 std::optional<uint32_t> getInitialEstimatedBlockWeight(
const BasicBlock *BB);
231 void estimateBlockWeights(
const Function &
F, DominatorTree *DT,
232 PostDominatorTree *PDT);
236 bool calcEstimatedHeuristics(
const BasicBlock *BB);
237 bool calcMetadataWeights(
const BasicBlock *BB);
238 bool calcPointerHeuristics(
const BasicBlock *BB);
239 bool calcZeroHeuristics(
const BasicBlock *BB,
const TargetLibraryInfo *TLI);
240 bool calcFloatingPointHeuristics(
const BasicBlock *BB);
242 BranchProbabilityInfo &BPI;
244 const CycleInfo *CI =
nullptr;
247 SmallDenseMap<const BasicBlock *, uint32_t> EstimatedBlockWeight;
250 SmallDenseMap<CycleRef, uint32_t> EstimatedLoopWeight;
253bool BPIConstruction::isLoopEnteringEdge(
const LoopEdge &Edge)
const {
260 return !CI->
contains(DstCycle, SrcCycle);
263bool BPIConstruction::isLoopExitingEdge(
const LoopEdge &
Edge)
const {
264 return isLoopEnteringEdge({
Edge.second,
Edge.first});
267bool BPIConstruction::isLoopEnteringExitingEdge(
const LoopEdge &
Edge)
const {
268 return isLoopEnteringEdge(
Edge) || isLoopExitingEdge(
Edge);
271void BPIConstruction::getLoopEnterBlocks(
272 const BasicBlock *BB, SmallVectorImpl<const BasicBlock *> &Enters)
const {
284bool BPIConstruction::calcMetadataWeights(
const BasicBlock *BB) {
301 uint64_t WeightSum = 0;
303 SmallVector<unsigned, 2> UnreachableIdxs;
304 SmallVector<unsigned, 2> ReachableIdxs;
308 for (
unsigned I = 0,
E = Weights.
size();
I !=
E; ++
I) {
309 WeightSum += Weights[
I];
310 auto EstimatedWeight = getEstimatedEdgeWeight({BB, *Succs++});
311 if (EstimatedWeight &&
321 uint64_t ScalingFactor =
322 (WeightSum > UINT32_MAX) ? WeightSum / UINT32_MAX + 1 : 1;
324 if (ScalingFactor > 1) {
327 Weights[
I] /= ScalingFactor;
328 WeightSum += Weights[
I];
331 assert(WeightSum <= UINT32_MAX &&
332 "Expected weights to scale down to 32 bits");
334 if (WeightSum == 0 || ReachableIdxs.
size() == 0) {
343 BP.
push_back({ Weights[
I],
static_cast<uint32_t
>(WeightSum) });
347 if (UnreachableIdxs.
size() == 0 || ReachableIdxs.
size() == 0) {
353 for (
auto I : UnreachableIdxs)
354 if (UnreachableProb < BP[
I]) {
355 BP[
I] = UnreachableProb;
379 for (
auto I : UnreachableIdxs)
380 NewUnreachableSum += BP[
I];
382 BranchProbability NewReachableSum =
386 for (
auto I : ReachableIdxs)
387 OldReachableSum += BP[
I];
389 if (OldReachableSum != NewReachableSum) {
390 if (OldReachableSum.
isZero()) {
394 BranchProbability PerEdge = NewReachableSum / ReachableIdxs.size();
395 for (
auto I : ReachableIdxs)
398 for (
auto I : ReachableIdxs) {
404 BP[
I].getNumerator();
405 uint32_t Div =
static_cast<uint32_t
>(
419bool BPIConstruction::calcPointerHeuristics(
const BasicBlock *BB) {
437 case ICmpInst::ICMP_NE:
440 case ICmpInst::ICMP_EQ:
452computeUnlikelySuccessors(
const BasicBlock *BB,
const CycleInfo &CI, CycleRef
C,
453 SmallPtrSetImpl<const BasicBlock *> &UnlikelyBlocks) {
507 SmallPtrSet<PHINode*, 8> VisitedInsts;
510 VisitedInsts.
insert(CmpPHI);
511 while (!WorkList.
empty()) {
513 for (BasicBlock *
B :
P->blocks()) {
517 Value *
V =
P->getIncomingValueForBlock(
B);
521 if (VisitedInsts.
insert(PN).second)
543 Cmp->getPredicate(), CmpLHSConst, CmpConst,
DL);
553std::optional<uint32_t>
554BPIConstruction::getEstimatedBlockWeight(
const BasicBlock *BB)
const {
555 auto WeightIt = EstimatedBlockWeight.find(BB);
556 if (WeightIt == EstimatedBlockWeight.end())
558 return WeightIt->second;
561std::optional<uint32_t>
562BPIConstruction::getEstimatedLoopWeight(CycleRef
C)
const {
563 auto WeightIt = EstimatedLoopWeight.find(
C);
564 if (WeightIt == EstimatedLoopWeight.end())
566 return WeightIt->second;
569std::optional<uint32_t>
570BPIConstruction::getEstimatedEdgeWeight(
const LoopEdge &
Edge)
const {
573 return isLoopEnteringEdge(
Edge)
575 : getEstimatedBlockWeight(
Edge.second);
578template <
class IterT>
579std::optional<uint32_t> BPIConstruction::getMaxEstimatedEdgeWeight(
581 std::optional<uint32_t> MaxWeight;
582 for (
const BasicBlock *DstBB : Successors) {
583 auto Weight = getEstimatedEdgeWeight({SrcBB, DstBB});
586 if (!MaxWeight || *MaxWeight < *Weight)
598bool BPIConstruction::updateEstimatedBlockWeight(
599 const BasicBlock *BB, uint32_t BBWeight,
600 SmallVectorImpl<const BasicBlock *> &BlockWorkList,
601 SmallVectorImpl<const BasicBlock *> &LoopWorkList) {
607 if (!EstimatedBlockWeight.insert({BB, BBWeight}).second)
612 if (isLoopExitingEdge({PredBlock, BB})) {
613 if (!EstimatedLoopWeight.count(CI->
getCycle(PredBlock)))
615 }
else if (!EstimatedBlockWeight.count(PredBlock))
633void BPIConstruction::propagateEstimatedBlockWeight(
634 const BasicBlock *BB, DominatorTree *DT, PostDominatorTree *PDT,
635 uint32_t BBWeight, SmallVectorImpl<const BasicBlock *> &BlockWorkList,
636 SmallVectorImpl<const BasicBlock *> &LoopWorkList) {
637 const auto *DTStartNode = DT->
getNode(BB);
638 const auto *PDTStartNode = PDT->
getNode(BB);
641 for (
const auto *DTNode = DTStartNode; DTNode !=
nullptr;
642 DTNode = DTNode->getIDom()) {
643 auto *DomBB = DTNode->getBlock();
650 const LoopEdge
Edge{DomBB, BB};
652 if (!isLoopEnteringExitingEdge(
Edge)) {
653 if (!updateEstimatedBlockWeight(DomBB, BBWeight, BlockWorkList,
658 }
else if (isLoopExitingEdge(
Edge)) {
664std::optional<uint32_t>
665BPIConstruction::getInitialEstimatedBlockWeight(
const BasicBlock *BB) {
667 auto hasNoReturn = [&](
const BasicBlock *BB) {
670 if (CI->hasFnAttr(Attribute::NoReturn))
685 return hasNoReturn(BB)
694 for (
const auto &
I : *BB)
696 if (CI->hasFnAttr(Attribute::Cold))
705void BPIConstruction::estimateBlockWeights(
const Function &
F, DominatorTree *DT,
706 PostDominatorTree *PDT) {
707 SmallVector<const BasicBlock *, 8> BlockWorkList;
708 SmallVector<const BasicBlock *, 8> LoopWorkList;
709 SmallDenseMap<CycleRef, SmallVector<BasicBlock *, 4>> LoopExitBlocks;
713 ReversePostOrderTraversal<const Function *> RPOT(&
F);
714 for (
const auto *BB : RPOT)
715 if (
auto BBWeight = getInitialEstimatedBlockWeight(BB))
718 propagateEstimatedBlockWeight(BB, DT, PDT, *BBWeight, BlockWorkList,
726 while (!LoopWorkList.
empty()) {
729 if (EstimatedLoopWeight.count(
C))
733 SmallVectorImpl<BasicBlock *> &Exits = Res.first->second;
736 auto LoopWeight = getMaxEstimatedEdgeWeight(
744 EstimatedLoopWeight.insert({
C, *LoopWeight});
746 getLoopEnterBlocks(LoopBB, BlockWorkList);
750 while (!BlockWorkList.
empty()) {
753 if (EstimatedBlockWeight.count(BB))
762 auto MaxWeight = getMaxEstimatedEdgeWeight(BB,
successors(BB));
765 propagateEstimatedBlockWeight(BB, DT, PDT, *MaxWeight, BlockWorkList,
768 }
while (!BlockWorkList.
empty() || !LoopWorkList.
empty());
774bool BPIConstruction::calcEstimatedHeuristics(
const BasicBlock *BB) {
776 "expected more than one successor!");
778 CycleRef BBCycle = CI->
getCycle(BB);
780 SmallPtrSet<const BasicBlock *, 8> UnlikelyBlocks;
783 computeUnlikelySuccessors(BB, *CI, BBCycle, UnlikelyBlocks);
786 bool FoundEstimatedWeight =
false;
787 SmallVector<uint32_t, 4> SuccWeights;
788 uint64_t TotalWeight = 0;
790 for (
const BasicBlock *SuccBB :
successors(BB)) {
791 std::optional<uint32_t> Weight;
792 const LoopEdge
Edge{BB, SuccBB};
794 Weight = getEstimatedEdgeWeight(
Edge);
796 if (isLoopExitingEdge(
Edge) &&
805 bool IsUnlikelyEdge = BBCycle && UnlikelyBlocks.
contains(SuccBB);
806 if (IsUnlikelyEdge &&
816 FoundEstimatedWeight =
true;
820 TotalWeight += WeightVal;
827 if (!FoundEstimatedWeight || TotalWeight == 0)
831 const unsigned SuccCount = SuccWeights.
size();
835 if (TotalWeight > UINT32_MAX) {
836 uint64_t ScalingFactor = TotalWeight / UINT32_MAX + 1;
838 for (
unsigned Idx = 0; Idx < SuccCount; ++Idx) {
839 SuccWeights[Idx] /= ScalingFactor;
843 TotalWeight += SuccWeights[Idx];
845 assert(TotalWeight <= UINT32_MAX &&
"Total weight overflows");
852 for (
unsigned Idx = 0; Idx < SuccCount; ++Idx) {
853 EdgeProbabilities[Idx] =
854 BranchProbability(SuccWeights[Idx], (uint32_t)TotalWeight);
860bool BPIConstruction::calcZeroHeuristics(
const BasicBlock *BB,
861 const TargetLibraryInfo *TLI) {
871 auto GetConstantInt = [](
Value *
V) {
878 ConstantInt *CV = GetConstantInt(
RHS);
885 if (
LHS->getOpcode() == Instruction::And)
886 if (ConstantInt *AndRHS = GetConstantInt(
LHS->getOperand(1)))
887 if (AndRHS->getValue().isPowerOf2())
891 LibFunc
Func = LibFunc::NotLibFunc;
898 if (Func == LibFunc_strcasecmp ||
899 Func == LibFunc_strcmp ||
900 Func == LibFunc_strncasecmp ||
901 Func == LibFunc_strncmp ||
902 Func == LibFunc_memcmp ||
903 Func == LibFunc_bcmp) {
915 default:
return false;
918 }
else if (CV->
isZero()) {
925 default:
return false;
928 }
else if (CV->
isOne()) {
932 default:
return false;
942 default:
return false;
956bool BPIConstruction::calcFloatingPointHeuristics(
const BasicBlock *BB) {
971 }
else if (FCmp->
getPredicate() == FCmpInst::FCMP_ORD) {
974 }
else if (FCmp->
getPredicate() == FCmpInst::FCMP_UNO) {
982void BPIConstruction::calculate(
const Function &
F,
const CycleInfo &CycleI,
983 const TargetLibraryInfo *TLI, DominatorTree *DT,
984 PostDominatorTree *PDT) {
987 std::unique_ptr<DominatorTree> DTPtr;
988 std::unique_ptr<PostDominatorTree> PDTPtr;
991 DTPtr = std::make_unique<DominatorTree>(
const_cast<Function &
>(
F));
996 PDTPtr = std::make_unique<PostDominatorTree>(
const_cast<Function &
>(
F));
1000 estimateBlockWeights(
F, DT, PDT);
1004 for (
const auto *BB :
post_order(&
F.getEntryBlock())) {
1010 if (calcMetadataWeights(BB))
1012 if (calcEstimatedHeuristics(BB))
1014 if (calcPointerHeuristics(BB))
1016 if (calcZeroHeuristics(BB, TLI))
1018 if (calcFloatingPointHeuristics(BB))
1026BranchProbabilityInfo::allocEdges(
const BasicBlock *BB) {
1028 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1030 if (NumSuccs == 0) {
1034 if (EdgeStarts.size() <= BB->
getNumber())
1035 EdgeStarts.resize(LastF->getMaxBlockNumber(), 0);
1036 unsigned EdgeStart = Probs.size();
1037 EdgeStarts[BB->
getNumber()] = EdgeStart + 1;
1038 Probs.append(NumSuccs, {});
1043BranchProbabilityInfo::getEdges(
const BasicBlock *BB)
const {
1045 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1046 if (EdgeStarts.size() <= BB->
getNumber())
1048 if (
unsigned EdgeStart = EdgeStarts[BB->
getNumber()]) {
1049 const BranchProbability *
Start = &Probs[EdgeStart - 1];
1050 size_t Count = SIZE_MAX;
1060 FunctionAnalysisManager::Invalidator &) {
1069 OS <<
"---- Branch Probabilities ----\n";
1072 assert(LastF &&
"Cannot print prior to running over a function");
1073 for (
const auto &BI : *LastF) {
1092 unsigned IndexInSuccessors)
const {
1094 return P[IndexInSuccessors];
1109 if (It.value() == Dst)
1110 Prob +=
P[It.index()];
1118 assert(Src->getTerminator()->getNumSuccessors() == Probs.size());
1121 for (
unsigned SuccIdx = 0; SuccIdx < Probs.size(); ++SuccIdx) {
1122 P[SuccIdx] = Probs[SuccIdx];
1123 LLVM_DEBUG(
dbgs() <<
"set edge " << Src->getName() <<
" -> " << SuccIdx
1124 <<
" successor probability to " << Probs[SuccIdx]
1126 TotalNumerator += Probs[SuccIdx].getNumerator();
1138 (void)TotalNumerator;
1152 for (
unsigned i = 0; i != DstP.
size(); ++i) {
1154 LLVM_DEBUG(
dbgs() <<
"set edge " << Dst->getName() <<
" -> " << i
1155 <<
" successor probability to " << SrcP[i] <<
"\n");
1160 assert(Src->getTerminator()->getNumSuccessors() == 2);
1175 Src->printAsOperand(OS,
false, Src->getModule());
1177 Dst->printAsOperand(OS,
false, Dst->getModule());
1178 OS <<
" probability is " << Prob
1179 << (
isEdgeHot(Src, Dst) ?
" [HOT edge]\n" :
"\n");
1187 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1188 if (EdgeStarts.size() > BB->
getNumber())
1200 BlockNumberEpoch =
F.getBlockNumberEpoch();
1203 BPIConstruction(*this).calculate(
F, CycleI, TLI, DT, PDT);
1231 BPI.calculate(
F, CI, &TLI, &DT, &PDT);
1254 OS <<
"Printing analysis 'Branch Probability Analysis' for function '"
1255 <<
F.getName() <<
"':\n";
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
This file contains the simple types necessary to represent the attributes associated with functions a...
BlockExecWeight
Set of dedicated "absolute" execution weights for a block.
@ NORETURN
Weight to a block containing non returning call.
@ UNWIND
Weight to 'unwind' block of an invoke instruction.
@ COLD
Weight to a 'cold' block.
@ ZERO
Special weight used for cases with exact zero probability.
@ UNREACHABLE
Weight to an 'unreachable' block.
@ DEFAULT
Default weight is used in cases when there is no dedicated execution weight set.
@ LOWEST_NON_ZERO
Minimal possible non zero weight.
static constexpr BranchProbability FPTakenProb(FPH_TAKEN_WEIGHT, FPH_TAKEN_WEIGHT+FPH_NONTAKEN_WEIGHT)
static const uint32_t FPH_TAKEN_WEIGHT
static const uint32_t LBH_TAKEN_WEIGHT
static const uint32_t ZH_NONTAKEN_WEIGHT
static const uint32_t PH_NONTAKEN_WEIGHT
static constexpr BranchProbability UR_TAKEN_PROB
Unreachable-terminating branch taken probability.
static const uint32_t PH_TAKEN_WEIGHT
Heuristics and lookup tables for non-loop branches: Pointer Heuristics (PH)
static constexpr BranchProbability FPUntakenProb(FPH_NONTAKEN_WEIGHT, FPH_TAKEN_WEIGHT+FPH_NONTAKEN_WEIGHT)
static constexpr BranchProbability PtrTakenProb(PH_TAKEN_WEIGHT, PH_TAKEN_WEIGHT+PH_NONTAKEN_WEIGHT)
static constexpr BranchProbability PtrUntakenProb(PH_NONTAKEN_WEIGHT, PH_TAKEN_WEIGHT+PH_NONTAKEN_WEIGHT)
static const uint32_t ZH_TAKEN_WEIGHT
Zero Heuristics (ZH)
static const uint32_t FPH_NONTAKEN_WEIGHT
static constexpr BranchProbability ZeroTakenProb(ZH_TAKEN_WEIGHT, ZH_TAKEN_WEIGHT+ZH_NONTAKEN_WEIGHT)
static const uint32_t LBH_NONTAKEN_WEIGHT
static constexpr BranchProbability ZeroUntakenProb(ZH_NONTAKEN_WEIGHT, ZH_TAKEN_WEIGHT+ZH_NONTAKEN_WEIGHT)
static const uint32_t FPH_ORD_WEIGHT
This is the probability for an ordered floating point comparison.
static const uint32_t FPH_UNO_WEIGHT
This is the probability for an unordered floating point comparison, it means one or two of the operan...
static cl::opt< std::string > PrintBranchProbFuncName("print-bpi-func-name", cl::Hidden, cl::desc("The option to specify the name of the function " "whose branch probability info is printed."))
static constexpr BranchProbability FPOrdTakenProb(FPH_ORD_WEIGHT, FPH_ORD_WEIGHT+FPH_UNO_WEIGHT)
static cl::opt< bool > PrintBranchProb("print-bpi", cl::init(false), cl::Hidden, cl::desc("Print the branch probability info."))
static constexpr BranchProbability FPOrdUntakenProb(FPH_UNO_WEIGHT, FPH_ORD_WEIGHT+FPH_UNO_WEIGHT)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file declares an analysis pass that computes CycleInfo for LLVM IR, specialized from GenericCycl...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
std::pair< BasicBlock *, BasicBlock * > Edge
This file defines the SmallVector class.
This templated class represents "all analyses that operate over <aparticular IR unit>" (e....
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
LLVM Basic Block Representation.
unsigned getNumber() const
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
bool isEHPad() const
Return true if this basic block is an exception handling block.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Analysis pass which computes BranchProbabilityInfo.
LLVM_ABI BranchProbabilityInfo run(Function &F, FunctionAnalysisManager &AM)
Run the analysis pass over a function and produce BPI.
Legacy analysis pass which computes BranchProbabilityInfo.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
BranchProbabilityInfoWrapperPass()
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void print(raw_ostream &OS, const Module *M=nullptr) const override
print - Print out the internal state of the pass.
Analysis providing branch probability information.
LLVM_ABI void eraseBlock(const BasicBlock *BB)
Forget analysis results for the given basic block.
LLVM_ABI void calculate(const Function &F, const CycleInfo &CI, const TargetLibraryInfo *TLI, DominatorTree *DT, PostDominatorTree *PDT)
LLVM_ABI bool invalidate(Function &, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &)
LLVM_ABI BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
LLVM_ABI void setEdgeProbability(const BasicBlock *Src, ArrayRef< BranchProbability > Probs)
Set the raw probabilities for all edges from the given block.
LLVM_ABI bool isEdgeHot(const BasicBlock *Src, const BasicBlock *Dst) const
Test if an edge is hot relative to other out-edges of the Src.
LLVM_ABI void swapSuccEdgesProbabilities(const BasicBlock *Src)
Swap outgoing edges probabilities for Src with branch terminator.
LLVM_ABI void print(raw_ostream &OS) const
LLVM_ABI raw_ostream & printEdgeProbability(raw_ostream &OS, const BasicBlock *Src, const BasicBlock *Dst) const
Print an edge's probability.
LLVM_ABI void copyEdgeProbabilities(BasicBlock *Src, BasicBlock *Dst)
Copy outgoing edge probabilities from Src to Dst.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
static constexpr BranchProbability getOne()
static uint32_t getDenominator()
static constexpr BranchProbability getUnknown()
static constexpr BranchProbability getZero()
uint32_t getNumerator() const
static constexpr BranchProbability getRaw(uint32_t N)
Represents analyses that only rely on functions' control flow.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
@ ICMP_SLT
signed less than
@ ICMP_SGT
signed greater than
bool isTrueWhenEqual() const
This is just a convenience.
Predicate getPredicate() const
Return the predicate for this instruction.
Value * getCondition() const
BasicBlock * getSuccessor(unsigned i) const
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Analysis pass which computes a CycleInfo.
Legacy analysis pass which computes a CycleInfo.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Analysis pass which computes a DominatorTree.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
Legacy analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
static bool isEquality(Predicate Pred)
ArrayRef< BlockT * > getEntries(CycleRef C) const
bool contains(CycleRef Outer, CycleRef Inner) const
Returns true iff Outer contains Inner. O(1). Non-strict.
void getExitBlocks(CycleRef C, SmallVectorImpl< BlockT * > &TmpStorage) const
Return all of the successor blocks of C: the blocks outside of C which are branched to from within it...
CycleRef getCycle(const BlockT *Block) const
Find the innermost cycle containing Block.
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
A Module instance is used to store all the information related to an LLVM module.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
Analysis pass which computes a PostDominatorTree.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
LLVM_ABI bool dominates(const Instruction *I1, const Instruction *I2) const
Return true if I1 dominates I2.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
void push_back(const T &Elt)
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
bool isPointerTy() const
True if this is an instance of PointerType.
Value * getOperand(unsigned i) const
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
const ParentTy * getParent() const
This class implements an extremely fast bulk output stream that can only output to a stream.
@ C
The default llvm calling convention, compatible with C.
@ BasicBlock
Various leaf nodes.
initializer< Ty > init(const Ty &Val)
NodeAddr< FuncNode * > Func
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto successors(const MachineBasicBlock *BB)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const Instruction *I=nullptr)
Attempt to constant fold a compare instruction (icmp/fcmp) with the specified operands.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
constexpr T divideNearest(U Numerator, V Denominator)
Returns (Numerator / Denominator) rounded by round-half-up.
auto reverse(ContainerTy &&C)
LLVM_ABI MDNode * getValidBranchWeightMDNode(const Instruction &I)
Get the valid branch weights metadata node.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
auto succ_size(const MachineBasicBlock *BB)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
auto post_order(const T &G)
Post-order traversal of a graph.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI Constant * ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, Constant *RHS, const DataLayout &DL)
Attempt to constant fold a binary operation with the specified operands.
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A special type used by analysis passes to provide an address that identifies that particular analysis...