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)
511 Cmp->getPredicate(), CmpLHSConst, CmpConst,
DL);
521std::optional<uint32_t>
522BPIConstruction::getEstimatedBlockWeight(
const BasicBlock *BB)
const {
523 auto WeightIt = EstimatedBlockWeight.find(BB);
524 if (WeightIt == EstimatedBlockWeight.end())
526 return WeightIt->second;
529std::optional<uint32_t>
530BPIConstruction::getEstimatedLoopWeight(CycleRef
C)
const {
531 auto WeightIt = EstimatedLoopWeight.find(
C);
532 if (WeightIt == EstimatedLoopWeight.end())
534 return WeightIt->second;
537std::optional<uint32_t>
538BPIConstruction::getEstimatedEdgeWeight(
const LoopEdge &
Edge)
const {
541 return isLoopEnteringEdge(
Edge)
543 : getEstimatedBlockWeight(
Edge.second);
546template <
class IterT>
547std::optional<uint32_t> BPIConstruction::getMaxEstimatedEdgeWeight(
549 std::optional<uint32_t> MaxWeight;
550 for (
const BasicBlock *DstBB : Successors) {
551 auto Weight = getEstimatedEdgeWeight({SrcBB, DstBB});
554 if (!MaxWeight || *MaxWeight < *Weight)
566bool BPIConstruction::updateEstimatedBlockWeight(
567 const BasicBlock *BB, uint32_t BBWeight,
568 SmallVectorImpl<const BasicBlock *> &BlockWorkList,
569 SmallVectorImpl<const BasicBlock *> &LoopWorkList) {
575 if (!EstimatedBlockWeight.insert({BB, BBWeight}).second)
580 if (isLoopExitingEdge({PredBlock, BB})) {
581 if (!EstimatedLoopWeight.count(CI->
getCycle(PredBlock)))
583 }
else if (!EstimatedBlockWeight.count(PredBlock))
601void BPIConstruction::propagateEstimatedBlockWeight(
602 const BasicBlock *BB, DominatorTree *DT, PostDominatorTree *PDT,
603 uint32_t BBWeight, SmallVectorImpl<const BasicBlock *> &BlockWorkList,
604 SmallVectorImpl<const BasicBlock *> &LoopWorkList) {
605 const auto *DTStartNode = DT->
getNode(BB);
606 const auto *PDTStartNode = PDT->
getNode(BB);
609 for (
const auto *DTNode = DTStartNode; DTNode !=
nullptr;
610 DTNode = DTNode->getIDom()) {
611 auto *DomBB = DTNode->getBlock();
618 const LoopEdge
Edge{DomBB, BB};
620 if (!isLoopEnteringExitingEdge(
Edge)) {
621 if (!updateEstimatedBlockWeight(DomBB, BBWeight, BlockWorkList,
626 }
else if (isLoopExitingEdge(
Edge)) {
632std::optional<uint32_t>
633BPIConstruction::getInitialEstimatedBlockWeight(
const BasicBlock *BB) {
635 auto hasNoReturn = [&](
const BasicBlock *BB) {
638 if (CI->hasFnAttr(Attribute::NoReturn))
653 return hasNoReturn(BB)
662 for (
const auto &
I : *BB)
664 if (CI->hasFnAttr(Attribute::Cold))
673void BPIConstruction::estimateBlockWeights(
const Function &
F, DominatorTree *DT,
674 PostDominatorTree *PDT) {
675 SmallVector<const BasicBlock *, 8> BlockWorkList;
676 SmallVector<const BasicBlock *, 8> LoopWorkList;
677 SmallDenseMap<CycleRef, SmallVector<BasicBlock *, 4>> LoopExitBlocks;
681 ReversePostOrderTraversal<const Function *> RPOT(&
F);
682 for (
const auto *BB : RPOT)
683 if (
auto BBWeight = getInitialEstimatedBlockWeight(BB))
686 propagateEstimatedBlockWeight(BB, DT, PDT, *BBWeight, BlockWorkList,
694 while (!LoopWorkList.
empty()) {
697 if (EstimatedLoopWeight.count(
C))
701 SmallVectorImpl<BasicBlock *> &Exits = Res.first->second;
704 auto LoopWeight = getMaxEstimatedEdgeWeight(
712 EstimatedLoopWeight.insert({
C, *LoopWeight});
714 getLoopEnterBlocks(LoopBB, BlockWorkList);
718 while (!BlockWorkList.
empty()) {
721 if (EstimatedBlockWeight.count(BB))
730 auto MaxWeight = getMaxEstimatedEdgeWeight(BB,
successors(BB));
733 propagateEstimatedBlockWeight(BB, DT, PDT, *MaxWeight, BlockWorkList,
736 }
while (!BlockWorkList.
empty() || !LoopWorkList.
empty());
742bool BPIConstruction::calcEstimatedHeuristics(
const BasicBlock *BB) {
744 "expected more than one successor!");
746 CycleRef BBCycle = CI->
getCycle(BB);
748 SmallPtrSet<const BasicBlock *, 8> UnlikelyBlocks;
751 computeUnlikelySuccessors(BB, *CI, BBCycle, UnlikelyBlocks);
754 bool FoundEstimatedWeight =
false;
755 SmallVector<uint32_t, 4> SuccWeights;
758 for (
const BasicBlock *SuccBB :
successors(BB)) {
759 std::optional<uint32_t> Weight;
760 const LoopEdge
Edge{BB, SuccBB};
762 Weight = getEstimatedEdgeWeight(
Edge);
764 if (isLoopExitingEdge(
Edge) &&
773 bool IsUnlikelyEdge = BBCycle && UnlikelyBlocks.
contains(SuccBB);
774 if (IsUnlikelyEdge &&
784 FoundEstimatedWeight =
true;
788 TotalWeight += WeightVal;
795 if (!FoundEstimatedWeight || TotalWeight == 0)
799 const unsigned SuccCount = SuccWeights.
size();
803 if (TotalWeight > UINT32_MAX) {
804 uint64_t ScalingFactor = TotalWeight / UINT32_MAX + 1;
806 for (
unsigned Idx = 0;
Idx < SuccCount; ++
Idx) {
807 SuccWeights[
Idx] /= ScalingFactor;
811 TotalWeight += SuccWeights[
Idx];
813 assert(TotalWeight <= UINT32_MAX &&
"Total weight overflows");
820 for (
unsigned Idx = 0;
Idx < SuccCount; ++
Idx) {
821 EdgeProbabilities[
Idx] =
822 BranchProbability(SuccWeights[Idx], (uint32_t)TotalWeight);
828bool BPIConstruction::calcZeroHeuristics(
const BasicBlock *BB,
829 const TargetLibraryInfo *TLI) {
839 auto GetConstantInt = [](
Value *
V) {
846 ConstantInt *CV = GetConstantInt(
RHS);
853 if (
LHS->getOpcode() == Instruction::And)
854 if (ConstantInt *AndRHS = GetConstantInt(
LHS->getOperand(1)))
855 if (AndRHS->getValue().isPowerOf2())
859 LibFunc
Func = LibFunc::NotLibFunc;
866 if (Func == LibFunc_strcasecmp ||
867 Func == LibFunc_strcmp ||
868 Func == LibFunc_strncasecmp ||
869 Func == LibFunc_strncmp ||
870 Func == LibFunc_memcmp ||
871 Func == LibFunc_bcmp) {
883 default:
return false;
886 }
else if (CV->
isZero()) {
893 default:
return false;
896 }
else if (CV->
isOne()) {
900 default:
return false;
910 default:
return false;
924bool BPIConstruction::calcFloatingPointHeuristics(
const BasicBlock *BB) {
939 }
else if (FCmp->
getPredicate() == FCmpInst::FCMP_ORD) {
942 }
else if (FCmp->
getPredicate() == FCmpInst::FCMP_UNO) {
950void BPIConstruction::calculate(
const Function &
F,
const CycleInfo &CycleI,
951 const TargetLibraryInfo *TLI, DominatorTree *DT,
952 PostDominatorTree *PDT) {
955 std::unique_ptr<DominatorTree> DTPtr;
956 std::unique_ptr<PostDominatorTree> PDTPtr;
959 DTPtr = std::make_unique<DominatorTree>(
const_cast<Function &
>(
F));
964 PDTPtr = std::make_unique<PostDominatorTree>(
const_cast<Function &
>(
F));
968 estimateBlockWeights(
F, DT, PDT);
972 for (
const auto *BB :
post_order(&
F.getEntryBlock())) {
978 if (calcMetadataWeights(BB))
980 if (calcEstimatedHeuristics(BB))
982 if (calcPointerHeuristics(BB))
984 if (calcZeroHeuristics(BB, TLI))
986 if (calcFloatingPointHeuristics(BB))
994BranchProbabilityInfo::allocEdges(
const BasicBlock *BB) {
996 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1002 if (EdgeStarts.size() <= BB->
getNumber())
1003 EdgeStarts.resize(LastF->getMaxBlockNumber(), 0);
1004 unsigned EdgeStart = Probs.size();
1005 EdgeStarts[BB->
getNumber()] = EdgeStart + 1;
1006 Probs.append(NumSuccs, {});
1011BranchProbabilityInfo::getEdges(
const BasicBlock *BB)
const {
1013 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1014 if (EdgeStarts.size() <= BB->
getNumber())
1016 if (
unsigned EdgeStart = EdgeStarts[BB->
getNumber()]) {
1017 const BranchProbability *
Start = &Probs[EdgeStart - 1];
1018 size_t Count = SIZE_MAX;
1028 FunctionAnalysisManager::Invalidator &) {
1037 OS <<
"---- Branch Probabilities ----\n";
1040 assert(LastF &&
"Cannot print prior to running over a function");
1041 for (
const auto &BI : *LastF) {
1060 unsigned IndexInSuccessors)
const {
1062 return P[IndexInSuccessors];
1077 if (It.value() == Dst)
1078 Prob +=
P[It.index()];
1090 if (WeightSum > UINT32_MAX) {
1091 uint64_t ScalingFactor = WeightSum / UINT32_MAX + 1;
1092 for (
uint32_t &Weight : ScaledWeights)
1093 Weight /= ScalingFactor;
1097 assert(WeightSum <= UINT32_MAX &&
1098 "Expected weights to scale down to 32 bits");
1100 if (WeightSum == 0) {
1101 fill(ScaledWeights, 1);
1102 WeightSum = ScaledWeights.
size();
1113 assert(Src->getTerminator()->getNumSuccessors() == Probs.size());
1115 uint64_t TotalNumerator = 0;
1116 for (
unsigned SuccIdx = 0; SuccIdx < Probs.size(); ++SuccIdx) {
1117 P[SuccIdx] = Probs[SuccIdx];
1118 LLVM_DEBUG(
dbgs() <<
"set edge " << Src->getName() <<
" -> " << SuccIdx
1119 <<
" successor probability to " << Probs[SuccIdx]
1121 TotalNumerator += Probs[SuccIdx].getNumerator();
1133 (void)TotalNumerator;
1147 for (
unsigned i = 0; i != DstP.
size(); ++i) {
1149 LLVM_DEBUG(
dbgs() <<
"set edge " << Dst->getName() <<
" -> " << i
1150 <<
" successor probability to " << SrcP[i] <<
"\n");
1155 assert(Src->getTerminator()->getNumSuccessors() == 2);
1170 Src->printAsOperand(OS,
false, Src->getModule());
1172 Dst->printAsOperand(OS,
false, Dst->getModule());
1173 OS <<
" probability is " << Prob
1174 << (
isEdgeHot(Src, Dst) ?
" [HOT edge]\n" :
"\n");
1182 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1183 if (EdgeStarts.size() > BB->
getNumber())
1195 BlockNumberEpoch =
F.getBlockNumberEpoch();
1198 BPIConstruction(*this).calculate(
F, CycleI, TLI, DT, PDT);
1201 if (Opts.print_bpi && (Opts.print_bpi_func_name.empty() ||
1202 F.getName() == Opts.print_bpi_func_name)) {
1227 BPI.calculate(
F, CI, &TLI, &DT, &PDT);
1250 OS <<
"Printing analysis 'Branch Probability Analysis' for function '"
1251 <<
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 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.
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.
SmallVector< MachineOperand, 4 > 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.
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)
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.
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.
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.
LLVM_ABI Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const Function *CtxF=nullptr)
Attempt to constant fold a compare instruction (icmp/fcmp) with the specified operands.
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...
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 >
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.
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...