[llvm] [Verifier] Add checks for loop metadata nodes (PR #182252)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 19 05:52:10 PST 2026
================
@@ -1145,6 +1146,61 @@ void Verifier::visitMDNode(const MDNode &MD, AreDebugLocsAllowed AllowLocs) {
Check(MD.isResolved(), "All nodes should be resolved!", &MD);
}
+// Loop attributes that require exactly two operands (name + i1).
+static const char *const LoopBooleanAttributeNames[] = {
+ "llvm.loop.distribute.enable",
+ "llvm.loop.vectorize.enable",
+};
+
+// Loop attributes that allow only a single operand (just the name).
+// TODO: This is not an exhaustive list and can also include attributes
+// like llvm.loop.licm_versioning.disable.
+static const char *const LoopSingleOperandAttributeNames[] = {
+ "llvm.loop.unroll.disable",
+ "llvm.loop.unroll.enable",
+ "llvm.loop.unroll.full",
+ "llvm.loop.unroll_and_jam.enable",
+ "llvm.loop.unroll_and_jam.disable",
+};
+
+void Verifier::verifyLoopMetadata(const MDNode *LoopID) {
+ // Allow empty loop metadata (!{}) so the verifier does not crash on malformed
+ // IR; skip further checks.
+ if (LoopID->getNumOperands() == 0)
+ return;
+ Check(LoopID->getNumOperands() >= 1,
+ "llvm.loop metadata must have at least one operand", LoopID);
+ for (const MDOperand &Op : llvm::drop_begin(LoopID->operands())) {
+ MDNode *Option = dyn_cast<MDNode>(Op);
+ if (!Option || Option->getNumOperands() < 1)
+ continue;
+ MDString *Name = dyn_cast<MDString>(Option->getOperand(0));
+ if (!Name)
+ continue;
+ StringRef AttrName = Name->getString();
+
+ // Verify single-operand attributes.
+ if (llvm::is_contained(LoopSingleOperandAttributeNames, AttrName)) {
+ Check(Option->getNumOperands() == 1,
+ "llvm.loop attribute must have exactly one operand", Option);
----------------
arsenm wrote:
This isn't an attribute, don't call it one
https://github.com/llvm/llvm-project/pull/182252
More information about the llvm-commits
mailing list