aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Verifier.cpp
diff options
context:
space:
mode:
authorMircea Trofin <mtrofin@google.com>2025-06-30 12:31:19 -0700
committerGitHub <noreply@github.com>2025-06-30 12:31:19 -0700
commit46628718c05abefe23cf6aa5024e4555693565d8 (patch)
treea2cd1392e1b4cf7047b5eb94ac0aa5bebac88f83 /llvm/lib/IR/Verifier.cpp
parent878d3594ed74cd1153bc5cba2cb7a449702cdf34 (diff)
downloadllvm-46628718c05abefe23cf6aa5024e4555693565d8.zip
llvm-46628718c05abefe23cf6aa5024e4555693565d8.tar.gz
llvm-46628718c05abefe23cf6aa5024e4555693565d8.tar.bz2
[IR][PGO] Verify the structure of `VP` metadata. (#145584)
Diffstat (limited to 'llvm/lib/IR/Verifier.cpp')
-rw-r--r--llvm/lib/IR/Verifier.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 96eb4ef..853f3b4 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -112,6 +112,7 @@
#include "llvm/IR/Value.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
+#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/AMDGPUAddrSpace.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/Casting.h"
@@ -5032,9 +5033,27 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
Check(mdconst::dyn_extract<ConstantInt>(MDO),
"!prof brunch_weights operand is not a const int");
}
+ } else if (ProfName == MDProfLabels::ValueProfile) {
+ Check(isValueProfileMD(MD), "invalid value profiling metadata", MD);
+ ConstantInt *KindInt = mdconst::dyn_extract<ConstantInt>(MD->getOperand(1));
+ Check(KindInt, "VP !prof missing kind argument", MD);
+
+ auto Kind = KindInt->getZExtValue();
+ Check(Kind >= InstrProfValueKind::IPVK_First &&
+ Kind <= InstrProfValueKind::IPVK_Last,
+ "Invalid VP !prof kind", MD);
+ Check(MD->getNumOperands() % 2 == 1,
+ "VP !prof should have an even number "
+ "of arguments after 'VP'",
+ MD);
+ if (Kind == InstrProfValueKind::IPVK_IndirectCallTarget ||
+ Kind == InstrProfValueKind::IPVK_MemOPSize)
+ Check(isa<CallBase>(I),
+ "VP !prof indirect call or memop size expected to be applied to "
+ "CallBase instructions only",
+ MD);
} else {
- Check(ProfName == MDProfLabels::ValueProfile,
- "expected either branch_weights or VP profile name", MD);
+ CheckFailed("expected either branch_weights or VP profile name", MD);
}
}