50#define DEBUG_TYPE "branch-prob"
54 cl::desc(
"Print the branch probability info."));
58 cl::desc(
"The option to specify the name of the function "
59 "whose branch probability info is printed."));
62 "Branch Probability Analysis",
false,
true)
164class BPIConstruction {
166 BPIConstruction(BranchProbabilityInfo &BPI) : BPI(BPI) {}
167 void calculate(
const Function &
F,
const CycleInfo &CI,
168 const TargetLibraryInfo *TLI, DominatorTree *DT,
169 PostDominatorTree *PDT);
173 using LoopEdge = std::pair<const BasicBlock *, const BasicBlock *>;
178 bool isLoopEnteringEdge(
const LoopEdge &
Edge)
const;
182 bool isLoopExitingEdge(
const LoopEdge &
Edge)
const;
185 bool isLoopEnteringExitingEdge(
const LoopEdge &
Edge)
const;
188 SmallVectorImpl<const BasicBlock *> &Enters)
const;
192 std::optional<uint32_t> getEstimatedBlockWeight(
const BasicBlock *BB)
const;
197 std::optional<uint32_t> getEstimatedLoopWeight(CycleRef
C)
const;
201 std::optional<uint32_t> getEstimatedEdgeWeight(
const LoopEdge &
Edge)
const;
206 template <
class IterT>
207 std::optional<uint32_t>
208 getMaxEstimatedEdgeWeight(
const BasicBlock *SrcBB,
216 updateEstimatedBlockWeight(
const BasicBlock *BB, uint32_t BBWeight,
217 SmallVectorImpl<const BasicBlock *> &BlockWorkList,
218 SmallVectorImpl<const BasicBlock *> &LoopWorkList);
222 void propagateEstimatedBlockWeight(
223 const BasicBlock *BB, DominatorTree *DT, PostDominatorTree *PDT,
224 uint32_t BBWeight, SmallVectorImpl<const BasicBlock *> &WorkList,
225 SmallVectorImpl<const BasicBlock *> &LoopWorkList);
228 std::optional<uint32_t> getInitialEstimatedBlockWeight(
const BasicBlock *BB);
231 void estimateBlockWeights(
const Function &
F, DominatorTree *DT,
232 PostDominatorTree *PDT);
236 bool calcEstimatedHeuristics(
const BasicBlock *BB);
237 bool calcMetadataWeights(
const BasicBlock *BB);
238 bool calcPointerHeuristics(
const BasicBlock *BB);
239 bool calcZeroHeuristics(
const BasicBlock *BB,
const TargetLibraryInfo *TLI);
240 bool calcFloatingPointHeuristics(
const BasicBlock *BB);
242 BranchProbabilityInfo &BPI;
244 const CycleInfo *CI =
nullptr;
247 SmallDenseMap<const BasicBlock *, uint32_t> EstimatedBlockWeight;
250 SmallDenseMap<CycleRef, uint32_t> EstimatedLoopWeight;
253bool BPIConstruction::isLoopEnteringEdge(
const LoopEdge &Edge)
const {
260 return !CI->
contains(DstCycle, SrcCycle);
263bool BPIConstruction::isLoopExitingEdge(
const LoopEdge &
Edge)
const {
264 return isLoopEnteringEdge({
Edge.second,
Edge.first});
267bool BPIConstruction::isLoopEnteringExitingEdge(
const LoopEdge &
Edge)
const {
268 return isLoopEnteringEdge(
Edge) || isLoopExitingEdge(
Edge);
271void BPIConstruction::getLoopEnterBlocks(
272 const BasicBlock *BB, SmallVectorImpl<const BasicBlock *> &Enters)
const {
284bool BPIConstruction::calcMetadataWeights(
const BasicBlock *BB) {
299 SmallVector<unsigned, 2> UnreachableIdxs;
300 SmallVector<unsigned, 2> ReachableIdxs;
304 for (
unsigned I = 0,
E = Weights.
size();
I !=
E; ++
I) {
305 auto EstimatedWeight = getEstimatedEdgeWeight({BB, *Succs++});
306 if (EstimatedWeight &&
315 if (ReachableIdxs.
empty())
324 if (UnreachableIdxs.
size() == 0 || ReachableIdxs.
size() == 0) {
330 for (
auto I : UnreachableIdxs)
331 if (UnreachableProb < BP[
I]) {
332 BP[
I] = UnreachableProb;
356 for (
auto I : UnreachableIdxs)
357 NewUnreachableSum += BP[
I];
359 BranchProbability NewReachableSum =
363 for (
auto I : ReachableIdxs)
364 OldReachableSum += BP[
I];
366 if (OldReachableSum != NewReachableSum) {
367 if (OldReachableSum.
isZero()) {
371 BranchProbability PerEdge = NewReachableSum / ReachableIdxs.size();
372 for (
auto I : ReachableIdxs)
375 for (
auto I : ReachableIdxs) {
381 BP[
I].getNumerator();
382 uint32_t Div =
static_cast<uint32_t
>(
396bool BPIConstruction::calcPointerHeuristics(
const BasicBlock *BB) {
414 case ICmpInst::ICMP_NE:
417 case ICmpInst::ICMP_EQ:
429computeUnlikelySuccessors(
const BasicBlock *BB,
const CycleInfo &CI, CycleRef
C,
430 SmallPtrSetImpl<const BasicBlock *> &UnlikelyBlocks) {
484 SmallPtrSet<PHINode*, 8> VisitedInsts;
487 VisitedInsts.
insert(CmpPHI);
488 while (!WorkList.
empty()) {
490 for (BasicBlock *
B :
P->blocks()) {
494 Value *
V =
P->getIncomingValueForBlock(
B);
498 if (VisitedInsts.
insert(PN).second)
520 Cmp->getPredicate(), CmpLHSConst, CmpConst,
DL);
530std::optional<uint32_t>
531BPIConstruction::getEstimatedBlockWeight(
const BasicBlock *BB)
const {
532 auto WeightIt = EstimatedBlockWeight.find(BB);
533 if (WeightIt == EstimatedBlockWeight.end())
535 return WeightIt->second;
538std::optional<uint32_t>
539BPIConstruction::getEstimatedLoopWeight(CycleRef
C)
const {
540 auto WeightIt = EstimatedLoopWeight.find(
C);
541 if (WeightIt == EstimatedLoopWeight.end())
543 return WeightIt->second;
546std::optional<uint32_t>
547BPIConstruction::getEstimatedEdgeWeight(
const LoopEdge &
Edge)
const {
550 return isLoopEnteringEdge(
Edge)
552 : getEstimatedBlockWeight(
Edge.second);
555template <
class IterT>
556std::optional<uint32_t> BPIConstruction::getMaxEstimatedEdgeWeight(
558 std::optional<uint32_t> MaxWeight;
559 for (
const BasicBlock *DstBB : Successors) {
560 auto Weight = getEstimatedEdgeWeight({SrcBB, DstBB});
563 if (!MaxWeight || *MaxWeight < *Weight)
575bool BPIConstruction::updateEstimatedBlockWeight(
576 const BasicBlock *BB, uint32_t BBWeight,
577 SmallVectorImpl<const BasicBlock *> &BlockWorkList,
578 SmallVectorImpl<const BasicBlock *> &LoopWorkList) {
584 if (!EstimatedBlockWeight.insert({BB, BBWeight}).second)
589 if (isLoopExitingEdge({PredBlock, BB})) {
590 if (!EstimatedLoopWeight.count(CI->
getCycle(PredBlock)))
592 }
else if (!EstimatedBlockWeight.count(PredBlock))
610void BPIConstruction::propagateEstimatedBlockWeight(
611 const BasicBlock *BB, DominatorTree *DT, PostDominatorTree *PDT,
612 uint32_t BBWeight, SmallVectorImpl<const BasicBlock *> &BlockWorkList,
613 SmallVectorImpl<const BasicBlock *> &LoopWorkList) {
614 const auto *DTStartNode = DT->
getNode(BB);
615 const auto *PDTStartNode = PDT->
getNode(BB);
618 for (
const auto *DTNode = DTStartNode; DTNode !=
nullptr;
619 DTNode = DTNode->getIDom()) {
620 auto *DomBB = DTNode->getBlock();
627 const LoopEdge
Edge{DomBB, BB};
629 if (!isLoopEnteringExitingEdge(
Edge)) {
630 if (!updateEstimatedBlockWeight(DomBB, BBWeight, BlockWorkList,
635 }
else if (isLoopExitingEdge(
Edge)) {
641std::optional<uint32_t>
642BPIConstruction::getInitialEstimatedBlockWeight(
const BasicBlock *BB) {
644 auto hasNoReturn = [&](
const BasicBlock *BB) {
647 if (CI->hasFnAttr(Attribute::NoReturn))
662 return hasNoReturn(BB)
671 for (
const auto &
I : *BB)
673 if (CI->hasFnAttr(Attribute::Cold))
682void BPIConstruction::estimateBlockWeights(
const Function &
F, DominatorTree *DT,
683 PostDominatorTree *PDT) {
684 SmallVector<const BasicBlock *, 8> BlockWorkList;
685 SmallVector<const BasicBlock *, 8> LoopWorkList;
686 SmallDenseMap<CycleRef, SmallVector<BasicBlock *, 4>> LoopExitBlocks;
690 ReversePostOrderTraversal<const Function *> RPOT(&
F);
691 for (
const auto *BB : RPOT)
692 if (
auto BBWeight = getInitialEstimatedBlockWeight(BB))
695 propagateEstimatedBlockWeight(BB, DT, PDT, *BBWeight, BlockWorkList,
703 while (!LoopWorkList.
empty()) {
706 if (EstimatedLoopWeight.count(
C))
710 SmallVectorImpl<BasicBlock *> &Exits = Res.first->second;
713 auto LoopWeight = getMaxEstimatedEdgeWeight(
721 EstimatedLoopWeight.insert({
C, *LoopWeight});
723 getLoopEnterBlocks(LoopBB, BlockWorkList);
727 while (!BlockWorkList.
empty()) {
730 if (EstimatedBlockWeight.count(BB))
739 auto MaxWeight = getMaxEstimatedEdgeWeight(BB,
successors(BB));
742 propagateEstimatedBlockWeight(BB, DT, PDT, *MaxWeight, BlockWorkList,
745 }
while (!BlockWorkList.
empty() || !LoopWorkList.
empty());
751bool BPIConstruction::calcEstimatedHeuristics(
const BasicBlock *BB) {
753 "expected more than one successor!");
755 CycleRef BBCycle = CI->
getCycle(BB);
757 SmallPtrSet<const BasicBlock *, 8> UnlikelyBlocks;
760 computeUnlikelySuccessors(BB, *CI, BBCycle, UnlikelyBlocks);
763 bool FoundEstimatedWeight =
false;
764 SmallVector<uint32_t, 4> SuccWeights;
767 for (
const BasicBlock *SuccBB :
successors(BB)) {
768 std::optional<uint32_t> Weight;
769 const LoopEdge
Edge{BB, SuccBB};
771 Weight = getEstimatedEdgeWeight(
Edge);
773 if (isLoopExitingEdge(
Edge) &&
782 bool IsUnlikelyEdge = BBCycle && UnlikelyBlocks.
contains(SuccBB);
783 if (IsUnlikelyEdge &&
793 FoundEstimatedWeight =
true;
797 TotalWeight += WeightVal;
804 if (!FoundEstimatedWeight || TotalWeight == 0)
808 const unsigned SuccCount = SuccWeights.
size();
812 if (TotalWeight > UINT32_MAX) {
813 uint64_t ScalingFactor = TotalWeight / UINT32_MAX + 1;
815 for (
unsigned Idx = 0; Idx < SuccCount; ++Idx) {
816 SuccWeights[Idx] /= ScalingFactor;
820 TotalWeight += SuccWeights[Idx];
822 assert(TotalWeight <= UINT32_MAX &&
"Total weight overflows");
829 for (
unsigned Idx = 0; Idx < SuccCount; ++Idx) {
830 EdgeProbabilities[Idx] =
831 BranchProbability(SuccWeights[Idx], (uint32_t)TotalWeight);
837bool BPIConstruction::calcZeroHeuristics(
const BasicBlock *BB,
838 const TargetLibraryInfo *TLI) {
848 auto GetConstantInt = [](
Value *
V) {
855 ConstantInt *CV = GetConstantInt(
RHS);
862 if (
LHS->getOpcode() == Instruction::And)
863 if (ConstantInt *AndRHS = GetConstantInt(
LHS->getOperand(1)))
864 if (AndRHS->getValue().isPowerOf2())
868 LibFunc
Func = LibFunc::NotLibFunc;
875 if (Func == LibFunc_strcasecmp ||
876 Func == LibFunc_strcmp ||
877 Func == LibFunc_strncasecmp ||
878 Func == LibFunc_strncmp ||
879 Func == LibFunc_memcmp ||
880 Func == LibFunc_bcmp) {
892 default:
return false;
895 }
else if (CV->
isZero()) {
902 default:
return false;
905 }
else if (CV->
isOne()) {
909 default:
return false;
919 default:
return false;
933bool BPIConstruction::calcFloatingPointHeuristics(
const BasicBlock *BB) {
948 }
else if (FCmp->
getPredicate() == FCmpInst::FCMP_ORD) {
951 }
else if (FCmp->
getPredicate() == FCmpInst::FCMP_UNO) {
959void BPIConstruction::calculate(
const Function &
F,
const CycleInfo &CycleI,
960 const TargetLibraryInfo *TLI, DominatorTree *DT,
961 PostDominatorTree *PDT) {
964 std::unique_ptr<DominatorTree> DTPtr;
965 std::unique_ptr<PostDominatorTree> PDTPtr;
968 DTPtr = std::make_unique<DominatorTree>(
const_cast<Function &
>(
F));
973 PDTPtr = std::make_unique<PostDominatorTree>(
const_cast<Function &
>(
F));
977 estimateBlockWeights(
F, DT, PDT);
981 for (
const auto *BB :
post_order(&
F.getEntryBlock())) {
987 if (calcMetadataWeights(BB))
989 if (calcEstimatedHeuristics(BB))
991 if (calcPointerHeuristics(BB))
993 if (calcZeroHeuristics(BB, TLI))
995 if (calcFloatingPointHeuristics(BB))
1003BranchProbabilityInfo::allocEdges(
const BasicBlock *BB) {
1005 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1007 if (NumSuccs == 0) {
1011 if (EdgeStarts.size() <= BB->
getNumber())
1012 EdgeStarts.resize(LastF->getMaxBlockNumber(), 0);
1013 unsigned EdgeStart = Probs.size();
1014 EdgeStarts[BB->
getNumber()] = EdgeStart + 1;
1015 Probs.append(NumSuccs, {});
1020BranchProbabilityInfo::getEdges(
const BasicBlock *BB)
const {
1022 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1023 if (EdgeStarts.size() <= BB->
getNumber())
1025 if (
unsigned EdgeStart = EdgeStarts[BB->
getNumber()]) {
1026 const BranchProbability *
Start = &Probs[EdgeStart - 1];
1027 size_t Count = SIZE_MAX;
1037 FunctionAnalysisManager::Invalidator &) {
1046 OS <<
"---- Branch Probabilities ----\n";
1049 assert(LastF &&
"Cannot print prior to running over a function");
1050 for (
const auto &BI : *LastF) {
1069 unsigned IndexInSuccessors)
const {
1071 return P[IndexInSuccessors];
1086 if (It.value() == Dst)
1087 Prob +=
P[It.index()];
1099 if (WeightSum > UINT32_MAX) {
1100 uint64_t ScalingFactor = WeightSum / UINT32_MAX + 1;
1101 for (
uint32_t &Weight : ScaledWeights)
1102 Weight /= ScalingFactor;
1106 assert(WeightSum <= UINT32_MAX &&
1107 "Expected weights to scale down to 32 bits");
1109 if (WeightSum == 0) {
1110 fill(ScaledWeights, 1);
1111 WeightSum = ScaledWeights.
size();
1122 assert(Src->getTerminator()->getNumSuccessors() == Probs.size());
1124 uint64_t TotalNumerator = 0;
1125 for (
unsigned SuccIdx = 0; SuccIdx < Probs.size(); ++SuccIdx) {
1126 P[SuccIdx] = Probs[SuccIdx];
1127 LLVM_DEBUG(
dbgs() <<
"set edge " << Src->getName() <<
" -> " << SuccIdx
1128 <<
" successor probability to " << Probs[SuccIdx]
1130 TotalNumerator += Probs[SuccIdx].getNumerator();
1142 (void)TotalNumerator;
1156 for (
unsigned i = 0; i != DstP.
size(); ++i) {
1158 LLVM_DEBUG(
dbgs() <<
"set edge " << Dst->getName() <<
" -> " << i
1159 <<
" successor probability to " << SrcP[i] <<
"\n");
1164 assert(Src->getTerminator()->getNumSuccessors() == 2);
1179 Src->printAsOperand(OS,
false, Src->getModule());
1181 Dst->printAsOperand(OS,
false, Dst->getModule());
1182 OS <<
" probability is " << Prob
1183 << (
isEdgeHot(Src, Dst) ?
" [HOT edge]\n" :
"\n");
1191 assert(BlockNumberEpoch == LastF->getBlockNumberEpoch());
1192 if (EdgeStarts.size() > BB->
getNumber())
1204 BlockNumberEpoch =
F.getBlockNumberEpoch();
1207 BPIConstruction(*this).calculate(
F, CycleI, TLI, DT, PDT);
1235 BPI.calculate(
F, CI, &TLI, &DT, &PDT);
1258 OS <<
"Printing analysis 'Branch Probability Analysis' for function '"
1259 <<
F.getName() <<
"':\n";
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
This file contains the simple types necessary to represent the attributes associated with functions a...
BlockExecWeight
Set of dedicated "absolute" execution weights for a block.
@ NORETURN
Weight to a block containing non returning call.
@ UNWIND
Weight to 'unwind' block of an invoke instruction.
@ COLD
Weight to a 'cold' block.
@ ZERO
Special weight used for cases with exact zero probability.
@ UNREACHABLE
Weight to an 'unreachable' block.
@ DEFAULT
Default weight is used in cases when there is no dedicated execution weight set.
@ LOWEST_NON_ZERO
Minimal possible non zero weight.
static constexpr BranchProbability FPTakenProb(FPH_TAKEN_WEIGHT, FPH_TAKEN_WEIGHT+FPH_NONTAKEN_WEIGHT)
static const uint32_t FPH_TAKEN_WEIGHT
static const uint32_t LBH_TAKEN_WEIGHT
static const uint32_t ZH_NONTAKEN_WEIGHT
static const uint32_t PH_NONTAKEN_WEIGHT
static constexpr BranchProbability UR_TAKEN_PROB
Unreachable-terminating branch taken probability.
static const uint32_t PH_TAKEN_WEIGHT
Heuristics and lookup tables for non-loop branches: Pointer Heuristics (PH)
static constexpr BranchProbability FPUntakenProb(FPH_NONTAKEN_WEIGHT, FPH_TAKEN_WEIGHT+FPH_NONTAKEN_WEIGHT)
static constexpr BranchProbability PtrTakenProb(PH_TAKEN_WEIGHT, PH_TAKEN_WEIGHT+PH_NONTAKEN_WEIGHT)
static constexpr BranchProbability PtrUntakenProb(PH_NONTAKEN_WEIGHT, PH_TAKEN_WEIGHT+PH_NONTAKEN_WEIGHT)
static const uint32_t ZH_TAKEN_WEIGHT
Zero Heuristics (ZH)
static const uint32_t FPH_NONTAKEN_WEIGHT
static constexpr BranchProbability ZeroTakenProb(ZH_TAKEN_WEIGHT, ZH_TAKEN_WEIGHT+ZH_NONTAKEN_WEIGHT)
static const uint32_t LBH_NONTAKEN_WEIGHT
static constexpr BranchProbability ZeroUntakenProb(ZH_NONTAKEN_WEIGHT, ZH_TAKEN_WEIGHT+ZH_NONTAKEN_WEIGHT)
static const uint32_t FPH_ORD_WEIGHT
This is the probability for an ordered floating point comparison.
static const uint32_t FPH_UNO_WEIGHT
This is the probability for an unordered floating point comparison, it means one or two of the operan...
static cl::opt< std::string > PrintBranchProbFuncName("print-bpi-func-name", cl::Hidden, cl::desc("The option to specify the name of the function " "whose branch probability info is printed."))
static constexpr BranchProbability FPOrdTakenProb(FPH_ORD_WEIGHT, FPH_ORD_WEIGHT+FPH_UNO_WEIGHT)
static cl::opt< bool > PrintBranchProb("print-bpi", cl::init(false), cl::Hidden, cl::desc("Print the branch probability info."))
static constexpr BranchProbability FPOrdUntakenProb(FPH_UNO_WEIGHT, FPH_ORD_WEIGHT+FPH_UNO_WEIGHT)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file declares an analysis pass that computes CycleInfo for LLVM IR, specialized from GenericCycl...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
std::pair< BasicBlock *, BasicBlock * > Edge
This file defines the SmallVector class.
This templated class represents "all analyses that operate over <aparticular IR unit>" (e....
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
LLVM Basic Block Representation.
unsigned getNumber() const
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
bool isEHPad() const
Return true if this basic block is an exception handling block.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Analysis pass which computes BranchProbabilityInfo.
LLVM_ABI BranchProbabilityInfo run(Function &F, FunctionAnalysisManager &AM)
Run the analysis pass over a function and produce BPI.
Legacy analysis pass which computes BranchProbabilityInfo.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
BranchProbabilityInfoWrapperPass()
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void print(raw_ostream &OS, const Module *M=nullptr) const override
print - Print out the internal state of the pass.
Analysis providing branch probability information.
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.
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.
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.
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...