50#define DEBUG_TYPE "branch-prob"
53 "Branch Probability Analysis",
false,
true)
155class BPIConstruction {
157 BPIConstruction(BranchProbabilityInfo &BPI) : BPI(BPI) {}
158 void calculate(
const Function &
F,
const CycleInfo &CI,
159 const TargetLibraryInfo *
TLI, DominatorTree *DT,
160 PostDominatorTree *PDT);
164 using LoopEdge = std::pair<const BasicBlock *, const BasicBlock *>;
169 bool isLoopEnteringEdge(
const LoopEdge &
Edge)
const;
173 bool isLoopExitingEdge(
const LoopEdge &
Edge)
const;
176 bool isLoopEnteringExitingEdge(
const LoopEdge &
Edge)
const;
179 SmallVectorImpl<const BasicBlock *> &Enters)
const;
183 std::optional<uint32_t> getEstimatedBlockWeight(
const BasicBlock *BB)
const;
188 std::optional<uint32_t> getEstimatedLoopWeight(CycleRef
C)
const;
192 std::optional<uint32_t> getEstimatedEdgeWeight(
const LoopEdge &
Edge)
const;
197 template <
class IterT>
198 std::optional<uint32_t>
199 getMaxEstimatedEdgeWeight(
const BasicBlock *SrcBB,
207 updateEstimatedBlockWeight(
const BasicBlock *BB, uint32_t BBWeight,
208 SmallVectorImpl<const BasicBlock *> &BlockWorkList,
209 SmallVectorImpl<const BasicBlock *> &LoopWorkList);
213 void propagateEstimatedBlockWeight(
214 const BasicBlock *BB, DominatorTree *DT, PostDominatorTree *PDT,
215 uint32_t BBWeight, SmallVectorImpl<const BasicBlock *> &WorkList,
216 SmallVectorImpl<const BasicBlock *> &LoopWorkList);
219 std::optional<uint32_t> getInitialEstimatedBlockWeight(
const BasicBlock *BB);
222 void estimateBlockWeights(
const Function &
F, DominatorTree *DT,
223 PostDominatorTree *PDT);
227 bool calcEstimatedHeuristics(
const BasicBlock *BB);
228 bool calcMetadataWeights(
const BasicBlock *BB);
229 bool calcPointerHeuristics(
const BasicBlock *BB);
230 bool calcZeroHeuristics(
const BasicBlock *BB,
const TargetLibraryInfo *
TLI);
231 bool calcFloatingPointHeuristics(
const BasicBlock *BB);
233 BranchProbabilityInfo &BPI;
235 const CycleInfo *CI =
nullptr;
238 SmallDenseMap<const BasicBlock *, uint32_t> EstimatedBlockWeight;
241 SmallDenseMap<CycleRef, uint32_t> EstimatedLoopWeight;
244bool BPIConstruction::isLoopEnteringEdge(
const LoopEdge &Edge)
const {
251 return !CI->
contains(DstCycle, SrcCycle);
254bool BPIConstruction::isLoopExitingEdge(
const LoopEdge &
Edge)
const {
255 return isLoopEnteringEdge({
Edge.second,
Edge.first});
258bool BPIConstruction::isLoopEnteringExitingEdge(
const LoopEdge &
Edge)
const {
259 return isLoopEnteringEdge(
Edge) || isLoopExitingEdge(
Edge);
262void BPIConstruction::getLoopEnterBlocks(
263 const BasicBlock *BB, SmallVectorImpl<const BasicBlock *> &Enters)
const {
275bool BPIConstruction::calcMetadataWeights(
const BasicBlock *BB) {
290 SmallVector<unsigned, 2> UnreachableIdxs;
291 SmallVector<unsigned, 2> ReachableIdxs;
295 for (
unsigned I = 0,
E = Weights.
size();
I !=
E; ++
I) {
296 auto EstimatedWeight = getEstimatedEdgeWeight({BB, *Succs++});
297 if (EstimatedWeight &&
306 if (ReachableIdxs.
empty())
315 if (UnreachableIdxs.
size() == 0 || ReachableIdxs.
size() == 0) {
321 for (
auto I : UnreachableIdxs)
322 if (UnreachableProb < BP[
I]) {
323 BP[
I] = UnreachableProb;
347 for (
auto I : UnreachableIdxs)
348 NewUnreachableSum += BP[
I];
350 BranchProbability NewReachableSum =
354 for (
auto I : ReachableIdxs)
355 OldReachableSum += BP[
I];
357 if (OldReachableSum != NewReachableSum) {
358 if (OldReachableSum.
isZero()) {
362 BranchProbability PerEdge = NewReachableSum / ReachableIdxs.size();
363 for (
auto I : ReachableIdxs)
366 for (
auto I : ReachableIdxs) {
372 BP[
I].getNumerator();
373 uint32_t
Div =
static_cast<uint32_t
>(
387bool BPIConstruction::calcPointerHeuristics(
const BasicBlock *BB) {
405 case ICmpInst::ICMP_NE:
408 case ICmpInst::ICMP_EQ:
420computeUnlikelySuccessors(
const BasicBlock *BB,
const CycleInfo &CI, CycleRef
C,
421 SmallPtrSetImpl<const BasicBlock *> &UnlikelyBlocks) {
475 SmallPtrSet<PHINode*, 8> VisitedInsts;
478 VisitedInsts.
insert(CmpPHI);
479 while (!WorkList.
empty()) {
481 for (BasicBlock *
B :
P->blocks()) {
485 Value *
V =
P->getIncomingValueForBlock(
B);
489 if (VisitedInsts.
insert(PN).second)
522std::optional<uint32_t>
523BPIConstruction::getEstimatedBlockWeight(
const BasicBlock *BB)
const {
524 auto WeightIt = EstimatedBlockWeight.find(BB);
525 if (WeightIt == EstimatedBlockWeight.end())
527 return WeightIt->second;
530std::optional<uint32_t>
531BPIConstruction::getEstimatedLoopWeight(CycleRef
C)
const {
532 auto WeightIt = EstimatedLoopWeight.find(
C);
533 if (WeightIt == EstimatedLoopWeight.end())
535 return WeightIt->second;
538std::optional<uint32_t>
539BPIConstruction::getEstimatedEdgeWeight(
const LoopEdge &
Edge)
const {
542 return isLoopEnteringEdge(
Edge)
544 : getEstimatedBlockWeight(
Edge.second);
547template <
class IterT>
548std::optional<uint32_t> BPIConstruction::getMaxEstimatedEdgeWeight(
550 std::optional<uint32_t> MaxWeight;
551 for (
const BasicBlock *DstBB : Successors) {
552 auto Weight = getEstimatedEdgeWeight({SrcBB, DstBB});
555 if (!MaxWeight || *MaxWeight < *Weight)
567bool BPIConstruction::updateEstimatedBlockWeight(
568 const BasicBlock *BB, uint32_t BBWeight,
569 SmallVectorImpl<const BasicBlock *> &BlockWorkList,
570 SmallVectorImpl<const BasicBlock *> &LoopWorkList) {
576 if (!EstimatedBlockWeight.insert({BB, BBWeight}).second)
581 if (isLoopExitingEdge({PredBlock, BB})) {
582 if (!EstimatedLoopWeight.count(CI->
getCycle(PredBlock)))
584 }
else if (!EstimatedBlockWeight.count(PredBlock))
602void BPIConstruction::propagateEstimatedBlockWeight(
603 const BasicBlock *BB, DominatorTree *DT, PostDominatorTree *PDT,
604 uint32_t BBWeight, SmallVectorImpl<const BasicBlock *> &BlockWorkList,
605 SmallVectorImpl<const BasicBlock *> &LoopWorkList) {
606 const auto *DTStartNode = DT->
getNode(BB);
607 const auto *PDTStartNode = PDT->
getNode(BB);
610 for (
const auto *DTNode = DTStartNode; DTNode !=
nullptr;
611 DTNode = DTNode->getIDom()) {
612 auto *DomBB = DTNode->getBlock();
619 const LoopEdge
Edge{DomBB, BB};
621 if (!isLoopEnteringExitingEdge(
Edge)) {
622 if (!updateEstimatedBlockWeight(DomBB, BBWeight, BlockWorkList,
627 }
else if (isLoopExitingEdge(
Edge)) {
633std::optional<uint32_t>
634BPIConstruction::getInitialEstimatedBlockWeight(
const BasicBlock *BB) {
636 auto hasNoReturn = [&](
const BasicBlock *BB) {
639 if (CI->hasFnAttr(Attribute::NoReturn))
654 return hasNoReturn(BB)
663 for (
const auto &
I : *BB)
665 if (CI->hasFnAttr(Attribute::Cold))
674void BPIConstruction::estimateBlockWeights(
const Function &
F, DominatorTree *DT,
675 PostDominatorTree *PDT) {
676 SmallVector<const BasicBlock *, 8> BlockWorkList;
677 SmallVector<const BasicBlock *, 8> LoopWorkList;
678 SmallDenseMap<CycleRef, SmallVector<BasicBlock *, 4>> LoopExitBlocks;
682 ReversePostOrderTraversal<const Function *> RPOT(&
F);
683 for (
const auto *BB : RPOT)
684 if (
auto BBWeight = getInitialEstimatedBlockWeight(BB))
687 propagateEstimatedBlockWeight(BB, DT, PDT, *BBWeight, BlockWorkList,
695 while (!LoopWorkList.
empty()) {
698 if (EstimatedLoopWeight.count(
C))
702 SmallVectorImpl<BasicBlock *> &Exits = Res.first->second;
705 auto LoopWeight = getMaxEstimatedEdgeWeight(
713 EstimatedLoopWeight.insert({
C, *LoopWeight});
715 getLoopEnterBlocks(LoopBB, BlockWorkList);
719 while (!BlockWorkList.
empty()) {
722 if (EstimatedBlockWeight.count(BB))
731 auto MaxWeight = getMaxEstimatedEdgeWeight(BB,
successors(BB));
734 propagateEstimatedBlockWeight(BB, DT, PDT, *MaxWeight, BlockWorkList,
737 }
while (!BlockWorkList.
empty() || !LoopWorkList.
empty());
743bool BPIConstruction::calcEstimatedHeuristics(
const BasicBlock *BB) {
745 "expected more than one successor!");
747 CycleRef BBCycle = CI->
getCycle(BB);
749 SmallPtrSet<const BasicBlock *, 8> UnlikelyBlocks;
752 computeUnlikelySuccessors(BB, *CI, BBCycle, UnlikelyBlocks);
755 bool FoundEstimatedWeight =
false;
756 SmallVector<uint32_t, 4> SuccWeights;
759 for (
const BasicBlock *SuccBB :
successors(BB)) {
760 std::optional<uint32_t> Weight;
761 const LoopEdge
Edge{BB, SuccBB};
763 Weight = getEstimatedEdgeWeight(
Edge);
765 if (isLoopExitingEdge(
Edge) &&
774 bool IsUnlikelyEdge = BBCycle && UnlikelyBlocks.
contains(SuccBB);
775 if (IsUnlikelyEdge &&
785 FoundEstimatedWeight =
true;
789 TotalWeight += WeightVal;
796 if (!FoundEstimatedWeight || TotalWeight == 0)
800 const unsigned SuccCount = SuccWeights.
size();
804 if (TotalWeight > UINT32_MAX) {
805 uint64_t ScalingFactor = TotalWeight / UINT32_MAX + 1;
807 for (
unsigned Idx = 0;
Idx < SuccCount; ++
Idx) {
808 SuccWeights[
Idx] /= ScalingFactor;
812 TotalWeight += SuccWeights[
Idx];
814 assert(TotalWeight <= UINT32_MAX &&
"Total weight overflows");
821 for (
unsigned Idx = 0;
Idx < SuccCount; ++
Idx) {
822 EdgeProbabilities[
Idx] =
823 BranchProbability(SuccWeights[Idx], (uint32_t)TotalWeight);
829bool BPIConstruction::calcZeroHeuristics(
const BasicBlock *BB,
830 const TargetLibraryInfo *
TLI) {
840 auto GetConstantInt = [](
Value *
V) {
847 ConstantInt *CV = GetConstantInt(
RHS);
854 if (
LHS->getOpcode() == Instruction::And)
855 if (ConstantInt *AndRHS = GetConstantInt(
LHS->getOperand(1)))
856 if (AndRHS->getValue().isPowerOf2())
860 LibFunc
Func = LibFunc::NotLibFunc;
864 Func =
TLI->getLibFunc(*CalledFn);
867 if (Func == LibFunc_strcasecmp ||
868 Func == LibFunc_strcmp ||
869 Func == LibFunc_strncasecmp ||
870 Func == LibFunc_strncmp ||
871 Func == LibFunc_memcmp ||
872 Func == LibFunc_bcmp) {
884 default:
return false;
887 }
else if (CV->
isZero()) {
894 default:
return false;
897 }
else if (CV->
isOne()) {
901 default:
return false;
911 default:
return false;
925bool BPIConstruction::calcFloatingPointHeuristics(
const BasicBlock *BB) {
940 }
else if (FCmp->
getPredicate() == FCmpInst::FCMP_ORD) {
943 }
else if (FCmp->
getPredicate() == FCmpInst::FCMP_UNO) {
951void BPIConstruction::calculate(
const Function &
F,
const CycleInfo &CycleI,
952 const TargetLibraryInfo *
TLI, DominatorTree *DT,
953 PostDominatorTree *PDT) {
956 std::unique_ptr<DominatorTree> DTPtr;
957 std::unique_ptr<PostDominatorTree> PDTPtr;
960 DTPtr = std::make_unique<DominatorTree>(
const_cast<Function &
>(
F));
965 PDTPtr = std::make_unique<PostDominatorTree>(
const_cast<Function &
>(
F));
969 estimateBlockWeights(
F, DT, PDT);
973 for (
const auto *BB :
post_order(&
F.getEntryBlock())) {
979 if (calcMetadataWeights(BB))
981 if (calcEstimatedHeuristics(BB))
983 if (calcPointerHeuristics(BB))
985 if (calcZeroHeuristics(BB,
TLI))
987 if (calcFloatingPointHeuristics(BB))
995BranchProbabilityInfo::allocEdges(
const BasicBlock *BB) {
997 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1003 if (EdgeStarts.size() <= BB->
getNumber())
1004 EdgeStarts.resize(LastF->getMaxBlockNumber(), 0);
1005 unsigned EdgeStart = Probs.size();
1006 EdgeStarts[BB->
getNumber()] = EdgeStart + 1;
1007 Probs.append(NumSuccs, {});
1012BranchProbabilityInfo::getEdges(
const BasicBlock *BB)
const {
1014 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1015 if (EdgeStarts.size() <= BB->
getNumber())
1017 if (
unsigned EdgeStart = EdgeStarts[BB->
getNumber()]) {
1018 const BranchProbability *
Start = &Probs[EdgeStart - 1];
1019 size_t Count = SIZE_MAX;
1029 FunctionAnalysisManager::Invalidator &) {
1038 OS <<
"---- Branch Probabilities ----\n";
1041 assert(LastF &&
"Cannot print prior to running over a function");
1042 for (
const auto &BI : *LastF) {
1061 unsigned IndexInSuccessors)
const {
1063 return P[IndexInSuccessors];
1078 if (It.value() == Dst)
1079 Prob +=
P[It.index()];
1091 if (WeightSum > UINT32_MAX) {
1092 uint64_t ScalingFactor = WeightSum / UINT32_MAX + 1;
1093 for (
uint32_t &Weight : ScaledWeights)
1094 Weight /= ScalingFactor;
1098 assert(WeightSum <= UINT32_MAX &&
1099 "Expected weights to scale down to 32 bits");
1101 if (WeightSum == 0) {
1102 fill(ScaledWeights, 1);
1103 WeightSum = ScaledWeights.
size();
1114 assert(Src->getTerminator()->getNumSuccessors() == Probs.size());
1116 uint64_t TotalNumerator = 0;
1117 for (
unsigned SuccIdx = 0; SuccIdx < Probs.size(); ++SuccIdx) {
1118 P[SuccIdx] = Probs[SuccIdx];
1119 LLVM_DEBUG(
dbgs() <<
"set edge " << Src->getName() <<
" -> " << SuccIdx
1120 <<
" successor probability to " << Probs[SuccIdx]
1122 TotalNumerator += Probs[SuccIdx].getNumerator();
1134 (void)TotalNumerator;
1148 for (
unsigned i = 0; i != DstP.
size(); ++i) {
1150 LLVM_DEBUG(
dbgs() <<
"set edge " << Dst->getName() <<
" -> " << i
1151 <<
" successor probability to " << SrcP[i] <<
"\n");
1156 assert(Src->getTerminator()->getNumSuccessors() == 2);
1171 Src->printAsOperand(OS,
false, Src->getModule());
1173 Dst->printAsOperand(OS,
false, Dst->getModule());
1174 OS <<
" probability is " << Prob
1175 << (
isEdgeHot(Src, Dst) ?
" [HOT edge]\n" :
"\n");
1183 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1184 if (EdgeStarts.size() > BB->
getNumber())
1196 BlockNumberEpoch =
F.getBlockNumberEpoch();
1199 BPIConstruction(*this).calculate(
F, CycleI,
TLI, DT, PDT);
1202 if (Opts.print_bpi && (Opts.print_bpi_func_name.empty() ||
1203 F.getName() == Opts.print_bpi_func_name)) {
1228 BPI.calculate(
F, CI, &
TLI, &DT, &PDT);
1251 OS <<
"Printing analysis 'Branch Probability Analysis' for function '"
1252 <<
F.getName() <<
"':\n";
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
const TargetLowering & TLI
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 constexpr BranchProbability FPOrdTakenProb(FPH_ORD_WEIGHT, FPH_ORD_WEIGHT+FPH_UNO_WEIGHT)
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.
SmallVector< MachineOperand, 4 > Cond
static void eraseBlock(MachineBasicBlock *MBB, LiveIntervals &LIS, MachineDomTreeUpdater &MDTU)
#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.
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.
static LLVM_ABI SmallVector< BranchProbability > getEdgeProbabilitiesFromWeights(ArrayRef< uint32_t > Weights)
Returns the probabilities of edges with branch weights Weights.
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)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
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 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.
NodeAddr< FuncNode * > Func
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
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)
auto map_to_vector(ContainerTy &&C, FuncTy &&F)
Map a range to a SmallVector with element types deduced from the mapping.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
constexpr T divideNearest(U Numerator, V Denominator)
Returns (Numerator / Denominator) rounded by round-half-up.
const AnalysisOptions & getAnalysisOptions(const LLVMContext &C)
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...
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 >
auto sum_of(R &&Range, E Init=E{0})
Returns the sum of all values in Range with Init initial value.
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.
LLVM_ABI Constant * ConstantFoldInstOperands(const Instruction *I, ArrayRef< Constant * > Ops, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, bool AllowNonDeterministic=true)
ConstantFoldInstOperands - Attempt to constant fold an instruction with the specified operands.
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...