LLVM 23.0.0git
BranchProbabilityInfo.cpp File Reference

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "branch-prob"

Enumerations

enum class  BlockExecWeight : std::uint32_t {
  ZERO = 0x0 , LOWEST_NON_ZERO = 0x1 , UNREACHABLE = ZERO , NORETURN = LOWEST_NON_ZERO ,
  UNWIND = LOWEST_NON_ZERO , COLD = 0xffff , DEFAULT = 0xfffff
}
 Set of dedicated "absolute" execution weights for a block. More...

Functions

 INITIALIZE_PASS_BEGIN (BranchProbabilityInfoWrapperPass, "branch-prob", "Branch Probability Analysis", false, true) INITIALIZE_PASS_END(BranchProbabilityInfoWrapperPass
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 constexpr BranchProbability ZeroTakenProb (ZH_TAKEN_WEIGHT, ZH_TAKEN_WEIGHT+ZH_NONTAKEN_WEIGHT)
static constexpr BranchProbability ZeroUntakenProb (ZH_NONTAKEN_WEIGHT, ZH_TAKEN_WEIGHT+ZH_NONTAKEN_WEIGHT)
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 constexpr BranchProbability FPTakenProb (FPH_TAKEN_WEIGHT, FPH_TAKEN_WEIGHT+FPH_NONTAKEN_WEIGHT)
static constexpr BranchProbability FPUntakenProb (FPH_NONTAKEN_WEIGHT, FPH_TAKEN_WEIGHT+FPH_NONTAKEN_WEIGHT)

Variables

static cl::opt< boolPrintBranchProb ("print-bpi", cl::init(false), cl::Hidden, cl::desc("Print the branch probability info."))
static cl::opt< std::stringPrintBranchProbFuncName ("print-bpi-func-name", cl::Hidden, cl::desc("The option to specify the name of the function " "whose branch probability info is printed."))
branch prob
branch Branch Probability Analysis
branch Branch Probability false
static const uint32_t LBH_TAKEN_WEIGHT = 124
static const uint32_t LBH_NONTAKEN_WEIGHT = 4
static constexpr BranchProbability UR_TAKEN_PROB = BranchProbability::getRaw(1)
 Unreachable-terminating branch taken probability.
static const uint32_t PH_TAKEN_WEIGHT = 20
 Heuristics and lookup tables for non-loop branches: Pointer Heuristics (PH)
static const uint32_t PH_NONTAKEN_WEIGHT = 12
static const uint32_t ZH_TAKEN_WEIGHT = 20
 Zero Heuristics (ZH)
static const uint32_t ZH_NONTAKEN_WEIGHT = 12
static const uint32_t FPH_TAKEN_WEIGHT = 20
static const uint32_t FPH_NONTAKEN_WEIGHT = 12
static const uint32_t FPH_ORD_WEIGHT = 1024 * 1024 - 1
 This is the probability for an ordered floating point comparison.
static const uint32_t FPH_UNO_WEIGHT = 1
 This is the probability for an unordered floating point comparison, it means one or two of the operands are NaN.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "branch-prob"

Definition at line 51 of file BranchProbabilityInfo.cpp.

Enumeration Type Documentation

◆ BlockExecWeight

enum class BlockExecWeight : std::uint32_t
strong

Set of dedicated "absolute" execution weights for a block.

These weights are meaningful relative to each other and their derivatives only.

Enumerator
ZERO 

Special weight used for cases with exact zero probability.

LOWEST_NON_ZERO 

Minimal possible non zero weight.

UNREACHABLE 

Weight to an 'unreachable' 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.

Cold blocks are the ones containing calls marked with attribute 'cold'.

DEFAULT 

Default weight is used in cases when there is no dedicated execution weight set.

It is not propagated through the domination line either.

Definition at line 145 of file BranchProbabilityInfo.cpp.

Function Documentation

◆ FPOrdTakenProb()

constexpr BranchProbability FPOrdTakenProb ( FPH_ORD_WEIGHT ,
FPH_ORD_WEIGHT+ FPH_UNO_WEIGHT )
staticconstexpr

References FPH_ORD_WEIGHT, and FPH_UNO_WEIGHT.

◆ FPOrdUntakenProb()

constexpr BranchProbability FPOrdUntakenProb ( FPH_UNO_WEIGHT ,
FPH_ORD_WEIGHT+ FPH_UNO_WEIGHT )
staticconstexpr

References FPH_ORD_WEIGHT, and FPH_UNO_WEIGHT.

◆ FPTakenProb()

constexpr BranchProbability FPTakenProb ( FPH_TAKEN_WEIGHT ,
FPH_TAKEN_WEIGHT+ FPH_NONTAKEN_WEIGHT )
staticconstexpr

◆ FPUntakenProb()

constexpr BranchProbability FPUntakenProb ( FPH_NONTAKEN_WEIGHT ,
FPH_TAKEN_WEIGHT+ FPH_NONTAKEN_WEIGHT )
staticconstexpr

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( BranchProbabilityInfoWrapperPass ,
"branch-prob" ,
"Branch Probability Analysis" ,
false ,
true  )

◆ PtrTakenProb()

constexpr BranchProbability PtrTakenProb ( PH_TAKEN_WEIGHT ,
PH_TAKEN_WEIGHT+ PH_NONTAKEN_WEIGHT )
staticconstexpr

◆ PtrUntakenProb()

constexpr BranchProbability PtrUntakenProb ( PH_NONTAKEN_WEIGHT ,
PH_TAKEN_WEIGHT+ PH_NONTAKEN_WEIGHT )
staticconstexpr

◆ ZeroTakenProb()

constexpr BranchProbability ZeroTakenProb ( ZH_TAKEN_WEIGHT ,
ZH_TAKEN_WEIGHT+ ZH_NONTAKEN_WEIGHT )
staticconstexpr

◆ ZeroUntakenProb()

constexpr BranchProbability ZeroUntakenProb ( ZH_NONTAKEN_WEIGHT ,
ZH_TAKEN_WEIGHT+ ZH_NONTAKEN_WEIGHT )
staticconstexpr

Variable Documentation

◆ Analysis

branch Branch Probability Analysis

Definition at line 69 of file BranchProbabilityInfo.cpp.

◆ false

branch Branch Probability false

Definition at line 69 of file BranchProbabilityInfo.cpp.

◆ FPH_NONTAKEN_WEIGHT

const uint32_t FPH_NONTAKEN_WEIGHT = 12
static

Definition at line 125 of file BranchProbabilityInfo.cpp.

Referenced by FPTakenProb(), and FPUntakenProb().

◆ FPH_ORD_WEIGHT

const uint32_t FPH_ORD_WEIGHT = 1024 * 1024 - 1
static

This is the probability for an ordered floating point comparison.

Definition at line 128 of file BranchProbabilityInfo.cpp.

Referenced by FPOrdTakenProb(), and FPOrdUntakenProb().

◆ FPH_TAKEN_WEIGHT

const uint32_t FPH_TAKEN_WEIGHT = 20
static

Definition at line 124 of file BranchProbabilityInfo.cpp.

Referenced by FPTakenProb(), and FPUntakenProb().

◆ FPH_UNO_WEIGHT

const uint32_t FPH_UNO_WEIGHT = 1
static

This is the probability for an unordered floating point comparison, it means one or two of the operands are NaN.

Usually it is used to test for an exceptional case, so the result is unlikely.

Definition at line 132 of file BranchProbabilityInfo.cpp.

Referenced by FPOrdTakenProb(), and FPOrdUntakenProb().

◆ LBH_NONTAKEN_WEIGHT

const uint32_t LBH_NONTAKEN_WEIGHT = 4
static

Definition at line 97 of file BranchProbabilityInfo.cpp.

◆ LBH_TAKEN_WEIGHT

const uint32_t LBH_TAKEN_WEIGHT = 124
static

Definition at line 96 of file BranchProbabilityInfo.cpp.

◆ PH_NONTAKEN_WEIGHT

const uint32_t PH_NONTAKEN_WEIGHT = 12
static

Definition at line 109 of file BranchProbabilityInfo.cpp.

Referenced by PtrTakenProb(), and PtrUntakenProb().

◆ PH_TAKEN_WEIGHT

const uint32_t PH_TAKEN_WEIGHT = 20
static

Heuristics and lookup tables for non-loop branches: Pointer Heuristics (PH)

Definition at line 108 of file BranchProbabilityInfo.cpp.

Referenced by PtrTakenProb(), and PtrUntakenProb().

◆ PrintBranchProb

cl::opt< bool > PrintBranchProb("print-bpi", cl::init(false), cl::Hidden, cl::desc("Print the branch probability info.")) ( "print-bpi" ,
cl::init(false) ,
cl::Hidden ,
cl::desc("Print the branch probability info.")  )
static

◆ PrintBranchProbFuncName

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.")) ( "print-bpi-func-name" ,
cl::Hidden ,
cl::desc("The option to specify the name of the function " "whose branch probability info is printed.")  )
static

◆ prob

branch prob

Definition at line 68 of file BranchProbabilityInfo.cpp.

◆ UR_TAKEN_PROB

BranchProbability UR_TAKEN_PROB = BranchProbability::getRaw(1)
staticconstexpr

Unreachable-terminating branch taken probability.

This is the probability for a branch being taken to a block that terminates (eventually) in unreachable. These are predicted as unlikely as possible. All reachable probability will proportionally share the remaining part.

Definition at line 104 of file BranchProbabilityInfo.cpp.

◆ ZH_NONTAKEN_WEIGHT

const uint32_t ZH_NONTAKEN_WEIGHT = 12
static

Definition at line 117 of file BranchProbabilityInfo.cpp.

Referenced by ZeroTakenProb(), and ZeroUntakenProb().

◆ ZH_TAKEN_WEIGHT

const uint32_t ZH_TAKEN_WEIGHT = 20
static

Zero Heuristics (ZH)

Definition at line 116 of file BranchProbabilityInfo.cpp.

Referenced by ZeroTakenProb(), and ZeroUntakenProb().