52#define DEBUG_TYPE "branch-prob"
56 cl::desc(
"Print the branch probability info."));
60 cl::desc(
"The option to specify the name of the function "
61 "whose branch probability info is printed."));
64 "Branch Probability Analysis",
false,
true)
226 const std::vector<const BasicBlock *> &Scc = *It;
231 for (
const auto *BB : Scc) {
233 SccNums[BB] = SccNum;
234 calculateSccBlockType(BB, SccNum);
241 auto SccIt = SccNums.find(BB);
242 if (SccIt == SccNums.end())
244 return SccIt->second;
250 for (
auto MapIt : SccBlocks[SccNum]) {
251 const auto *BB = MapIt.first;
252 if (isSCCHeader(BB, SccNum))
254 if (getSCCNum(Pred) != SccNum)
261 for (
auto MapIt : SccBlocks[SccNum]) {
262 const auto *BB = MapIt.first;
263 if (isSCCExitingBlock(BB, SccNum))
265 if (getSCCNum(Succ) != SccNum)
272 assert(getSCCNum(BB) == SccNum);
274 assert(SccBlocks.size() >
static_cast<unsigned>(SccNum) &&
"Unknown SCC");
275 const auto &SccBlockTypes = SccBlocks[SccNum];
277 auto It = SccBlockTypes.find(BB);
278 if (It != SccBlockTypes.end()) {
284void BranchProbabilityInfo::SccInfo::calculateSccBlockType(
const BasicBlock *BB,
286 assert(getSCCNum(BB) == SccNum);
292 return getSCCNum(Pred) != SccNum;
297 return getSCCNum(Succ) != SccNum;
303 if (SccBlocks.size() <=
static_cast<unsigned>(SccNum))
304 SccBlocks.resize(SccNum + 1);
305 auto &SccBlockTypes = SccBlocks[SccNum];
307 if (BlockType != Inner) {
309 std::tie(std::ignore, IsInserted) =
310 SccBlockTypes.insert(std::make_pair(BB, BlockType));
311 assert(IsInserted &&
"Duplicated block in SCC");
315BranchProbabilityInfo::LoopBlock::LoopBlock(
const BasicBlock *BB,
321 LD.second = SccI.getSCCNum(BB);
325bool BranchProbabilityInfo::isLoopEnteringEdge(
const LoopEdge &Edge)
const {
326 const auto &SrcBlock = Edge.first;
327 const auto &DstBlock = Edge.second;
328 return (DstBlock.getLoop() &&
329 !DstBlock.getLoop()->contains(SrcBlock.getLoop())) ||
331 (DstBlock.getSccNum() != -1 &&
332 SrcBlock.getSccNum() != DstBlock.getSccNum());
335bool BranchProbabilityInfo::isLoopExitingEdge(
const LoopEdge &Edge)
const {
336 return isLoopEnteringEdge({Edge.second, Edge.first});
339bool BranchProbabilityInfo::isLoopEnteringExitingEdge(
340 const LoopEdge &Edge)
const {
341 return isLoopEnteringEdge(Edge) || isLoopExitingEdge(Edge);
344bool BranchProbabilityInfo::isLoopBackEdge(
const LoopEdge &Edge)
const {
345 const auto &SrcBlock = Edge.first;
346 const auto &DstBlock = Edge.second;
347 return SrcBlock.belongsToSameLoop(DstBlock) &&
348 ((DstBlock.getLoop() &&
349 DstBlock.getLoop()->getHeader() == DstBlock.getBlock()) ||
350 (DstBlock.getSccNum() != -1 &&
351 SccI->isSCCHeader(DstBlock.getBlock(), DstBlock.getSccNum())));
354void BranchProbabilityInfo::getLoopEnterBlocks(
357 auto *Header = LB.getLoop()->getHeader();
360 assert(LB.getSccNum() != -1 &&
"LB doesn't belong to any loop?");
361 SccI->getSccEnterBlocks(LB.getSccNum(), Enters);
365void BranchProbabilityInfo::getLoopExitBlocks(
368 LB.getLoop()->getExitBlocks(Exits);
370 assert(LB.getSccNum() != -1 &&
"LB doesn't belong to any loop?");
371 SccI->getSccExitBlocks(LB.getSccNum(), Exits);
379bool BranchProbabilityInfo::calcMetadataWeights(
const BasicBlock *BB) {
382 if (!(isa<BranchInst>(TI) || isa<SwitchInst>(TI) || isa<IndirectBrInst>(TI) ||
383 isa<InvokeInst>(TI) || isa<CallBrInst>(TI)))
402 for (
unsigned I = 0, E = Weights.
size();
I != E; ++
I) {
403 WeightSum += Weights[
I];
404 const LoopBlock SrcLoopBB = getLoopBlock(BB);
405 const LoopBlock DstLoopBB = getLoopBlock(TI->
getSuccessor(
I));
406 auto EstimatedWeight = getEstimatedEdgeWeight({SrcLoopBB, DstLoopBB});
407 if (EstimatedWeight &&
408 *EstimatedWeight <=
static_cast<uint32_t>(BlockExecWeight::UNREACHABLE))
418 (WeightSum > UINT32_MAX) ? WeightSum / UINT32_MAX + 1 : 1;
420 if (ScalingFactor > 1) {
423 Weights[
I] /= ScalingFactor;
424 WeightSum += Weights[
I];
427 assert(WeightSum <= UINT32_MAX &&
428 "Expected weights to scale down to 32 bits");
430 if (WeightSum == 0 || ReachableIdxs.
size() == 0) {
443 if (UnreachableIdxs.
size() == 0 || ReachableIdxs.
size() == 0) {
449 for (
auto I : UnreachableIdxs)
450 if (UnreachableProb < BP[
I]) {
451 BP[
I] = UnreachableProb;
475 for (
auto I : UnreachableIdxs)
476 NewUnreachableSum += BP[
I];
482 for (
auto I : ReachableIdxs)
483 OldReachableSum += BP[
I];
485 if (OldReachableSum != NewReachableSum) {
486 if (OldReachableSum.
isZero()) {
491 for (
auto I : ReachableIdxs)
494 for (
auto I : ReachableIdxs) {
500 BP[
I].getNumerator();
515bool BranchProbabilityInfo::calcPointerHeuristics(
const BasicBlock *BB) {
572 if (!CI || !isa<Instruction>(CI->
getOperand(0)) ||
580 PHINode *CmpPHI = dyn_cast<PHINode>(CmpLHS);
584 while (!CmpPHI && CmpLHS && isa<BinaryOperator>(CmpLHS) &&
587 if (!L->contains(CmpLHS))
589 InstChain.
push_back(cast<BinaryOperator>(CmpLHS));
590 CmpLHS = dyn_cast<Instruction>(CmpLHS->
getOperand(0));
592 CmpPHI = dyn_cast<PHINode>(CmpLHS);
594 if (!CmpPHI || !L->contains(CmpPHI))
601 VisitedInsts.
insert(CmpPHI);
602 while (!WorkList.
empty()) {
608 Value *V =
P->getIncomingValueForBlock(
B);
611 if (
PHINode *PN = dyn_cast<PHINode>(V)) {
612 if (VisitedInsts.
insert(PN).second)
619 Constant *CmpLHSConst = dyn_cast<Constant>(V);
626 I->getOpcode(), CmpLHSConst, cast<Constant>(
I->getOperand(1)),
DL);
645std::optional<uint32_t>
646BranchProbabilityInfo::getEstimatedBlockWeight(
const BasicBlock *BB)
const {
647 auto WeightIt = EstimatedBlockWeight.find(BB);
648 if (WeightIt == EstimatedBlockWeight.end())
650 return WeightIt->second;
653std::optional<uint32_t>
654BranchProbabilityInfo::getEstimatedLoopWeight(
const LoopData &L)
const {
655 auto WeightIt = EstimatedLoopWeight.
find(L);
656 if (WeightIt == EstimatedLoopWeight.
end())
658 return WeightIt->second;
661std::optional<uint32_t>
662BranchProbabilityInfo::getEstimatedEdgeWeight(
const LoopEdge &Edge)
const {
665 return isLoopEnteringEdge(Edge)
666 ? getEstimatedLoopWeight(Edge.second.getLoopData())
667 : getEstimatedBlockWeight(Edge.second.getBlock());
670template <
class IterT>
671std::optional<uint32_t> BranchProbabilityInfo::getMaxEstimatedEdgeWeight(
674 std::optional<uint32_t> MaxWeight;
676 const LoopBlock DstLoopBB = getLoopBlock(DstBB);
677 auto Weight = getEstimatedEdgeWeight({SrcLoopBB, DstLoopBB});
682 if (!MaxWeight || *MaxWeight < *Weight)
694bool BranchProbabilityInfo::updateEstimatedBlockWeight(
695 LoopBlock &LoopBB,
uint32_t BBWeight,
705 if (!EstimatedBlockWeight.insert({BB, BBWeight}).second)
709 LoopBlock PredLoop = getLoopBlock(PredBlock);
711 if (isLoopExitingEdge({PredLoop, LoopBB})) {
712 if (!EstimatedLoopWeight.
count(PredLoop.getLoopData()))
714 }
else if (!EstimatedBlockWeight.count(PredBlock))
732void BranchProbabilityInfo::propagateEstimatedBlockWeight(
737 const auto *DTStartNode = DT->
getNode(BB);
738 const auto *PDTStartNode = PDT->
getNode(BB);
741 for (
const auto *DTNode = DTStartNode; DTNode !=
nullptr;
742 DTNode = DTNode->getIDom()) {
743 auto *DomBB = DTNode->getBlock();
750 LoopBlock DomLoopBB = getLoopBlock(DomBB);
751 const LoopEdge Edge{DomLoopBB, LoopBB};
753 if (!isLoopEnteringExitingEdge(Edge)) {
754 if (!updateEstimatedBlockWeight(DomLoopBB, BBWeight, BlockWorkList,
759 }
else if (isLoopExitingEdge(Edge)) {
765std::optional<uint32_t>
766BranchProbabilityInfo::getInitialEstimatedBlockWeight(
const BasicBlock *BB) {
768 auto hasNoReturn = [&](
const BasicBlock *BB) {
770 if (
const CallInst *CI = dyn_cast<CallInst>(&
I))
771 if (CI->hasFnAttr(Attribute::NoReturn))
786 return hasNoReturn(BB)
787 ?
static_cast<uint32_t>(BlockExecWeight::NORETURN)
788 :
static_cast<uint32_t>(BlockExecWeight::UNREACHABLE);
792 return static_cast<uint32_t>(BlockExecWeight::UNWIND);
795 for (
const auto &
I : *BB)
796 if (
const CallInst *CI = dyn_cast<CallInst>(&
I))
797 if (CI->hasFnAttr(Attribute::Cold))
798 return static_cast<uint32_t>(BlockExecWeight::COLD);
806void BranchProbabilityInfo::computeEestimateBlockWeight(
815 for (
const auto *BB : RPOT)
816 if (
auto BBWeight = getInitialEstimatedBlockWeight(BB))
819 propagateEstimatedBlockWeight(getLoopBlock(BB), DT, PDT, *BBWeight,
820 BlockWorkList, LoopWorkList);
827 while (!LoopWorkList.
empty()) {
829 const LoopData
LD = LoopBB.getLoopData();
830 if (EstimatedLoopWeight.
count(LD))
836 getLoopExitBlocks(LoopBB, Exits);
837 auto LoopWeight = getMaxEstimatedEdgeWeight(
842 if (LoopWeight <=
static_cast<uint32_t>(BlockExecWeight::UNREACHABLE))
843 LoopWeight =
static_cast<uint32_t>(BlockExecWeight::LOWEST_NON_ZERO);
845 EstimatedLoopWeight.
insert({
LD, *LoopWeight});
847 getLoopEnterBlocks(LoopBB, BlockWorkList);
851 while (!BlockWorkList.
empty()) {
854 if (EstimatedBlockWeight.count(BB))
863 const LoopBlock LoopBB = getLoopBlock(BB);
864 auto MaxWeight = getMaxEstimatedEdgeWeight(LoopBB,
successors(BB));
867 propagateEstimatedBlockWeight(LoopBB, DT, PDT, *MaxWeight,
868 BlockWorkList, LoopWorkList);
870 }
while (!BlockWorkList.
empty() || !LoopWorkList.
empty());
876bool BranchProbabilityInfo::calcEstimatedHeuristics(
const BasicBlock *BB) {
878 "expected more than one successor!");
880 const LoopBlock LoopBB = getLoopBlock(BB);
884 if (LoopBB.getLoop())
888 bool FoundEstimatedWeight =
false;
893 std::optional<uint32_t> Weight;
894 const LoopBlock SuccLoopBB = getLoopBlock(SuccBB);
895 const LoopEdge Edge{LoopBB, SuccLoopBB};
897 Weight = getEstimatedEdgeWeight(Edge);
899 if (isLoopExitingEdge(Edge) &&
901 Weight !=
static_cast<uint32_t>(BlockExecWeight::ZERO)) {
904 static_cast<uint32_t>(BlockExecWeight::LOWEST_NON_ZERO),
905 Weight.value_or(
static_cast<uint32_t>(BlockExecWeight::DEFAULT)) /
908 bool IsUnlikelyEdge = LoopBB.getLoop() && UnlikelyBlocks.
contains(SuccBB);
909 if (IsUnlikelyEdge &&
911 Weight !=
static_cast<uint32_t>(BlockExecWeight::ZERO)) {
914 static_cast<uint32_t>(BlockExecWeight::LOWEST_NON_ZERO),
915 Weight.value_or(
static_cast<uint32_t>(BlockExecWeight::DEFAULT)) / 2);
919 FoundEstimatedWeight =
true;
922 Weight.value_or(
static_cast<uint32_t>(BlockExecWeight::DEFAULT));
923 TotalWeight += WeightVal;
930 if (!FoundEstimatedWeight || TotalWeight == 0)
934 const unsigned SuccCount = SuccWeights.
size();
938 if (TotalWeight > UINT32_MAX) {
939 uint64_t ScalingFactor = TotalWeight / UINT32_MAX + 1;
941 for (
unsigned Idx = 0;
Idx < SuccCount; ++
Idx) {
942 SuccWeights[
Idx] /= ScalingFactor;
943 if (SuccWeights[
Idx] ==
static_cast<uint32_t>(BlockExecWeight::ZERO))
945 static_cast<uint32_t>(BlockExecWeight::LOWEST_NON_ZERO);
946 TotalWeight += SuccWeights[
Idx];
948 assert(TotalWeight <= UINT32_MAX &&
"Total weight overflows");
955 for (
unsigned Idx = 0;
Idx < SuccCount; ++
Idx) {
956 EdgeProbabilities[
Idx] =
963bool BranchProbabilityInfo::calcZeroHeuristics(
const BasicBlock *BB,
974 auto GetConstantInt = [](
Value *
V) {
975 if (
auto *
I = dyn_cast<BitCastInst>(V))
976 return dyn_cast<ConstantInt>(
I->getOperand(0));
977 return dyn_cast<ConstantInt>(V);
988 if (
LHS->getOpcode() == Instruction::And)
990 if (AndRHS->getValue().isPowerOf2())
1000 ProbabilityTable::const_iterator Search;
1001 if (Func == LibFunc_strcasecmp ||
1002 Func == LibFunc_strcmp ||
1003 Func == LibFunc_strncasecmp ||
1004 Func == LibFunc_strncmp ||
1005 Func == LibFunc_memcmp ||
1006 Func == LibFunc_bcmp) {
1010 }
else if (CV->
isZero()) {
1014 }
else if (CV->
isOne()) {
1030bool BranchProbabilityInfo::calcFloatingPointHeuristics(
const BasicBlock *BB) {
1051 ProbList = Search->second;
1073 OS <<
"---- Branch Probabilities ----\n";
1076 assert(LastF &&
"Cannot print prior to running over a function");
1077 for (
const auto &BI : *LastF) {
1096 unsigned IndexInSuccessors)
const {
1097 auto I = Probs.find(std::make_pair(Src, IndexInSuccessors));
1098 assert((Probs.end() == Probs.find(std::make_pair(Src, 0))) ==
1099 (Probs.end() ==
I) &&
1100 "Probability for I-th successor must always be defined along with the "
1101 "probability for the first successor");
1103 if (
I != Probs.end())
1120 if (!Probs.count(std::make_pair(Src, 0)))
1126 Prob += Probs.find(std::make_pair(Src,
I.getSuccessorIndex()))->second;
1134 assert(Src->getTerminator()->getNumSuccessors() == Probs.
size());
1136 if (Probs.
size() == 0)
1139 Handles.insert(BasicBlockCallbackVH(Src,
this));
1141 for (
unsigned SuccIdx = 0; SuccIdx < Probs.
size(); ++SuccIdx) {
1142 this->Probs[std::make_pair(Src, SuccIdx)] = Probs[SuccIdx];
1143 LLVM_DEBUG(
dbgs() <<
"set edge " << Src->getName() <<
" -> " << SuccIdx
1144 <<
" successor probability to " << Probs[SuccIdx]
1146 TotalNumerator += Probs[SuccIdx].getNumerator();
1156 (void)TotalNumerator;
1162 unsigned NumSuccessors = Src->getTerminator()->getNumSuccessors();
1163 assert(NumSuccessors == Dst->getTerminator()->getNumSuccessors());
1164 if (NumSuccessors == 0)
1166 if (!this->Probs.contains(std::make_pair(Src, 0)))
1169 Handles.insert(BasicBlockCallbackVH(Dst,
this));
1170 for (
unsigned SuccIdx = 0; SuccIdx < NumSuccessors; ++SuccIdx) {
1171 auto Prob = this->Probs[std::make_pair(Src, SuccIdx)];
1172 this->Probs[std::make_pair(Dst, SuccIdx)] = Prob;
1173 LLVM_DEBUG(
dbgs() <<
"set edge " << Dst->getName() <<
" -> " << SuccIdx
1174 <<
" successor probability to " << Prob <<
"\n");
1179 assert(Src->getTerminator()->getNumSuccessors() == 2);
1180 if (!Probs.contains(std::make_pair(Src, 0)))
1182 assert(Probs.contains(std::make_pair(Src, 1)));
1183 std::swap(Probs[std::make_pair(Src, 0)], Probs[std::make_pair(Src, 1)]);
1192 Src->printAsOperand(
OS,
false, Src->getModule());
1194 Dst->printAsOperand(
OS,
false, Dst->getModule());
1195 OS <<
" probability is " << Prob
1196 << (
isEdgeHot(Src, Dst) ?
" [HOT edge]\n" :
"\n");
1211 Handles.erase(BasicBlockCallbackVH(BB,
this));
1212 for (
unsigned I = 0;; ++
I) {
1213 auto MapI = Probs.find(std::make_pair(BB,
I));
1214 if (MapI == Probs.end()) {
1215 assert(Probs.count(std::make_pair(BB,
I + 1)) == 0 &&
1216 "Must be no more successors");
1232 SccI = std::make_unique<SccInfo>(
F);
1234 assert(EstimatedBlockWeight.empty());
1237 std::unique_ptr<DominatorTree> DTPtr;
1238 std::unique_ptr<PostDominatorTree> PDTPtr;
1241 DTPtr = std::make_unique<DominatorTree>(
const_cast<Function &
>(
F));
1246 PDTPtr = std::make_unique<PostDominatorTree>(
const_cast<Function &
>(
F));
1250 computeEestimateBlockWeight(
F, DT, PDT);
1254 for (
const auto *BB :
post_order(&
F.getEntryBlock())) {
1260 if (calcMetadataWeights(BB))
1262 if (calcEstimatedHeuristics(BB))
1264 if (calcPointerHeuristics(BB))
1266 if (calcZeroHeuristics(BB, TLI))
1268 if (calcFloatingPointHeuristics(BB))
1272 EstimatedLoopWeight.
clear();
1273 EstimatedBlockWeight.clear();
1296 const LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
1298 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
1299 DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
1301 getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();
1302 BPI.calculate(
F, LI, &TLI, &DT, &PDT);
1327 OS <<
"Printing analysis 'Branch Probability Analysis' for function '"
1328 <<
F.getName() <<
"':\n";
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)
branch Branch Probability Analysis
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...
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< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
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 ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
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.
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
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.
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...
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.
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...
SccInfo(const Function &F)
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...
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.
void eraseBlock(const BasicBlock *BB)
Forget analysis results for the given basic block.
void setEdgeProbability(const BasicBlock *Src, const SmallVectorImpl< BranchProbability > &Probs)
Set the raw probabilities for all edges from the given block.
bool invalidate(Function &, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &)
BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
void calculate(const Function &F, const LoopInfo &LI, const TargetLibraryInfo *TLI, DominatorTree *DT, PostDominatorTree *PDT)
bool isEdgeHot(const BasicBlock *Src, const BasicBlock *Dst) const
Test if an edge is hot relative to other out-edges of the Src.
void swapSuccEdgesProbabilities(const BasicBlock *Src)
Swap outgoing edges probabilities for Src with branch terminator.
void print(raw_ostream &OS) const
raw_ostream & printEdgeProbability(raw_ostream &OS, const BasicBlock *Src, const BasicBlock *Dst) const
Print an edge's probability.
void copyEdgeProbabilities(BasicBlock *Src, BasicBlock *Dst)
Copy outgoing edge probabilities from Src to Dst.
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.
This class represents a function call, abstracting a target machine's calling convention.
This class is the base class for the comparison instructions.
@ 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.
This is the shared class of boolean and integer constants.
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.
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
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.
This instruction compares its operands according to the predicate given to the constructor.
static bool isEquality(Predicate Pred)
FunctionPass class - This class is used to implement most global optimizations.
This instruction compares its operands according to the predicate given to the constructor.
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
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.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Analysis pass which computes a PostDominatorTree.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
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.
StringRef getName() const
Return a constant reference to the value's name.
A range adaptor for a pair of iterators.
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.
BlockType
Used as immediate MachineOperands for block signatures.
initializer< Ty > init(const Ty &Val)
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
pred_iterator pred_end(BasicBlock *BB)
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.
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)
void initializeBranchProbabilityInfoWrapperPassPass(PassRegistry &)
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.
pred_iterator pred_begin(BasicBlock *BB)
auto reverse(ContainerTy &&C)
MDNode * getValidBranchWeightMDNode(const Instruction &I)
Get the valid branch weights metadata node.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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)
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...
bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
unsigned succ_size(const MachineBasicBlock *BB)
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...