[llvm-branch-commits] [llvm][IR] Extend BranchWeightMetadata to track provenance of weights (PR #86609)
Matthias Braun via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Apr 8 18:28:40 PDT 2024
================
@@ -106,6 +104,30 @@ bool hasValidBranchWeightMD(const Instruction &I) {
return getValidBranchWeightMDNode(I);
}
+bool hasExpectedProvenance(const Instruction &I) {
+ auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
+ return hasExpectedProvenance(ProfileData);
+}
+
+bool hasExpectedProvenance(const MDNode *ProfileData) {
+ if (!isBranchWeightMD(ProfileData))
+ return false;
+
+ auto *ProfDataName = dyn_cast<MDString>(ProfileData->getOperand(1));
+ if (!ProfDataName)
+ return false;
+ return ProfDataName->getString().equals("expected");
+}
+
+unsigned getBranchWeightOffset(const Instruction &I) {
+ auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
+ return getBranchWeightOffset(ProfileData);
+}
+
+unsigned getBranchWeightOffset(const MDNode *ProfileData) {
+ return hasExpectedProvenance(ProfileData) ? 2 : 1;
+}
----------------
MatzeB wrote:
What about a `hasBranchWeightProvenance()` API instead that just checks whether there is a string? That way you would get the same effect today but can skip the string comparison (and maybe get better behavior if there is a string that isn't actually "expected")
https://github.com/llvm/llvm-project/pull/86609
More information about the llvm-branch-commits
mailing list