43constexpr unsigned WeightsIdx = 1;
46constexpr unsigned MinBWOps = 3;
48bool 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");
70bool 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 ||
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))
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.
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.
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.
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.
bool hasBranchWeightMD(const Instruction &I)
Checks if an instructions has Branch Weight Metadata.