================
@@ -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
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits