[Mlir-commits] [mlir] [mlir][core|ptr] Add `PtrLikeTypeInterface` and casting ops to the `ptr` dialect (PR #137469)
Matthias Springer
llvmlistbot at llvm.org
Sun Apr 27 04:22:58 PDT 2025
================
@@ -63,6 +64,54 @@ def Ptr_PtrType : Ptr_Type<"Ptr", "ptr", [
return $_get(memorySpace.getContext(), memorySpace);
}]>
];
+ let extraClassDeclaration = [{
+ // `PtrLikeTypeInterface` interface methods.
+ /// Returns `Type()` as this pointer type is opaque.
+ Type getElementType() const {
+ return Type();
+ }
+ /// Clones the pointer with specified memory space or returns failure
+ /// if an `elementType` was specified or if the memory space doesn't
+ /// implement `MemorySpaceAttrInterface`.
+ FailureOr<PtrLikeTypeInterface> clonePtrWith(Attribute memorySpace,
+ std::optional<Type> elementType) const {
+ if (elementType)
+ return failure();
+ if (auto ms = dyn_cast<MemorySpaceAttrInterface>(memorySpace))
+ return cast<PtrLikeTypeInterface>(get(ms));
+ return failure();
+ }
+ /// `!ptr.ptr` types are seen as ptr-like objects with no metadata.
+ bool hasPtrMetadata() const {
+ return false;
+ }
+ }];
+}
+
+def Ptr_PtrMetadata : Ptr_Type<"PtrMetadata", "ptr_metadata"> {
----------------
matthias-springer wrote:
Also, is there a way to extract the sizes, strides, offset from a `!ptr.ptr_metadata<memref<?x?xf32>>`. Such an operation would presumably have to be added to the `memref` dialect? Can the `memref` dialect depend on the `ptr` dialect?
https://github.com/llvm/llvm-project/pull/137469
More information about the Mlir-commits
mailing list