llvm::getBranchProbability

Return the probability that conditional branch B takes one successor.

Synopsis

Declared in <llvm/Transforms/Utils/LoopUtils.h>

BranchProbability
getBranchProbability(
    CondBrInst* B,
    bool ForFirstTarget);

Description

Based on branch weight metadata, return either:

  • An unknown probability if the implementation cannot extract the probability (e.g., B must have exactly two target labels, so it must be a conditional branch).

  • The probability P that control flows from B to its first target label such that 1 - P is the probability of control flowing to its second target label, or vice-versa if ForFirstTarget is false.

Return Value

The selected successor probability, or unknown if unsupported.

Parameters

NameDescription
BConditional branch with exactly two successors.
ForFirstTargetIf true, return the probability of the first successor; otherwise the second.