[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


================
@@ -17,6 +17,72 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
 include "mlir/Interfaces/ViewLikeInterface.td"
 include "mlir/IR/OpAsmInterface.td"
 
+//===----------------------------------------------------------------------===//
+// FromPtrOp
+//===----------------------------------------------------------------------===//
+
+def Ptr_FromPtrOp : Pointer_Op<"from_ptr", [
+    Pure, OptionalTypesMatchWith<"metadata type", "result", "metadata",
+            "PtrMetadataType::get(cast<PtrLikeTypeInterface>($_self))">
+  ]> {
+  let summary = "Casts a `!ptr.ptr` value to a ptr-like value.";
+  let description = [{
+    The `from_ptr` operation casts a `ptr` value to a ptr-like object. It's
+    important to note that:
+    - The ptr-like object cannot be a `!ptr.ptr`.
+    - The memory-space of both the `ptr` and ptr-like object must match.
+    - The cast is Pure (no UB and side-effect free).
+
+    The optional `metadata` operand exists to provide any ptr-like metadata
+    that might be required to perform the cast.
+
+    Example:
+
+    ```mlir
+    %typed_ptr = ptr.from_ptr %ptr : !ptr.ptr<0> -> !my.ptr<f32, 0>
----------------
ftynse wrote:

Nit: can we use named address spaces here and below? I don't remember offhand if the pointer type mandates integer address spaces, and that's something we have been trying to remove from memref.

https://github.com/llvm/llvm-project/pull/137469


More information about the Mlir-commits mailing list