[llvm-branch-commits] [llvm] [IR][PGO] Verify the structure of `VP` metadata. (PR #145584)
Mircea Trofin via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jun 25 08:08:10 PDT 2025
https://github.com/mtrofin updated https://github.com/llvm/llvm-project/pull/145584
>From 591bfc27c2de4a140301100afbbdea1d5a14e39c Mon Sep 17 00:00:00 2001
From: Mircea Trofin <mtrofin at google.com>
Date: Tue, 24 Jun 2025 13:14:09 -0700
Subject: [PATCH] [IR][PGO] Verify the structure of `VP` metadata.
---
llvm/include/llvm/IR/ProfDataUtils.h | 3 +++
llvm/lib/IR/ProfDataUtils.cpp | 2 +-
llvm/lib/IR/Verifier.cpp | 9 +++++++--
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/IR/ProfDataUtils.h b/llvm/include/llvm/IR/ProfDataUtils.h
index 8e8d069b836f1..55b84abbbeb23 100644
--- a/llvm/include/llvm/IR/ProfDataUtils.h
+++ b/llvm/include/llvm/IR/ProfDataUtils.h
@@ -28,6 +28,9 @@ LLVM_ABI bool hasProfMD(const Instruction &I);
/// Checks if an MDNode contains Branch Weight Metadata
LLVM_ABI bool isBranchWeightMD(const MDNode *ProfileData);
+/// Checks if an MDNode contains value profiling Metadata
+LLVM_ABI bool isValueProfileMD(const MDNode *ProfileData);
+
/// Checks if an instructions has Branch Weight Metadata
///
/// \param I The instruction to check
diff --git a/llvm/lib/IR/ProfDataUtils.cpp b/llvm/lib/IR/ProfDataUtils.cpp
index 21524eb840539..914535b599586 100644
--- a/llvm/lib/IR/ProfDataUtils.cpp
+++ b/llvm/lib/IR/ProfDataUtils.cpp
@@ -96,7 +96,7 @@ bool isBranchWeightMD(const MDNode *ProfileData) {
return isTargetMD(ProfileData, "branch_weights", MinBWOps);
}
-static bool isValueProfileMD(const MDNode *ProfileData) {
+bool isValueProfileMD(const MDNode *ProfileData) {
return isTargetMD(ProfileData, "VP", MinVPOps);
}
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index ae95e3e2bff8d..c6f8ea78c04d5 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5008,9 +5008,14 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
Check(mdconst::dyn_extract<ConstantInt>(MDO),
"!prof brunch_weights operand is not a const int");
}
- } else {
- Check(ProfName == "VP", "expected either branch_weights or VP profile name",
+ } else if (ProfName == "VP") {
+ Check(isValueProfileMD(MD),"invalid value profiling metadata",MD);
+ Check(isa<CallBase>(I),
+ "value profiling !prof metadata is expected to be placed on call "
+ "instructions (which may be memops)",
MD);
+ } else {
+ CheckFailed("expected either branch_weights or VP profile name", MD);
}
}
More information about the llvm-branch-commits
mailing list