44constexpr unsigned WeightsIdx = 1;
47constexpr unsigned MinBWOps = 3;
51bool isTargetMD(
const MDNode *ProfData,
const char *
Name,
unsigned MinOps) {
54 if (!ProfData || !
Name || MinOps < 2)
61 auto *ProfDataName = dyn_cast<MDString>(ProfData->
getOperand(0));
65 return ProfDataName->getString().equals(
Name);
73 return nullptr !=
I.getMetadata(LLVMContext::MD_prof);
77 return isTargetMD(ProfileData,
"branch_weights", MinBWOps);
81 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
90 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
98 if (ProfileData && ProfileData->getNumOperands() == 1 +
I.getNumSuccessors())
108 assert(WeightsIdx < NOps &&
"Weights Index must be less than NOps.");
109 Weights.
resize(NOps - WeightsIdx);
111 for (
unsigned Idx = WeightsIdx,
E = NOps;
Idx !=
E; ++
Idx) {
113 mdconst::dyn_extract<ConstantInt>(ProfileData->
getOperand(
Idx));
114 assert(Weight &&
"Malformed branch_weight in MD_prof node");
116 "Too many bits for uint32_t");
131 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
137 assert((
I.getOpcode() == Instruction::Br ||
138 I.getOpcode() == Instruction::Select) &&
139 "Looking for branch weights on something besides branch, select, or "
143 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
147 if (Weights.
size() > 2)
150 TrueVal = Weights[0];
151 FalseVal = Weights[1];
160 auto *ProfDataName = dyn_cast<MDString>(ProfileData->
getOperand(0));
164 if (ProfDataName->getString().equals(
"branch_weights")) {
166 auto *V = mdconst::dyn_extract<ConstantInt>(ProfileData->
getOperand(
Idx));
167 assert(V &&
"Malformed branch_weight in MD_prof node");
168 TotalVal += V->getValue().getZExtValue();
173 if (ProfDataName->getString().equals(
"VP") &&
175 TotalVal = mdconst::dyn_extract<ConstantInt>(ProfileData->
getOperand(2))
190 I.setMetadata(LLVMContext::MD_prof, BranchWeights);
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file contains the declarations for profiling metadata utility functions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
unsigned getActiveBits() const
Compute the number of active bits in the 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.
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight)
Return metadata containing two branch weights.
const MDOperand & getOperand(unsigned I) const
unsigned getNumOperands() const
Return number of MDNode operands.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This is an optimization pass for GlobalISel generic memory operations.
bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalWeights)
Retrieve the total of all weights from MD_prof data.
bool isBranchWeightMD(const MDNode *ProfileData)
Checks if an MDNode contains Branch Weight Metadata.
MDNode * getBranchWeightMDNode(const Instruction &I)
Get the branch weights metadata node.
void setBranchWeights(Instruction &I, ArrayRef< uint32_t > Weights)
Create a new branch_weights metadata node and add or overwrite a prof metadata reference to instructi...
MDNode * getValidBranchWeightMDNode(const Instruction &I)
Get the valid branch weights metadata node.
bool hasValidBranchWeightMD(const Instruction &I)
Checks if an instructions has valid Branch Weight Metadata.
bool hasProfMD(const Instruction &I)
Checks if an Instruction has MD_prof Metadata.
bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
void extractFromBranchWeightMD(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Faster version of extractBranchWeights() that skips checks and must only be called with "branch_weigh...
bool hasBranchWeightMD(const Instruction &I)
Checks if an instructions has Branch Weight Metadata.