[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:20:20 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:
What can you do with a metadata SSA value? In particular, are there ways to construct a metadata object? (apart from `get_metadata`)
https://github.com/llvm/llvm-project/pull/137469
More information about the Mlir-commits
mailing list