[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:51:22 PDT 2026


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

>From 5eeb0a8de1a3a157634a6e017ba1dddfac89de86 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 ++++++
 mlir/test/IR/parser.mlir     | 6 ++++++
 2 files changed, 12 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;
diff --git a/mlir/test/IR/parser.mlir b/mlir/test/IR/parser.mlir
index 3bb6e38b4d613..a22f788288e5d 100644
--- a/mlir/test/IR/parser.mlir
+++ b/mlir/test/IR/parser.mlir
@@ -127,6 +127,12 @@ func.func private @memrefs_nomap_dictspace(memref<5x6x7xf32, {memSpace = "specia
 // CHECK: func private @memrefs_map_dictspace(memref<5x6x7xf32, #map{{[0-9]*}}, {memSpace = "special", subIndex = 3 : i64}>)
 func.func private @memrefs_map_dictspace(memref<5x6x7xf32, #map3, {memSpace = "special", subIndex = 3}>)
 
+// CHECK: func private @memrefs_nomap_opaquespace(memref<5x6x7xf32, #unknown_dialect.unknown_attr>)
+func.func private @memrefs_nomap_opaquespace(memref<5x6x7xf32, #unknown_dialect.unknown_attr>)
+
+// CHECK: func private @memrefs_map_opaquespace(memref<5x6x7xf32, #map{{[0-9]*}}, #unknown_dialect.unknown_attr>)
+func.func private @memrefs_map_opaquespace(memref<5x6x7xf32, #map3, #unknown_dialect.unknown_attr>)
+
 // CHECK: func private @complex_types(complex<i1>) -> complex<f32>
 func.func private @complex_types(complex<i1>) -> complex<f32>
 



More information about the Mlir-commits mailing list