aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Verifier.cpp
diff options
context:
space:
mode:
authorPaul Kirth <paulkirth@google.com>2024-06-24 15:17:40 -0700
committerGitHub <noreply@github.com>2024-06-24 15:17:40 -0700
commita3a44bfbdfefe0928124f9e40d242507f75b87f4 (patch)
treefdf8b8308c35be72b861414a9e3c3adc1ae7ffe9 /llvm/lib/IR/Verifier.cpp
parent75ac887a3033c6e4eb8e423a78490c8d4bf7d5b5 (diff)
downloadllvm-a3a44bfbdfefe0928124f9e40d242507f75b87f4.zip
llvm-a3a44bfbdfefe0928124f9e40d242507f75b87f4.tar.gz
llvm-a3a44bfbdfefe0928124f9e40d242507f75b87f4.tar.bz2
[llvm][ProfDataUtils] Provide getNumBranchWeights API (#90146)
As suggested in https://github.com/llvm/llvm-project/pull/86609/files#r1556689262 an API for getting the number of branch weights directly from the MD node would be useful in a variety of checks, and keeps the logic within ProfDataUtils.
Diffstat (limited to 'llvm/lib/IR/Verifier.cpp')
-rw-r--r--llvm/lib/IR/Verifier.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 0abd5f7..c98f61d 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -4818,10 +4818,9 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
// Check consistency of !prof branch_weights metadata.
if (ProfName == "branch_weights") {
- unsigned int Offset = getBranchWeightOffset(MD);
+ unsigned NumBranchWeights = getNumBranchWeights(*MD);
if (isa<InvokeInst>(&I)) {
- Check(MD->getNumOperands() == (1 + Offset) ||
- MD->getNumOperands() == (2 + Offset),
+ Check(NumBranchWeights == 1 || NumBranchWeights == 2,
"Wrong number of InvokeInst branch_weights operands", MD);
} else {
unsigned ExpectedNumOperands = 0;
@@ -4841,10 +4840,11 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
CheckFailed("!prof branch_weights are not allowed for this instruction",
MD);
- Check(MD->getNumOperands() == Offset + ExpectedNumOperands,
- "Wrong number of operands", MD);
+ Check(NumBranchWeights == ExpectedNumOperands, "Wrong number of operands",
+ MD);
}
- for (unsigned i = Offset; i < MD->getNumOperands(); ++i) {
+ for (unsigned i = getBranchWeightOffset(MD); i < MD->getNumOperands();
+ ++i) {
auto &MDO = MD->getOperand(i);
Check(MDO, "second operand should not be null", MD);
Check(mdconst::dyn_extract<ConstantInt>(MDO),