Go to the documentation of this file.
43 constexpr
unsigned WeightsIdx = 1;
46 constexpr
unsigned MinBWOps = 3;
48 bool extractWeights(
const MDNode *ProfileData,
51 assert(ProfileData &&
"ProfileData was nullptr in extractWeights");
54 assert(WeightsIdx < NOps &&
"Weights Index must be less than NOps.");
55 Weights.
resize(NOps - WeightsIdx);
57 for (
unsigned Idx = WeightsIdx,
E = NOps; Idx !=
E; ++Idx) {
59 mdconst::dyn_extract<ConstantInt>(ProfileData->
getOperand(Idx));
60 assert(Weight &&
"Malformed branch_weight in MD_prof node");
62 "Too many bits for uint32_t");
70 bool isTargetMD(
const MDNode *ProfData,
const char *Name,
unsigned MinOps) {
73 if (!ProfData || !Name || MinOps < 2)
80 auto *ProfDataName = dyn_cast<MDString>(ProfData->
getOperand(0));
84 return ProfDataName->getString().equals(Name);
92 return nullptr !=
I.getMetadata(LLVMContext::MD_prof);
96 return isTargetMD(ProfileData,
"branch_weights", MinBWOps);
100 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
109 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
117 if (ProfileData && ProfileData->
getNumOperands() == 1 +
I.getNumSuccessors())
126 return extractWeights(ProfileData, Weights);
131 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
137 assert((
I.getOpcode() == Instruction::Br ||
139 "Looking for branch weights on something besides branch, select, or "
143 auto *ProfileData =
I.getMetadata(LLVMContext::MD_prof);
147 if (Weights.size() > 2)
160 auto *ProfDataName = dyn_cast<MDString>(ProfileData->
getOperand(0));
164 if (ProfDataName->getString().equals(
"branch_weights")) {
165 for (
unsigned Idx = 1; Idx < ProfileData->
getNumOperands(); Idx++) {
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))
This is an optimization pass for GlobalISel generic memory operations.
bool isBranchWeightMD(const MDNode *ProfileData)
Checks if an MDNode contains Branch Weight Metadata.
const APInt & getValue() const
Return the constant as an APInt value reference.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
unsigned getNumOperands() const
Return number of MDNode operands.
This is the shared class of boolean and integer constants.
bool hasValidBranchWeightMD(const Instruction &I)
Checks if an instructions has valid Branch Weight Metadata.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool hasBranchWeightMD(const Instruction &I)
Checks if an instructions has Branch Weight Metadata.
const MDOperand & getOperand(unsigned I) const
bool hasProfMD(const Instruction &I)
Checks if an Instruction has MD_prof Metadata.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalWeights)
Retrieve the total of all weights from MD_prof data.
MDNode * getValidBranchWeightMDNode(const Instruction &I)
Get the valid branch weights metadata node.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
MDNode * getBranchWeightMDNode(const Instruction &I)
Get the branch weights metadata node.
unsigned getActiveBits() const
Compute the number of active bits in the value.
bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.