[Mlir-commits] [mlir] [mlir][core|ptr] Add `PtrLikeTypeInterface` and casting ops to the `ptr` dialect (PR #137469)

Fabian Mora llvmlistbot at llvm.org
Fri Jun 6 15:54:31 PDT 2025


================
@@ -52,6 +118,36 @@ def Ptr_PtrAddOp : Pointer_Op<"ptr_add", [
   }];
 }
 
+//===----------------------------------------------------------------------===//
+// ToPtrOp
+//===----------------------------------------------------------------------===//
+
+def Ptr_ToPtrOp : Pointer_Op<"to_ptr", [Pure]> {
+  let summary = "Casts a ptr-like value to a `!ptr.ptr` value.";
+  let description = [{
+    The `to_ptr` operation casts a ptr-like object to a `!ptr.ptr`. It's
+    important to note that:
+    - The ptr-like object cannot be a `!ptr.ptr`.
----------------
fabianmcg wrote:

The idea is that any `!ptr.ptr` to `!ptr.ptr` conversions must happen through other operations, for example, memory space cast. This allows to put a barrier around acceptable casting semantics inside the dialect. The boundary of this barrier is those ops that allow to go to external ptr-like types.

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


More information about the Mlir-commits mailing list