[Mlir-commits] [mlir] 4388400 - [mlir] Remove the memory space attribute restriction on memref types (#222995)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Sep 11 23:48:46 PDT 2026
Author: Benjamin Chetioui
Date: 2026-09-12T08:48:40+02:00
New Revision: 4388400c3d0a95b75a36f81c7edd2eb95c6d63ea
URL: https://github.com/llvm/llvm-project/commit/4388400c3d0a95b75a36f81c7edd2eb95c6d63ea
DIFF: https://github.com/llvm/llvm-project/commit/4388400c3d0a95b75a36f81c7edd2eb95c6d63ea.diff
LOG: [mlir] Remove the memory space attribute restriction on memref types (#222995)
Follow-up to #187682. `isSupportedMemorySpace` only rejected builtin
attributes other than IntegerAttr/StringAttr/DictionaryAttr. This is a
leftover from when memory spaces were restricted to integers, and is now
inconsistent.
Added:
Modified:
mlir/include/mlir/IR/BuiltinTypes.td
mlir/lib/IR/BuiltinTypes.cpp
mlir/lib/IR/TypeDetail.h
mlir/test/IR/invalid-builtin-types.mlir
mlir/test/IR/parser.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/BuiltinTypes.td b/mlir/include/mlir/IR/BuiltinTypes.td
index d5d53dc8b9532..ffb0e542153ee 100644
--- a/mlir/include/mlir/IR/BuiltinTypes.td
+++ b/mlir/include/mlir/IR/BuiltinTypes.td
@@ -894,7 +894,8 @@ def Builtin_MemRef : Builtin_Type<"MemRef", "memref", [
form which is converted to a semi-affine map automatically.
The memory space of a memref is specified by a target-specific attribute.
- It might be an integer value, string, dictionary or custom dialect attribute.
+ It might be an integer value, string, dictionary or custom dialect
+ attribute; no restriction is placed on the kind of attribute used.
The empty memory space (attribute is None) is target specific.
The notionally dynamic value of a memref value includes the address of the
diff --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp
index 1608b245686e2..36353edf15bc7 100644
--- a/mlir/lib/IR/BuiltinTypes.cpp
+++ b/mlir/lib/IR/BuiltinTypes.cpp
@@ -608,28 +608,6 @@ mlir::isRankReducedType(ShapedType originalType,
return SliceVerificationResult::Success;
}
-bool mlir::detail::isSupportedMemorySpace(Attribute memorySpace) {
- // Empty attribute is allowed as default memory space.
- if (!memorySpace)
- return true;
-
- // Supported built-in attributes.
- 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;
-
- return false;
-}
-
Attribute mlir::detail::wrapIntegerMemorySpace(unsigned memorySpace,
MLIRContext *ctx) {
if (memorySpace == 0)
@@ -785,9 +763,6 @@ LogicalResult MemRefType::verify(function_ref<InFlightDiagnostic()> emitError,
if (failed(layout.verifyLayout(shape, emitError)))
return failure();
- if (!isSupportedMemorySpace(memorySpace))
- return emitError() << "unsupported memory space Attribute";
-
return success();
}
@@ -914,9 +889,6 @@ UnrankedMemRefType::verify(function_ref<InFlightDiagnostic()> emitError,
if (!BaseMemRefType::isValidElementType(elementType))
return emitError() << "invalid memref element type";
- if (!isSupportedMemorySpace(memorySpace))
- return emitError() << "unsupported memory space Attribute";
-
return success();
}
diff --git a/mlir/lib/IR/TypeDetail.h b/mlir/lib/IR/TypeDetail.h
index 0e952d5c14c7e..36620ae15b7f4 100644
--- a/mlir/lib/IR/TypeDetail.h
+++ b/mlir/lib/IR/TypeDetail.h
@@ -135,9 +135,6 @@ struct TupleTypeStorage final
unsigned numElements;
};
-/// Checks if the memorySpace has supported Attribute type.
-bool isSupportedMemorySpace(Attribute memorySpace);
-
/// Wraps deprecated integer memory space to the new Attribute form.
Attribute wrapIntegerMemorySpace(unsigned memorySpace, MLIRContext *ctx);
diff --git a/mlir/test/IR/invalid-builtin-types.mlir b/mlir/test/IR/invalid-builtin-types.mlir
index ef3412486d9f4..8207b183e4a5d 100644
--- a/mlir/test/IR/invalid-builtin-types.mlir
+++ b/mlir/test/IR/invalid-builtin-types.mlir
@@ -33,10 +33,6 @@ func.func @memrefs(memref<2x4xi8, >) // expected-error {{expected list element}}
// Test non-existent map in memref type.
func.func @memrefs(memref<2x4xi8, #map7>) // expected-error {{undefined symbol alias id 'map7'}}
-// -----
-// Test unsupported memory space.
-func.func @memrefs(memref<2x4xi8, i8>) // expected-error {{unsupported memory space Attribute}}
-
// -----
// Test non-existent map in map composition of memref type.
#map0 = affine_map<(d0, d1) -> (d0, d1)>
diff --git a/mlir/test/IR/parser.mlir b/mlir/test/IR/parser.mlir
index 6cd07f616540f..f3f63786199ec 100644
--- a/mlir/test/IR/parser.mlir
+++ b/mlir/test/IR/parser.mlir
@@ -133,6 +133,12 @@ func.func private @memrefs_nomap_opaquespace(memref<5x6x7xf32, #unknown_dialect.
// 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 @memrefs_nomap_typespace(memref<5x6x7xf32, i8>)
+func.func private @memrefs_nomap_typespace(memref<5x6x7xf32, i8>)
+
+// CHECK: func private @memrefs_map_typespace(memref<5x6x7xf32, #map{{[0-9]*}}, i8>)
+func.func private @memrefs_map_typespace(memref<5x6x7xf32, #map3, i8>)
+
// 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