[Mlir-commits] [mlir] [mlir][core|ptr] Add `PtrLikeTypeInterface` and casting ops to the `ptr` dialect (PR #137469)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Thu Jun 5 14:02:35 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"> {
+ let summary = "Pointer metadata type";
+ let description = [{
+ The `ptr_metadata` type represents an opaque-view of the metadata associated
+ with a `ptr-like` object type.
+ It's an error to get a `ptr_metadata` using `ptr-like` type with no
+ metadata.
----------------
ftynse wrote:
Could you clarify what you mean by it being an error? Such a type must not be constructible? Is there a diagnostic? Assertion?
https://github.com/llvm/llvm-project/pull/137469
More information about the Mlir-commits
mailing list