[Mlir-commits] [mlir] [mlir] Accept OpaqueAttr as a valid memory space if the context allows unregistered dialects (PR #187682)

Adam Paszke llvmlistbot at llvm.org
Fri Mar 20 04:42:45 PDT 2026


https://github.com/apaszke created https://github.com/llvm/llvm-project/pull/187682



When a context allows unregistered dialects and an unknown attribute is encountered, it is wrapped in OpaqueAttr from the builtin dialect.

This used to work fine, but recently, MLIR bitcode deserialization started verifying the MemRef types it creates. This causes deserailization errors unless OpaqueAttr is considered a valid memref memory space.

>From 342201e6ca7f58c763f3808349fd9b9fc3700b8c Mon Sep 17 00:00:00 2001
From: Adam Paszke <apaszke at google.com>
Date: Fri, 20 Mar 2026 11:38:24 +0000
Subject: [PATCH] [mlir] Accept OpaqueAttr as a valid memory space if the
 context allows unregistered dialects

When a context allows unregistered dialects and an unknown attribute is encountered,
it is wrapped in OpaqueAttr from the builtin dialect.

This used to work fine, but recently, MLIR bitcode deserialization started verifying
the MemRef types it creates. This causes deserailization errors unless OpaqueAttr is
considered a valid memref memory space.
---
 mlir/lib/IR/BuiltinTypes.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp
index 786c30851a071..0bebbe7aea33a 100644
--- a/mlir/lib/IR/BuiltinTypes.cpp
+++ b/mlir/lib/IR/BuiltinTypes.cpp
@@ -616,6 +616,12 @@ bool mlir::detail::isSupportedMemorySpace(Attribute memorySpace) {
   if (llvm::isa<IntegerAttr, StringAttr, DictionaryAttr>(memorySpace))
     return true;
 
+  // Allow opaque attributes if unregistered dialects are allowed.
+  // They hold unregistered custom dialect attributes.
+  if (memorySpace.getContext()->allowsUnregisteredDialects() &&
+      isa<OpaqueAttr>(memorySpace))
+    return true;
+
   // Allow custom dialect attributes.
   if (!isa<BuiltinDialect>(memorySpace.getDialect()))
     return true;



More information about the Mlir-commits mailing list