[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:30 PDT 2025


================
@@ -110,6 +110,55 @@ def MemRefElementTypeInterface : TypeInterface<"MemRefElementTypeInterface"> {
   }];
 }
 
+//===----------------------------------------------------------------------===//
+// PtrLikeTypeInterface
+//===----------------------------------------------------------------------===//
+
+def PtrLikeTypeInterface : TypeInterface<"PtrLikeTypeInterface"> {
+  let cppNamespace = "::mlir";
+  let description = [{
+    A ptr-like type represents an object storing a memory address. This object
+    is constituted by:
+    - A memory address called the base pointer. The base pointer is an 
+      indivisible object.
----------------
fabianmcg wrote:

> Nit about "indivisible": does this intend to be the same concept as we used for vector types? (So we can use ptr in vectors?). If so, I'd ensure the same term is used in both places and we refer one from another.

I updated to:
```
    - A memory address called the base pointer. This pointer is treated as a
      bag of bits without any assumed structure. The bit-width of the base
      pointer must be a compile-time constant. However, the bit-width may remain
      opaque or unavailable during transformations that do not depend on the
      base pointer. Finally, it is considered indivisible in the sense that as
      a `PtrLikeTypeInterface` value, it has no metadata.
```


> It may also be worth explaining that indivisibility is conceptual for the purpose of reasoning about the program, or something along those lines. Fat pointers, bit-stealing and stuff...

On this point I'm not sure, because that's why the ptr is divided between the base ptr and metadata. For example, I'd argue bit-stealing is metadata, same thing for all the non-address information in fat pointers. So the base ptr is fully indivisible for the interface.

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


More information about the Mlir-commits mailing list