[Mlir-commits] [mlir] [mlir][ptr] Add the `ptradd` and `type_offset` ops, and `int_space` attr (PR #136434)

Fabian Mora llvmlistbot at llvm.org
Sun Apr 20 05:55:28 PDT 2025


================
@@ -11,7 +11,78 @@
 
 include "mlir/Dialect/Ptr/IR/PtrDialect.td"
 include "mlir/Dialect/Ptr/IR/PtrAttrDefs.td"
+include "mlir/Dialect/Ptr/IR/PtrEnums.td"
 include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.td"
+include "mlir/Interfaces/SideEffectInterfaces.td"
+include "mlir/Interfaces/ViewLikeInterface.td"
 include "mlir/IR/OpAsmInterface.td"
 
+//===----------------------------------------------------------------------===//
+// PtrAddOp
+//===----------------------------------------------------------------------===//
+
+def Ptr_PtrAddOp : Pointer_Op<"ptradd", [
+    Pure, AllTypesMatch<["base", "result"]>,
+    DeclareOpInterfaceMethods<ViewLikeOpInterface>
+  ]> {
+  let summary = "Pointer add operation";
+  let description = [{
+    The `ptradd` operation adds an integer offset to a pointer to produce a new
+    pointer. The input and output pointer types are always the same.
+
+    Example:
+
+    ```mlir
+    %x_off  = ptr.ptradd %x, %off : !ptr.ptr<0>, i32
+    %x_off0 = ptr.ptradd nusw %x, %off : !ptr.ptr<0>, i32
+    ```
+  }];
+
+  let arguments = (ins
+    Ptr_PtrType:$base,
+    AnySignlessIntegerOrIndex:$offset,
+    DefaultValuedAttr<Ptr_PtrAddFlags,
+        "::mlir::ptr::PtrAddFlags::none">:$flags);
+  let results = (outs Ptr_PtrType:$result);
+  let assemblyFormat = [{
+    ($flags^)? $base `,` $offset attr-dict `:` type($base) `,` type($offset)
+  }];
+  let hasFolder = 1;
+}
+
+//===----------------------------------------------------------------------===//
+// TypeOffsetOp
+//===----------------------------------------------------------------------===//
+
+def Ptr_TypeOffsetOp : Pointer_Op<"type_offset", [ConstantLike, Pure]> {
+  let summary = "Type offset operation";
+  let description = [{
+    The `type_offset` operation produces an int or index-typed SSA value
+    equal to a target-specific constant representing the offset of a single
+    element of the given type.
----------------
fabianmcg wrote:

I would argue no. However, the `DataLayout` makes it independent, as the layout doesn't distinguish sizes by memory space (either LLVM or MLIR's). Therefore, until we don't have the support on the layout it's independent.

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


More information about the Mlir-commits mailing list