[Mlir-commits] [mlir] [MLIR][LLVM] Add function metadata to LLVMFuncOp (PR #203018)

Tobias Gysi llvmlistbot at llvm.org
Tue Aug 11 22:08:08 PDT 2026


================
@@ -135,6 +135,24 @@ bool AddressSpaceAttr::isValidPtrIntCast(
   return false;
 }
 
+//===----------------------------------------------------------------------===//
+// FunctionMetadataAttr
+//===----------------------------------------------------------------------===//
+
+LogicalResult
+FunctionMetadataAttr::verify(function_ref<InFlightDiagnostic()> emitError,
+                             StringAttr metadataName, MDNodeAttr node) {
+  (void)node;
+  StringRef name = metadataName.getValue();
+  if (name.empty())
+    return emitError() << "function_metadata entry name must not be empty";
+  if (name == "dbg" || name == "prof") {
----------------
gysit wrote:

In other places where LLVM dialect has multiple ways to express things (for example intrinsics can be represented by an explicit op or a call) we usually allow both formats and leave it on the import to decide what to prefer. We could consider todo the same here, or are you sure that these two kinds are the only ones that may show up here? 

If we want to keep the verification, I would suggest to try to avoid the magic strings somehow. Could we do something along these lines:
```
static constexpr unsigned kReservedFunctionMetadataKinds[] = {
    llvm::LLVMContext::MD_dbg, llvm::LLVMContext::MD_prof};

// ...

if (llvm::any_of(kReservedFunctionMetadataKinds, [&](unsigned kind) {
      return name == getFixedMetadataKindName(kind);
    }))
  return emitError() << "reserved function_metadata entry '" << name
                     << "' must use a dedicated LLVM dialect representation";
```

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


More information about the Mlir-commits mailing list