42constexpr unsigned MinBWOps = 3;
45constexpr unsigned MinVPOps = 5;
49bool isTargetMD(
const MDNode *ProfData,
const char *Name,
unsigned MinOps) {
52 if (!ProfData || !Name || MinOps < 2)
63 return ProfDataName->getString() ==
Name;
67 typename =
typename std::enable_if<std::is_arithmetic_v<T>>>
68static void extractFromBranchWeightMD(
const MDNode *ProfileData,
74 assert(WeightsIdx < NOps &&
"Weights Index must be less than NOps.");
75 Weights.
resize(NOps - WeightsIdx);
77 for (
unsigned Idx = WeightsIdx,
E = NOps; Idx !=
E; ++Idx) {
80 assert(Weight &&
"Malformed branch_weight in MD_prof node");
82 "Too many bits for MD_prof branch_weight");
96 "synthetic_function_entry_count";
101 return I.hasMetadata(LLVMContext::MD_prof);
113 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
118 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
132 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
143 assert(ProfDataName ==
nullptr ||
145 return ProfDataName !=
nullptr;
157 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
172 extractFromBranchWeightMD(ProfileData, Weights);
177 extractFromBranchWeightMD(ProfileData, Weights);
184 extractFromBranchWeightMD(ProfileData, Weights);
190 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
196 assert((
I.getOpcode() == Instruction::Br ||
197 I.getOpcode() == Instruction::Select) &&
198 "Looking for branch weights on something besides branch, select, or "
202 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
206 if (Weights.
size() > 2)
209 TrueVal = Weights[0];
210 FalseVal = Weights[1];
227 TotalVal += V->getValue().getZExtValue();
249 LLVMContext::MD_prof,
251 {MDB.createString(MDProfLabels::UnknownBranchWeightsMarker),
252 MDB.createString(PassName)}));
258 LLVMContext::MD_prof,
260 {MDB.createString(MDProfLabels::UnknownBranchWeightsMarker),
261 MDB.createString(PassName)}));
271 auto *MD =
I.getMetadata(LLVMContext::MD_prof);
281 I.setMetadata(LLVMContext::MD_prof, BranchWeights);
285 std::optional<uint64_t> KnownMaxCount) {
286 uint64_t MaxCount = KnownMaxCount.has_value() ? KnownMaxCount.value()
288 assert(MaxCount > 0 &&
"Bad max count");
291 for (
const auto &ECI : Weights)
293 return DownscaledWeights;
297 assert(
T != 0 &&
"Caller should guarantee");
298 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
299 if (ProfileData ==
nullptr)
316 APInt APS(128, S), APT(128,
T);
329 for (
unsigned Idx = 1; Idx < ProfileData->
getNumOperands(); Idx += 2) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file contains the declarations for profiling metadata utility functions.
This file defines the SmallVector class.
static const char PassName[]
Class for arbitrary precision integers.
LLVM_ABI APInt udiv(const APInt &RHS) const
Unsigned division operation.
unsigned getActiveBits() const
Compute the number of active bits in the value.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This is the shared class of boolean and integer constants.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const APInt & getValue() const
Return the constant as an APInt value reference.
This is an important class for using LLVM in a threaded context.
LLVM_ABI ConstantAsMetadata * createConstant(Constant *C)
Return the given constant as metadata.
LLVM_ABI MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight, bool IsExpected=false)
Return metadata containing two branch weights.
const MDOperand & getOperand(unsigned I) const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
bool equalsStr(StringRef Str) const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
@ C
The default llvm calling convention, compatible with C.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalWeights)
Retrieve the total of all weights from MD_prof data.
LLVM_ABI unsigned getBranchWeightOffset(const MDNode *ProfileData)
Return the offset to the first branch weight data.
LLVM_ABI bool isBranchWeightMD(const MDNode *ProfileData)
Checks if an MDNode contains Branch Weight Metadata.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool isExplicitlyUnknownProfileMetadata(const MDNode &MD)
LLVM_ABI MDNode * getBranchWeightMDNode(const Instruction &I)
Get the branch weights metadata node.
LLVM_ABI void setExplicitlyUnknownBranchWeights(Instruction &I, StringRef PassName)
Specify that the branch weights for this terminator cannot be known at compile time.
LLVM_ABI bool hasBranchWeightOrigin(const Instruction &I)
Check if Branch Weight Metadata has an "expected" field from an llvm.expect* intrinsic.
LLVM_ABI void setBranchWeights(Instruction &I, ArrayRef< uint32_t > Weights, bool IsExpected)
Create a new branch_weights metadata node and add or overwrite a prof metadata reference to instructi...
LLVM_ABI MDNode * getValidBranchWeightMDNode(const Instruction &I)
Get the valid branch weights metadata node.
LLVM_ABI bool hasValidBranchWeightMD(const Instruction &I)
Checks if an instructions has valid Branch Weight Metadata.
FunctionAddr VTableAddr Count
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 void setExplicitlyUnknownFunctionEntryCount(Function &F, StringRef PassName)
Analogous to setExplicitlyUnknownBranchWeights, but for functions and their entry counts.
LLVM_ABI bool isValueProfileMD(const MDNode *ProfileData)
Checks if an MDNode contains value profiling Metadata.
LLVM_ABI unsigned getNumBranchWeights(const MDNode &ProfileData)
LLVM_ABI void extractFromBranchWeightMD32(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Faster version of extractBranchWeights() that skips checks and must only be called with "branch_weigh...
LLVM_ABI bool hasExplicitlyUnknownBranchWeights(const Instruction &I)
LLVM_ABI bool hasProfMD(const Instruction &I)
Checks if an Instruction has MD_prof Metadata.
auto max_element(R &&Range)
Provide wrappers to std::max_element which take ranges instead of having to pass begin/end explicitly...
LLVM_ABI bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
LLVM_ABI const char * LLVMLoopEstimatedTripCount
Profile-based loop metadata that should be accessed only by using llvm::getLoopEstimatedTripCount and...
uint32_t scaleBranchCount(uint64_t Count, uint64_t Scale)
Scale an individual branch count.
LLVM_ABI bool hasBranchWeightMD(const Instruction &I)
Checks if an instructions has Branch Weight Metadata.
uint64_t calculateCountScale(uint64_t MaxCount)
Calculate what to divide by to scale counts.
LLVM_ABI SmallVector< uint32_t > downscaleWeights(ArrayRef< uint64_t > Weights, std::optional< uint64_t > KnownMaxCount=std::nullopt)
downscale the given weights preserving the ratio.
const uint64_t NOMORE_ICP_MAGICNUM
Magic number in the value profile metadata showing a target has been promoted for the instruction and...
LLVM_ABI void scaleProfData(Instruction &I, uint64_t S, uint64_t T)
Scaling the profile data attached to 'I' using the ratio of S/T.
static bool hasCountTypeMD(const Instruction &I)
LLVM_ABI void extractFromBranchWeightMD64(const MDNode *ProfileData, SmallVectorImpl< uint64_t > &Weights)
Faster version of extractBranchWeights() that skips checks and must only be called with "branch_weigh...
static LLVM_ABI const char * ExpectedBranchWeights
static LLVM_ABI const char * SyntheticFunctionEntryCount
static LLVM_ABI const char * BranchWeights
static LLVM_ABI const char * FunctionEntryCount
static LLVM_ABI const char * UnknownBranchWeightsMarker
static LLVM_ABI const char * ValueProfile