51#define DEBUG_TYPE "branch-prob"
55 cl::desc(
"Print the branch probability info."));
59 cl::desc(
"The option to specify the name of the function "
60 "whose branch probability info is printed."));
63 "Branch Probability Analysis",
false,
true)
222 const std::vector<const BasicBlock *> &Scc = *It;
227 for (
const auto *BB : Scc) {
229 SccNums[BB] = SccNum;
230 calculateSccBlockType(BB, SccNum);
237 auto SccIt = SccNums.find(BB);
238 if (SccIt == SccNums.end())
240 return SccIt->second;
246 for (
auto MapIt : SccBlocks[SccNum]) {
247 const auto *BB = MapIt.first;
257 for (
auto MapIt : SccBlocks[SccNum]) {
258 const auto *BB = MapIt.first;
268 assert(getSCCNum(BB) == SccNum);
270 assert(SccBlocks.size() >
static_cast<unsigned>(SccNum) &&
"Unknown SCC");
271 const auto &SccBlockTypes = SccBlocks[SccNum];
273 auto It = SccBlockTypes.find(BB);
274 if (It != SccBlockTypes.end()) {
280void BranchProbabilityInfo::SccInfo::calculateSccBlockType(
const BasicBlock *BB,
282 assert(getSCCNum(BB) == SccNum);
288 return getSCCNum(Pred) != SccNum;
293 return getSCCNum(Succ) != SccNum;
295 BlockType |= Exiting;
299 if (SccBlocks.size() <=
static_cast<unsigned>(SccNum))
300 SccBlocks.resize(SccNum + 1);
301 auto &SccBlockTypes = SccBlocks[SccNum];
303 if (BlockType != Inner) {
305 std::tie(std::ignore, IsInserted) =
306 SccBlockTypes.insert(std::make_pair(BB, BlockType));
307 assert(IsInserted &&
"Duplicated block in SCC");
311BranchProbabilityInfo::LoopBlock::LoopBlock(
const BasicBlock *BB,
317 LD.second = SccI.getSCCNum(BB);
321bool BranchProbabilityInfo::isLoopEnteringEdge(
const LoopEdge &Edge)
const {
322 const auto &SrcBlock = Edge.first;
323 const auto &DstBlock = Edge.second;
324 return (DstBlock.getLoop() &&
325 !DstBlock.getLoop()->contains(SrcBlock.getLoop())) ||
327 (DstBlock.getSccNum() != -1 &&
328 SrcBlock.getSccNum() != DstBlock.getSccNum());
331bool BranchProbabilityInfo::isLoopExitingEdge(
const LoopEdge &Edge)
const {
332 return isLoopEnteringEdge({Edge.second, Edge.first});
335bool BranchProbabilityInfo::isLoopEnteringExitingEdge(
336 const LoopEdge &Edge)
const {
337 return isLoopEnteringEdge(Edge) || isLoopExitingEdge(Edge);
340bool BranchProbabilityInfo::isLoopBackEdge(
const LoopEdge &Edge)
const {
341 const auto &SrcBlock = Edge.first;
342 const auto &DstBlock = Edge.second;
343 return SrcBlock.belongsToSameLoop(DstBlock) &&
344 ((DstBlock.getLoop() &&
345 DstBlock.getLoop()->getHeader() == DstBlock.getBlock()) ||
346 (DstBlock.getSccNum() != -1 &&
347 SccI->isSCCHeader(DstBlock.getBlock(), DstBlock.getSccNum())));
350void BranchProbabilityInfo::getLoopEnterBlocks(
351 const LoopBlock &LB, SmallVectorImpl<BasicBlock *> &Enters)
const {
353 auto *Header = LB.getLoop()->getHeader();
356 assert(LB.getSccNum() != -1 &&
"LB doesn't belong to any loop?");
357 SccI->getSccEnterBlocks(LB.getSccNum(), Enters);
361void BranchProbabilityInfo::getLoopExitBlocks(
362 const LoopBlock &LB, SmallVectorImpl<BasicBlock *> &Exits)
const {
364 LB.getLoop()->getExitBlocks(Exits);
366 assert(LB.getSccNum() != -1 &&
"LB doesn't belong to any loop?");
367 SccI->getSccExitBlocks(LB.getSccNum(), Exits);
375bool BranchProbabilityInfo::calcMetadataWeights(
const BasicBlock *BB) {
392 uint64_t WeightSum = 0;
394 SmallVector<unsigned, 2> UnreachableIdxs;
395 SmallVector<unsigned, 2> ReachableIdxs;
398 for (
unsigned I = 0,
E = Weights.
size();
I !=
E; ++
I) {
399 WeightSum += Weights[
I];
400 const LoopBlock SrcLoopBB = getLoopBlock(BB);
401 const LoopBlock DstLoopBB = getLoopBlock(TI->
getSuccessor(
I));
402 auto EstimatedWeight = getEstimatedEdgeWeight({SrcLoopBB, DstLoopBB});
403 if (EstimatedWeight &&
413 uint64_t ScalingFactor =
414 (WeightSum > UINT32_MAX) ? WeightSum / UINT32_MAX + 1 : 1;
416 if (ScalingFactor > 1) {
419 Weights[
I] /= ScalingFactor;
420 WeightSum += Weights[
I];
423 assert(WeightSum <= UINT32_MAX &&
424 "Expected weights to scale down to 32 bits");
426 if (WeightSum == 0 || ReachableIdxs.
size() == 0) {
435 BP.
push_back({ Weights[
I],
static_cast<uint32_t
>(WeightSum) });
439 if (UnreachableIdxs.
size() == 0 || ReachableIdxs.
size() == 0) {
445 for (
auto I : UnreachableIdxs)
446 if (UnreachableProb < BP[
I]) {
447 BP[
I] = UnreachableProb;
471 for (
auto I : UnreachableIdxs)
472 NewUnreachableSum += BP[
I];
474 BranchProbability NewReachableSum =
478 for (
auto I : ReachableIdxs)
479 OldReachableSum += BP[
I];
481 if (OldReachableSum != NewReachableSum) {
482 if (OldReachableSum.
isZero()) {
486 BranchProbability PerEdge = NewReachableSum / ReachableIdxs.size();
487 for (
auto I : ReachableIdxs)
490 for (
auto I : ReachableIdxs) {
496 BP[
I].getNumerator();
497 uint32_t Div =
static_cast<uint32_t
>(
511bool BranchProbabilityInfo::calcPointerHeuristics(
const BasicBlock *BB) {
583 if (!L->contains(CmpLHS))
590 if (!CmpPHI || !L->contains(CmpPHI))
597 VisitedInsts.
insert(CmpPHI);
598 while (!WorkList.
empty()) {
604 Value *V =
P->getIncomingValueForBlock(
B);
608 if (VisitedInsts.
insert(PN).second)
633 if (Result && ((Result->isNullValue() &&
B == BI->
getSuccessor(0)) ||
640std::optional<uint32_t>
641BranchProbabilityInfo::getEstimatedBlockWeight(
const BasicBlock *BB)
const {
642 auto WeightIt = EstimatedBlockWeight.find(BB);
643 if (WeightIt == EstimatedBlockWeight.end())
645 return WeightIt->second;
648std::optional<uint32_t>
649BranchProbabilityInfo::getEstimatedLoopWeight(
const LoopData &L)
const {
650 auto WeightIt = EstimatedLoopWeight.find(L);
651 if (WeightIt == EstimatedLoopWeight.end())
653 return WeightIt->second;
656std::optional<uint32_t>
657BranchProbabilityInfo::getEstimatedEdgeWeight(
const LoopEdge &Edge)
const {
660 return isLoopEnteringEdge(Edge)
661 ? getEstimatedLoopWeight(Edge.second.getLoopData())
662 : getEstimatedBlockWeight(Edge.second.getBlock());
665template <
class IterT>
666std::optional<uint32_t> BranchProbabilityInfo::getMaxEstimatedEdgeWeight(
668 std::optional<uint32_t> MaxWeight;
669 for (
const BasicBlock *DstBB : Successors) {
670 const LoopBlock DstLoopBB = getLoopBlock(DstBB);
671 auto Weight = getEstimatedEdgeWeight({SrcLoopBB, DstLoopBB});
676 if (!MaxWeight || *MaxWeight < *Weight)
688bool BranchProbabilityInfo::updateEstimatedBlockWeight(
689 LoopBlock &LoopBB, uint32_t BBWeight,
690 SmallVectorImpl<BasicBlock *> &BlockWorkList,
691 SmallVectorImpl<LoopBlock> &LoopWorkList) {
699 if (!EstimatedBlockWeight.insert({BB, BBWeight}).second)
703 LoopBlock PredLoop = getLoopBlock(PredBlock);
705 if (isLoopExitingEdge({PredLoop, LoopBB})) {
706 if (!EstimatedLoopWeight.count(PredLoop.getLoopData()))
708 }
else if (!EstimatedBlockWeight.count(PredBlock))
726void BranchProbabilityInfo::propagateEstimatedBlockWeight(
727 const LoopBlock &LoopBB, DominatorTree *DT, PostDominatorTree *PDT,
728 uint32_t BBWeight, SmallVectorImpl<BasicBlock *> &BlockWorkList,
729 SmallVectorImpl<LoopBlock> &LoopWorkList) {
731 const auto *DTStartNode = DT->
getNode(BB);
732 const auto *PDTStartNode = PDT->
getNode(BB);
735 for (
const auto *DTNode = DTStartNode; DTNode !=
nullptr;
736 DTNode = DTNode->getIDom()) {
737 auto *DomBB = DTNode->getBlock();
744 LoopBlock DomLoopBB = getLoopBlock(DomBB);
745 const LoopEdge Edge{DomLoopBB, LoopBB};
747 if (!isLoopEnteringExitingEdge(Edge)) {
748 if (!updateEstimatedBlockWeight(DomLoopBB, BBWeight, BlockWorkList,
753 }
else if (isLoopExitingEdge(Edge)) {
759std::optional<uint32_t>
760BranchProbabilityInfo::getInitialEstimatedBlockWeight(
const BasicBlock *BB) {
762 auto hasNoReturn = [&](
const BasicBlock *BB) {
765 if (CI->hasFnAttr(Attribute::NoReturn))
780 return hasNoReturn(BB)
789 for (
const auto &
I : *BB)
791 if (CI->hasFnAttr(Attribute::Cold))
800void BranchProbabilityInfo::estimateBlockWeights(
const Function &
F,
802 PostDominatorTree *PDT) {
803 SmallVector<BasicBlock *, 8> BlockWorkList;
805 SmallDenseMap<LoopData, SmallVector<BasicBlock *, 4>> LoopExitBlocks;
809 ReversePostOrderTraversal<const Function *> RPOT(&
F);
810 for (
const auto *BB : RPOT)
811 if (
auto BBWeight = getInitialEstimatedBlockWeight(BB))
814 propagateEstimatedBlockWeight(getLoopBlock(BB), DT, PDT, *BBWeight,
815 BlockWorkList, LoopWorkList);
822 while (!LoopWorkList.
empty()) {
824 const LoopData
LD = LoopBB.getLoopData();
825 if (EstimatedLoopWeight.count(LD))
829 SmallVectorImpl<BasicBlock *> &Exits = Res.first->second;
831 getLoopExitBlocks(LoopBB, Exits);
832 auto LoopWeight = getMaxEstimatedEdgeWeight(
840 EstimatedLoopWeight.insert({
LD, *LoopWeight});
842 getLoopEnterBlocks(LoopBB, BlockWorkList);
846 while (!BlockWorkList.
empty()) {
849 if (EstimatedBlockWeight.count(BB))
858 const LoopBlock LoopBB = getLoopBlock(BB);
859 auto MaxWeight = getMaxEstimatedEdgeWeight(LoopBB,
successors(BB));
862 propagateEstimatedBlockWeight(LoopBB, DT, PDT, *MaxWeight,
863 BlockWorkList, LoopWorkList);
865 }
while (!BlockWorkList.
empty() || !LoopWorkList.
empty());
871bool BranchProbabilityInfo::calcEstimatedHeuristics(
const BasicBlock *BB) {
873 "expected more than one successor!");
875 const LoopBlock LoopBB = getLoopBlock(BB);
877 SmallPtrSet<const BasicBlock *, 8> UnlikelyBlocks;
879 if (LoopBB.getLoop())
883 bool FoundEstimatedWeight =
false;
884 SmallVector<uint32_t, 4> SuccWeights;
885 uint64_t TotalWeight = 0;
887 for (
const BasicBlock *SuccBB :
successors(BB)) {
888 std::optional<uint32_t> Weight;
889 const LoopBlock SuccLoopBB = getLoopBlock(SuccBB);
890 const LoopEdge Edge{LoopBB, SuccLoopBB};
892 Weight = getEstimatedEdgeWeight(Edge);
894 if (isLoopExitingEdge(Edge) &&
903 bool IsUnlikelyEdge = LoopBB.getLoop() && UnlikelyBlocks.
contains(SuccBB);
904 if (IsUnlikelyEdge &&
914 FoundEstimatedWeight =
true;
918 TotalWeight += WeightVal;
925 if (!FoundEstimatedWeight || TotalWeight == 0)
929 const unsigned SuccCount = SuccWeights.
size();
933 if (TotalWeight > UINT32_MAX) {
934 uint64_t ScalingFactor = TotalWeight / UINT32_MAX + 1;
936 for (
unsigned Idx = 0; Idx < SuccCount; ++Idx) {
937 SuccWeights[Idx] /= ScalingFactor;
941 TotalWeight += SuccWeights[Idx];
943 assert(TotalWeight <= UINT32_MAX &&
"Total weight overflows");
950 for (
unsigned Idx = 0; Idx < SuccCount; ++Idx) {
951 EdgeProbabilities[Idx] =
952 BranchProbability(SuccWeights[Idx], (uint32_t)TotalWeight);
958bool BranchProbabilityInfo::calcZeroHeuristics(
const BasicBlock *BB,
959 const TargetLibraryInfo *TLI) {
969 auto GetConstantInt = [](
Value *
V) {
976 ConstantInt *CV = GetConstantInt(
RHS);
983 if (
LHS->getOpcode() == Instruction::And)
984 if (ConstantInt *AndRHS = GetConstantInt(
LHS->getOperand(1)))
985 if (AndRHS->getValue().isPowerOf2())
989 LibFunc
Func = LibFunc::NotLibFunc;
995 ProbabilityTable::const_iterator Search;
996 if (Func == LibFunc_strcasecmp ||
997 Func == LibFunc_strcmp ||
998 Func == LibFunc_strncasecmp ||
999 Func == LibFunc_strncmp ||
1000 Func == LibFunc_memcmp ||
1001 Func == LibFunc_bcmp) {
1005 }
else if (CV->
isZero()) {
1009 }
else if (CV->
isOne()) {
1025bool BranchProbabilityInfo::calcFloatingPointHeuristics(
const BasicBlock *BB) {
1046 ProbList = Search->second;
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 {
1092 auto I = Probs.find(std::make_pair(Src, IndexInSuccessors));
1093 assert((Probs.end() == Probs.find(std::make_pair(Src, 0))) ==
1094 (Probs.end() ==
I) &&
1095 "Probability for I-th successor must always be defined along with the "
1096 "probability for the first successor");
1098 if (
I != Probs.end())
1115 if (!Probs.count(std::make_pair(Src, 0)))
1121 Prob += Probs.find(std::make_pair(Src,
I.getSuccessorIndex()))->second;
1129 assert(Src->getTerminator()->getNumSuccessors() == Probs.size());
1131 if (Probs.size() == 0)
1134 Handles.insert(BasicBlockCallbackVH(Src,
this));
1136 for (
unsigned SuccIdx = 0; SuccIdx < Probs.size(); ++SuccIdx) {
1137 this->Probs[std::make_pair(Src, SuccIdx)] = Probs[SuccIdx];
1138 LLVM_DEBUG(
dbgs() <<
"set edge " << Src->getName() <<
" -> " << SuccIdx
1139 <<
" successor probability to " << Probs[SuccIdx]
1141 TotalNumerator += Probs[SuccIdx].getNumerator();
1151 (void)TotalNumerator;
1157 unsigned NumSuccessors = Src->getTerminator()->getNumSuccessors();
1158 assert(NumSuccessors == Dst->getTerminator()->getNumSuccessors());
1159 if (NumSuccessors == 0)
1161 if (!this->Probs.contains(std::make_pair(Src, 0)))
1164 Handles.insert(BasicBlockCallbackVH(Dst,
this));
1165 for (
unsigned SuccIdx = 0; SuccIdx < NumSuccessors; ++SuccIdx) {
1166 auto Prob = this->Probs[std::make_pair(Src, SuccIdx)];
1167 this->Probs[std::make_pair(Dst, SuccIdx)] = Prob;
1168 LLVM_DEBUG(
dbgs() <<
"set edge " << Dst->getName() <<
" -> " << SuccIdx
1169 <<
" successor probability to " << Prob <<
"\n");
1174 assert(Src->getTerminator()->getNumSuccessors() == 2);
1175 auto It0 = Probs.find(std::make_pair(Src, 0));
1176 if (It0 == Probs.end())
1178 auto It1 = Probs.find(std::make_pair(Src, 1));
1179 assert(It1 != Probs.end());
1189 Src->printAsOperand(OS,
false, Src->getModule());
1191 Dst->printAsOperand(OS,
false, Dst->getModule());
1192 OS <<
" probability is " << Prob
1193 << (
isEdgeHot(Src, Dst) ?
" [HOT edge]\n" :
"\n");
1208 Handles.erase(BasicBlockCallbackVH(BB,
this));
1209 for (
unsigned I = 0;; ++
I) {
1210 auto MapI = Probs.find(std::make_pair(BB,
I));
1211 if (MapI == Probs.end()) {
1212 assert(Probs.count(std::make_pair(BB,
I + 1)) == 0 &&
1213 "Must be no more successors");
1229 SccI = std::make_unique<SccInfo>(
F);
1231 assert(EstimatedBlockWeight.empty());
1232 assert(EstimatedLoopWeight.empty());
1234 std::unique_ptr<DominatorTree> DTPtr;
1235 std::unique_ptr<PostDominatorTree> PDTPtr;
1238 DTPtr = std::make_unique<DominatorTree>(
const_cast<Function &
>(
F));
1243 PDTPtr = std::make_unique<PostDominatorTree>(
const_cast<Function &
>(
F));
1247 estimateBlockWeights(
F, DT, PDT);
1251 for (
const auto *BB :
post_order(&
F.getEntryBlock())) {
1257 if (calcMetadataWeights(BB))
1259 if (calcEstimatedHeuristics(BB))
1261 if (calcPointerHeuristics(BB))
1263 if (calcZeroHeuristics(BB, TLI))
1265 if (calcFloatingPointHeuristics(BB))
1269 EstimatedLoopWeight.clear();
1270 EstimatedBlockWeight.clear();
1299 BPI.calculate(
F, LI, &TLI, &DT, &PDT);
1324 OS <<
"Printing analysis 'Branch Probability Analysis' for function '"
1325 <<
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
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 const uint32_t FPH_TAKEN_WEIGHT
static const BranchProbability FPUntakenProb(FPH_NONTAKEN_WEIGHT, FPH_TAKEN_WEIGHT+FPH_NONTAKEN_WEIGHT)
static const BranchProbability ZeroUntakenProb(ZH_NONTAKEN_WEIGHT, ZH_TAKEN_WEIGHT+ZH_NONTAKEN_WEIGHT)
static const uint32_t LBH_TAKEN_WEIGHT
static const uint32_t ZH_NONTAKEN_WEIGHT
static const ProbabilityTable ICmpWithLibCallTable
strcmp and similar functions return zero, negative, or positive, if the first string is equal,...
static const ProbabilityTable ICmpWithMinusOneTable
Integer compares with -1:
static const BranchProbability FPOrdTakenProb(FPH_ORD_WEIGHT, FPH_ORD_WEIGHT+FPH_UNO_WEIGHT)
static const ProbabilityTable ICmpWithZeroTable
Integer compares with 0:
static const uint32_t PH_NONTAKEN_WEIGHT
std::map< CmpInst::Predicate, ProbabilityList > ProbabilityTable
static const BranchProbability PtrTakenProb(PH_TAKEN_WEIGHT, PH_TAKEN_WEIGHT+PH_NONTAKEN_WEIGHT)
static const BranchProbability ZeroTakenProb(ZH_TAKEN_WEIGHT, ZH_TAKEN_WEIGHT+ZH_NONTAKEN_WEIGHT)
static const BranchProbability FPOrdUntakenProb(FPH_UNO_WEIGHT, FPH_ORD_WEIGHT+FPH_UNO_WEIGHT)
static const uint32_t PH_TAKEN_WEIGHT
Heuristics and lookup tables for non-loop branches: Pointer Heuristics (PH)
static const BranchProbability FPTakenProb(FPH_TAKEN_WEIGHT, FPH_TAKEN_WEIGHT+FPH_NONTAKEN_WEIGHT)
static const BranchProbability PtrUntakenProb(PH_NONTAKEN_WEIGHT, PH_TAKEN_WEIGHT+PH_NONTAKEN_WEIGHT)
SmallVector< BranchProbability > ProbabilityList
static const ProbabilityTable ICmpWithOneTable
Integer compares with 1:
static const uint32_t ZH_TAKEN_WEIGHT
Zero Heuristics (ZH)
static const uint32_t FPH_NONTAKEN_WEIGHT
static const BranchProbability UR_TAKEN_PROB
Unreachable-terminating branch taken probability.
static const ProbabilityTable FCmpTable
Floating-Point compares:
static const uint32_t LBH_NONTAKEN_WEIGHT
static const ProbabilityTable PointerTable
Pointer comparisons:
static const uint32_t FPH_ORD_WEIGHT
This is the probability for an ordered floating point comparison.
static void computeUnlikelySuccessors(const BasicBlock *BB, Loop *L, SmallPtrSetImpl< const BasicBlock * > &UnlikelyBlocks)
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 cl::opt< bool > PrintBranchProb("print-bpi", cl::init(false), cl::Hidden, cl::desc("Print the branch probability info."))
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 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
This builds on the llvm/ADT/GraphTraits.h file to find the strongly connected components (SCCs) of a ...
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.
LLVM Basic Block Representation.
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 if the block is well formed or null if the block is not well forme...
Conditional or Unconditional Branch instruction.
bool isConditional() const
BasicBlock * getSuccessor(unsigned i) const
Value * getCondition() const
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 releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
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.
bool isSCCHeader(const BasicBlock *BB, int SccNum) const
Returns true if BB is a 'header' block in SCC with SccNum ID, false otherwise.
LLVM_ABI void getSccEnterBlocks(int SccNum, SmallVectorImpl< BasicBlock * > &Enters) const
Fills in Enters vector with all such blocks that don't belong to SCC with SccNum ID but there is an e...
bool isSCCExitingBlock(const BasicBlock *BB, int SccNum) const
Returns true if BB is an 'exiting' block in SCC with SccNum ID, false otherwise.
LLVM_ABI SccInfo(const Function &F)
LLVM_ABI void getSccExitBlocks(int SccNum, SmallVectorImpl< BasicBlock * > &Exits) const
Fills in Exits vector with all such blocks that don't belong to SCC with SccNum ID but there is an ed...
LLVM_ABI int getSCCNum(const BasicBlock *BB) const
If BB belongs to some SCC then ID of that SCC is returned, otherwise -1 is returned.
Analysis providing branch probability information.
LLVM_ABI void eraseBlock(const BasicBlock *BB)
Forget analysis results for the given basic block.
LLVM_ABI void setEdgeProbability(const BasicBlock *Src, const SmallVectorImpl< BranchProbability > &Probs)
Set the raw probabilities for all edges from the given block.
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 calculate(const Function &F, const LoopInfo &LI, const TargetLibraryInfo *TLI, DominatorTree *DT, PostDominatorTree *PDT)
LLVM_ABI void releaseMemory()
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 uint32_t getDenominator()
static BranchProbability getRaw(uint32_t N)
static BranchProbability getOne()
static BranchProbability getUnknown()
uint32_t getNumerator() const
static BranchProbability getZero()
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...
This class is the base class for the comparison instructions.
@ ICMP_SLT
signed less than
@ ICMP_SGT
signed greater than
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
bool isTrueWhenEqual() const
This is just a convenience.
Predicate getPredicate() const
Return the predicate for this instruction.
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.
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
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)
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.
LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
Analysis pass that exposes the LoopInfo for a function.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
The legacy pass manager's analysis pass to compute loop information.
Represents a single loop in the control flow graph.
A Module instance is used to store all the information related to an LLVM module.
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.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
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
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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
LLVM Value Representation.
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.
This class implements an extremely fast bulk output stream that can only output to a stream.
Enumerate the SCCs of a directed graph in reverse topological order of the SCC DAG.
bool isAtEnd() const
Direct loop termination test which is more efficient than comparison with end().
@ 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.
FunctionAddr VTableAddr Value
auto pred_end(const MachineBasicBlock *BB)
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.
scc_iterator< T > scc_begin(const T &G)
Construct the begin iterator for a deduced graph type T.
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.
iterator_range< po_iterator< T > > post_order(const T &G)
constexpr T divideNearest(U Numerator, V Denominator)
Returns (Numerator / Denominator) rounded by round-half-up.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
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...
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.
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)
@ Mul
Product of integers.
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...
LLVM_ABI bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
auto pred_begin(const MachineBasicBlock *BB)
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.
SuccIterator< const Instruction, const BasicBlock > const_succ_iterator
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...