[llvm] [IR] Composable and Extensible Memory Cache Control Hints (PR #181612)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 23 02:53:31 PDT 2026
================
@@ -5631,6 +5632,66 @@ void Verifier::visitInlineHistoryMetadata(Instruction &I, MDNode *MD) {
}
}
+void Verifier::visitMemCacheHintMetadata(Instruction &I, MDNode *MD) {
+ Check(I.mayReadOrWriteMemory(),
+ "!mem.cache_hint is only valid on memory operations", &I);
+
+ Check(MD->getNumOperands() % 2 == 0,
+ "!mem.cache_hint must have even number of operands "
+ "(operand_no, hint_node pairs)",
+ MD);
+
+ const auto *CB = dyn_cast<CallBase>(&I);
+ if (CB)
+ Check(CB->getIntrinsicID() != Intrinsic::not_intrinsic,
+ "!mem.cache_hint is not supported on non-intrinsic calls", &I);
+
+ unsigned NumOperands = CB ? CB->arg_size() : I.getNumOperands();
+
+ SmallDenseSet<unsigned, 4> SeenOperandNos;
+
+ // Top-level metadata alternates: i32 operand_no, MDNode hint_node.
+ for (unsigned i = 0; i + 1 < MD->getNumOperands(); i += 2) {
+ auto *OpNoCI = mdconst::dyn_extract<ConstantInt>(MD->getOperand(i));
+ Check(OpNoCI,
+ "!mem.cache_hint operand_no must be an integer constant in pair", MD);
+
+ Check(OpNoCI->getValue().isNonNegative(),
+ "!mem.cache_hint operand_no must be non-negative", MD);
+
+ uint64_t OperandNo = OpNoCI->getZExtValue();
+ Check(OperandNo < NumOperands, "!mem.cache_hint operand_no is out of range",
+ &I);
+
+ Value *Operand =
+ CB ? CB->getArgOperand(OperandNo) : I.getOperand(OperandNo);
+ Check(Operand->getType()->isPtrOrPtrVectorTy(),
+ "!mem.cache_hint operand_no must refer to a pointer operand", &I);
+
+ Check(SeenOperandNos.insert(OperandNo).second,
+ "!mem.cache_hint contains duplicate operand_no", MD);
+
+ const auto *Node = dyn_cast<MDNode>(MD->getOperand(i + 1));
+ Check(Node, "!mem.cache_hint hint node must be a metadata node", MD);
+
+ Check(Node->getNumOperands() % 2 == 0,
+ "!mem.cache_hint hint node must have even number of operands "
+ "(key-value pairs)",
+ Node);
+
+ SmallDenseSet<StringRef, 8> SeenKeys;
----------------
antoniofrighetto wrote:
I would use a StringSet here, but not strong.
https://github.com/llvm/llvm-project/pull/181612
More information about the llvm-commits
mailing list