[llvm] [IR][PGO] Verify the structure of `VP` metadata. (PR #145584)

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 08:56:18 PDT 2025


================
@@ -5026,9 +5027,25 @@ 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'");
----------------
teresajohnson wrote:

This looks like a good suggestion

https://github.com/llvm/llvm-project/pull/145584


More information about the llvm-commits mailing list