[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:16:36 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(); }
+
+//===----------------------------------------------------------------------===//
+// TypeOffsetOp
+//===----------------------------------------------------------------------===//
+
+OpFoldResult TypeOffsetOp::fold(FoldAdaptor adaptor) {
+ return TypeAttr::get(getElementType());
----------------
joker-eph wrote:
I don't quite get what this is?
https://github.com/llvm/llvm-project/pull/136434
More information about the Mlir-commits
mailing list