49#define DEBUG_TYPE "branch-prob"
53 cl::desc(
"Print the branch probability info."));
57 cl::desc(
"The option to specify the name of the function "
58 "whose branch probability info is printed."));
61 "Branch Probability Analysis",
false,
true)
163class BPIConstruction {
165 BPIConstruction(BranchProbabilityInfo &BPI) : BPI(BPI) {}
166 void calculate(
const Function &
F,
const CycleInfo &CI,
167 const TargetLibraryInfo *TLI, DominatorTree *DT,
168 PostDominatorTree *PDT);
172 using LoopEdge = std::pair<const BasicBlock *, const BasicBlock *>;
177 bool isLoopEnteringEdge(
const LoopEdge &
Edge)
const;
181 bool isLoopExitingEdge(
const LoopEdge &
Edge)
const;
184 bool isLoopEnteringExitingEdge(
const LoopEdge &
Edge)
const;
187 SmallVectorImpl<const BasicBlock *> &Enters)
const;
191 std::optional<uint32_t> getEstimatedBlockWeight(
const BasicBlock *BB)
const;
196 std::optional<uint32_t> getEstimatedLoopWeight(CycleRef
C)
const;
200 std::optional<uint32_t> getEstimatedEdgeWeight(
const LoopEdge &
Edge)
const;
205 template <
class IterT>
206 std::optional<uint32_t>
207 getMaxEstimatedEdgeWeight(
const BasicBlock *SrcBB,
215 updateEstimatedBlockWeight(
const BasicBlock *BB, uint32_t BBWeight,
216 SmallVectorImpl<const BasicBlock *> &BlockWorkList,
217 SmallVectorImpl<const BasicBlock *> &LoopWorkList);
221 void propagateEstimatedBlockWeight(
222 const BasicBlock *BB, DominatorTree *DT, PostDominatorTree *PDT,
223 uint32_t BBWeight, SmallVectorImpl<const BasicBlock *> &WorkList,
224 SmallVectorImpl<const BasicBlock *> &LoopWorkList);
227 std::optional<uint32_t> getInitialEstimatedBlockWeight(
const BasicBlock *BB);
230 void estimateBlockWeights(
const Function &
F, DominatorTree *DT,
231 PostDominatorTree *PDT);
235 bool calcEstimatedHeuristics(
const BasicBlock *BB);
236 bool calcMetadataWeights(
const BasicBlock *BB);
237 bool calcPointerHeuristics(
const BasicBlock *BB);
238 bool calcZeroHeuristics(
const BasicBlock *BB,
const TargetLibraryInfo *TLI);
239 bool calcFloatingPointHeuristics(
const BasicBlock *BB);
241 BranchProbabilityInfo &BPI;
243 const CycleInfo *CI =
nullptr;
246 SmallDenseMap<const BasicBlock *, uint32_t> EstimatedBlockWeight;
249 SmallDenseMap<CycleRef, uint32_t> EstimatedLoopWeight;
252bool BPIConstruction::isLoopEnteringEdge(
const LoopEdge &Edge)
const {
259 return !CI->
contains(DstCycle, SrcCycle);
262bool BPIConstruction::isLoopExitingEdge(
const LoopEdge &
Edge)
const {
263 return isLoopEnteringEdge({
Edge.second,
Edge.first});
266bool BPIConstruction::isLoopEnteringExitingEdge(
const LoopEdge &
Edge)
const {
267 return isLoopEnteringEdge(
Edge) || isLoopExitingEdge(
Edge);
270void BPIConstruction::getLoopEnterBlocks(
271 const BasicBlock *BB, SmallVectorImpl<const BasicBlock *> &Enters)
const {
283bool BPIConstruction::calcMetadataWeights(
const BasicBlock *BB) {
302 SmallVector<unsigned, 2> UnreachableIdxs;
303 SmallVector<unsigned, 2> ReachableIdxs;
307 for (
unsigned I = 0,
E = Weights.
size();
I !=
E; ++
I) {
308 WeightSum += Weights[
I];
309 auto EstimatedWeight = getEstimatedEdgeWeight({BB, *Succs++});
310 if (EstimatedWeight &&
321 (WeightSum > UINT32_MAX) ? WeightSum / UINT32_MAX + 1 : 1;
323 if (ScalingFactor > 1) {
326 Weights[
I] /= ScalingFactor;
327 WeightSum += Weights[
I];
330 assert(WeightSum <= UINT32_MAX &&
331 "Expected weights to scale down to 32 bits");
333 if (WeightSum == 0 || ReachableIdxs.
size() == 0) {
342 BP.
push_back({ Weights[
I],
static_cast<uint32_t
>(WeightSum) });
346 if (UnreachableIdxs.
size() == 0 || ReachableIdxs.
size() == 0) {
352 for (
auto I : UnreachableIdxs)
353 if (UnreachableProb < BP[
I]) {
354 BP[
I] = UnreachableProb;
378 for (
auto I : UnreachableIdxs)
379 NewUnreachableSum += BP[
I];
381 BranchProbability NewReachableSum =
385 for (
auto I : ReachableIdxs)
386 OldReachableSum += BP[
I];
388 if (OldReachableSum != NewReachableSum) {
389 if (OldReachableSum.
isZero()) {
393 BranchProbability PerEdge = NewReachableSum / ReachableIdxs.size();
394 for (
auto I : ReachableIdxs)
397 for (
auto I : ReachableIdxs) {
403 BP[
I].getNumerator();
404 uint32_t Div =
static_cast<uint32_t
>(
418bool BPIConstruction::calcPointerHeuristics(
const BasicBlock *BB) {
436 case ICmpInst::ICMP_NE:
439 case ICmpInst::ICMP_EQ:
451computeUnlikelySuccessors(
const BasicBlock *BB,
const CycleInfo &CI, CycleRef
C,
452 SmallPtrSetImpl<const BasicBlock *> &UnlikelyBlocks) {
506 SmallPtrSet<PHINode*, 8> VisitedInsts;
509 VisitedInsts.
insert(CmpPHI);
510 while (!WorkList.
empty()) {
512 for (BasicBlock *
B :
P->blocks()) {
516 Value *
V =
P->getIncomingValueForBlock(
B);
520 if (VisitedInsts.
insert(PN).second)
542 Cmp->getPredicate(), CmpLHSConst, CmpConst,
DL);
552std::optional<uint32_t>
553BPIConstruction::getEstimatedBlockWeight(
const BasicBlock *BB)
const {
554 auto WeightIt = EstimatedBlockWeight.find(BB);
555 if (WeightIt == EstimatedBlockWeight.end())
557 return WeightIt->second;
560std::optional<uint32_t>
561BPIConstruction::getEstimatedLoopWeight(CycleRef
C)
const {
562 auto WeightIt = EstimatedLoopWeight.find(
C);
563 if (WeightIt == EstimatedLoopWeight.end())
565 return WeightIt->second;
568std::optional<uint32_t>
569BPIConstruction::getEstimatedEdgeWeight(
const LoopEdge &
Edge)
const {
572 return isLoopEnteringEdge(
Edge)
574 : getEstimatedBlockWeight(
Edge.second);
577template <
class IterT>
578std::optional<uint32_t> BPIConstruction::getMaxEstimatedEdgeWeight(
580 std::optional<uint32_t> MaxWeight;
581 for (
const BasicBlock *DstBB : Successors) {
582 auto Weight = getEstimatedEdgeWeight({SrcBB, DstBB});
585 if (!MaxWeight || *MaxWeight < *Weight)
597bool BPIConstruction::updateEstimatedBlockWeight(
598 const BasicBlock *BB, uint32_t BBWeight,
599 SmallVectorImpl<const BasicBlock *> &BlockWorkList,
600 SmallVectorImpl<const BasicBlock *> &LoopWorkList) {
606 if (!EstimatedBlockWeight.insert({BB, BBWeight}).second)
611 if (isLoopExitingEdge({PredBlock, BB})) {
612 if (!EstimatedLoopWeight.count(CI->
getCycle(PredBlock)))
614 }
else if (!EstimatedBlockWeight.count(PredBlock))
632void BPIConstruction::propagateEstimatedBlockWeight(
633 const BasicBlock *BB, DominatorTree *DT, PostDominatorTree *PDT,
634 uint32_t BBWeight, SmallVectorImpl<const BasicBlock *> &BlockWorkList,
635 SmallVectorImpl<const BasicBlock *> &LoopWorkList) {
636 const auto *DTStartNode = DT->
getNode(BB);
637 const auto *PDTStartNode = PDT->
getNode(BB);
640 for (
const auto *DTNode = DTStartNode; DTNode !=
nullptr;
641 DTNode = DTNode->getIDom()) {
642 auto *DomBB = DTNode->getBlock();
649 const LoopEdge
Edge{DomBB, BB};
651 if (!isLoopEnteringExitingEdge(
Edge)) {
652 if (!updateEstimatedBlockWeight(DomBB, BBWeight, BlockWorkList,
657 }
else if (isLoopExitingEdge(
Edge)) {
663std::optional<uint32_t>
664BPIConstruction::getInitialEstimatedBlockWeight(
const BasicBlock *BB) {
666 auto hasNoReturn = [&](
const BasicBlock *BB) {
669 if (CI->hasFnAttr(Attribute::NoReturn))
684 return hasNoReturn(BB)
693 for (
const auto &
I : *BB)
695 if (CI->hasFnAttr(Attribute::Cold))
704void BPIConstruction::estimateBlockWeights(
const Function &
F, DominatorTree *DT,
705 PostDominatorTree *PDT) {
706 SmallVector<const BasicBlock *, 8> BlockWorkList;
707 SmallVector<const BasicBlock *, 8> LoopWorkList;
708 SmallDenseMap<CycleRef, SmallVector<BasicBlock *, 4>> LoopExitBlocks;
712 ReversePostOrderTraversal<const Function *> RPOT(&
F);
713 for (
const auto *BB : RPOT)
714 if (
auto BBWeight = getInitialEstimatedBlockWeight(BB))
717 propagateEstimatedBlockWeight(BB, DT, PDT, *BBWeight, BlockWorkList,
725 while (!LoopWorkList.
empty()) {
728 if (EstimatedLoopWeight.count(
C))
732 SmallVectorImpl<BasicBlock *> &Exits = Res.first->second;
735 auto LoopWeight = getMaxEstimatedEdgeWeight(
743 EstimatedLoopWeight.insert({
C, *LoopWeight});
745 getLoopEnterBlocks(LoopBB, BlockWorkList);
749 while (!BlockWorkList.
empty()) {
752 if (EstimatedBlockWeight.count(BB))
761 auto MaxWeight = getMaxEstimatedEdgeWeight(BB,
successors(BB));
764 propagateEstimatedBlockWeight(BB, DT, PDT, *MaxWeight, BlockWorkList,
767 }
while (!BlockWorkList.
empty() || !LoopWorkList.
empty());
773bool BPIConstruction::calcEstimatedHeuristics(
const BasicBlock *BB) {
775 "expected more than one successor!");
777 CycleRef BBCycle = CI->
getCycle(BB);
779 SmallPtrSet<const BasicBlock *, 8> UnlikelyBlocks;
782 computeUnlikelySuccessors(BB, *CI, BBCycle, UnlikelyBlocks);
785 bool FoundEstimatedWeight =
false;
786 SmallVector<uint32_t, 4> SuccWeights;
789 for (
const BasicBlock *SuccBB :
successors(BB)) {
790 std::optional<uint32_t> Weight;
791 const LoopEdge
Edge{BB, SuccBB};
793 Weight = getEstimatedEdgeWeight(
Edge);
795 if (isLoopExitingEdge(
Edge) &&
804 bool IsUnlikelyEdge = BBCycle && UnlikelyBlocks.
contains(SuccBB);
805 if (IsUnlikelyEdge &&
815 FoundEstimatedWeight =
true;
819 TotalWeight += WeightVal;
826 if (!FoundEstimatedWeight || TotalWeight == 0)
830 const unsigned SuccCount = SuccWeights.
size();
834 if (TotalWeight > UINT32_MAX) {
835 uint64_t ScalingFactor = TotalWeight / UINT32_MAX + 1;
837 for (
unsigned Idx = 0; Idx < SuccCount; ++Idx) {
838 SuccWeights[Idx] /= ScalingFactor;
842 TotalWeight += SuccWeights[Idx];
844 assert(TotalWeight <= UINT32_MAX &&
"Total weight overflows");
851 for (
unsigned Idx = 0; Idx < SuccCount; ++Idx) {
852 EdgeProbabilities[Idx] =
853 BranchProbability(SuccWeights[Idx], (uint32_t)TotalWeight);
859bool BPIConstruction::calcZeroHeuristics(
const BasicBlock *BB,
860 const TargetLibraryInfo *TLI) {
870 auto GetConstantInt = [](
Value *
V) {
877 ConstantInt *CV = GetConstantInt(
RHS);
884 if (
LHS->getOpcode() == Instruction::And)
885 if (ConstantInt *AndRHS = GetConstantInt(
LHS->getOperand(1)))
886 if (AndRHS->getValue().isPowerOf2())
890 LibFunc
Func = LibFunc::NotLibFunc;
897 if (Func == LibFunc_strcasecmp ||
898 Func == LibFunc_strcmp ||
899 Func == LibFunc_strncasecmp ||
900 Func == LibFunc_strncmp ||
901 Func == LibFunc_memcmp ||
902 Func == LibFunc_bcmp) {
914 default:
return false;
917 }
else if (CV->
isZero()) {
924 default:
return false;
927 }
else if (CV->
isOne()) {
931 default:
return false;
941 default:
return false;
955bool BPIConstruction::calcFloatingPointHeuristics(
const BasicBlock *BB) {
970 }
else if (FCmp->
getPredicate() == FCmpInst::FCMP_ORD) {
973 }
else if (FCmp->
getPredicate() == FCmpInst::FCMP_UNO) {
981void BPIConstruction::calculate(
const Function &
F,
const CycleInfo &CycleI,
982 const TargetLibraryInfo *TLI, DominatorTree *DT,
983 PostDominatorTree *PDT) {
986 std::unique_ptr<DominatorTree> DTPtr;
987 std::unique_ptr<PostDominatorTree> PDTPtr;
990 DTPtr = std::make_unique<DominatorTree>(
const_cast<Function &
>(
F));
995 PDTPtr = std::make_unique<PostDominatorTree>(
const_cast<Function &
>(
F));
999 estimateBlockWeights(
F, DT, PDT);
1003 for (
const auto *BB :
post_order(&
F.getEntryBlock())) {
1009 if (calcMetadataWeights(BB))
1011 if (calcEstimatedHeuristics(BB))
1013 if (calcPointerHeuristics(BB))
1015 if (calcZeroHeuristics(BB, TLI))
1017 if (calcFloatingPointHeuristics(BB))
1025BranchProbabilityInfo::allocEdges(
const BasicBlock *BB) {
1027 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1029 if (NumSuccs == 0) {
1033 if (EdgeStarts.size() <= BB->
getNumber())
1034 EdgeStarts.resize(LastF->getMaxBlockNumber(), 0);
1035 unsigned EdgeStart = Probs.size();
1036 EdgeStarts[BB->
getNumber()] = EdgeStart + 1;
1037 Probs.append(NumSuccs, {});
1042BranchProbabilityInfo::getEdges(
const BasicBlock *BB)
const {
1044 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1045 if (EdgeStarts.size() <= BB->
getNumber())
1047 if (
unsigned EdgeStart = EdgeStarts[BB->
getNumber()]) {
1048 const BranchProbability *
Start = &Probs[EdgeStart - 1];
1049 size_t Count = SIZE_MAX;
1059 FunctionAnalysisManager::Invalidator &) {
1068 OS <<
"---- Branch Probabilities ----\n";
1071 assert(LastF &&
"Cannot print prior to running over a function");
1072 for (
const auto &BI : *LastF) {
1091 unsigned IndexInSuccessors)
const {
1093 return P[IndexInSuccessors];
1108 if (It.value() == Dst)
1109 Prob +=
P[It.index()];
1117 assert(Src->getTerminator()->getNumSuccessors() == Probs.size());
1119 uint64_t TotalNumerator = 0;
1120 for (
unsigned SuccIdx = 0; SuccIdx < Probs.size(); ++SuccIdx) {
1121 P[SuccIdx] = Probs[SuccIdx];
1122 LLVM_DEBUG(
dbgs() <<
"set edge " << Src->getName() <<
" -> " << SuccIdx
1123 <<
" successor probability to " << Probs[SuccIdx]
1125 TotalNumerator += Probs[SuccIdx].getNumerator();
1137 (void)TotalNumerator;
1151 for (
unsigned i = 0; i != DstP.
size(); ++i) {
1153 LLVM_DEBUG(
dbgs() <<
"set edge " << Dst->getName() <<
" -> " << i
1154 <<
" successor probability to " << SrcP[i] <<
"\n");
1159 assert(Src->getTerminator()->getNumSuccessors() == 2);
1174 Src->printAsOperand(OS,
false, Src->getModule());
1176 Dst->printAsOperand(OS,
false, Dst->getModule());
1177 OS <<
" probability is " << Prob
1178 << (
isEdgeHot(Src, Dst) ?
" [HOT edge]\n" :
"\n");
1186 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1187 if (EdgeStarts.size() > BB->
getNumber())
1199 BlockNumberEpoch =
F.getBlockNumberEpoch();
1202 BPIConstruction(*this).calculate(
F, CycleI, TLI, DT, PDT);
1230 BPI.calculate(
F, CI, &TLI, &DT, &PDT);
1253 OS <<
"Printing analysis 'Branch Probability Analysis' for function '"
1254 <<
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< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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.
LibFunc getLibFunc(StringRef funcName) 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.
@ 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...