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

Mehdi Amini llvmlistbot at llvm.org
Sun Apr 20 05:15:57 PDT 2025


================
@@ -39,6 +41,37 @@ void PtrDialect::initialize() {
       >();
 }
 
+//===----------------------------------------------------------------------===//
+// PtrAddOp
+//===----------------------------------------------------------------------===//
+
+/// Fold the op to the base ptr when the offset is 0.
+OpFoldResult PtrAddOp::fold(FoldAdaptor adaptor) {
+  Attribute attr = adaptor.getOffset();
+  if (!attr)
+    return nullptr;
+  if (llvm::APInt value; m_ConstantInt(&value).match(attr) && value.isZero())
+    return getBase();
+  return nullptr;
+}
+
+Value PtrAddOp::getViewSource() { return getBase(); }
----------------
joker-eph wrote:

Why out of line? Can this be in the header?

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


More information about the Mlir-commits mailing list