[all-commits] [llvm/llvm-project] 966d17: [mlir][ptr] Add ConstantOp with NullAttr and Addre...

Fabian Mora via All-commits all-commits at lists.llvm.org
Sun Sep 14 06:56:55 PDT 2025


  Branch: refs/heads/users/fabianmcg/ptr-constantop
  Home:   https://github.com/llvm/llvm-project
  Commit: 966d174801809e733017f6940ed46ffbe2a78df0
      https://github.com/llvm/llvm-project/commit/966d174801809e733017f6940ed46ffbe2a78df0
  Author: Fabian Mora <6982088+fabianmcg at users.noreply.github.com>
  Date:   2025-09-14 (Sun, 14 Sep 2025)

  Changed paths:
    M mlir/include/mlir/Dialect/Ptr/IR/PtrAttrDefs.td
    M mlir/include/mlir/Dialect/Ptr/IR/PtrAttrs.h
    M mlir/include/mlir/Dialect/Ptr/IR/PtrOps.td
    M mlir/include/mlir/IR/DialectImplementation.h
    M mlir/lib/Dialect/Ptr/IR/PtrDialect.cpp
    M mlir/lib/Target/LLVMIR/Dialect/Ptr/PtrToLLVMIRTranslation.cpp
    M mlir/test/Dialect/Ptr/ops.mlir
    M mlir/test/Target/LLVMIR/ptr.mlir

  Log Message:
  -----------
  [mlir][ptr] Add ConstantOp with NullAttr and AddressAttr support

This patch introduces the `ptr.constant` operation. It also adds the `NullAttr`
and `AddressAttr` for representing null pointers, and integer raw addresses.

It also implements LLVM IR translation for `ptr.constant` with `#ptr.null` or
`#ptr.address` attributes.

Finally, it extends `FieldParser` to support APInt parsing.

Example:
```mlir
llvm.func @constant_address_op() ->
    !llvm.struct<(!ptr.ptr<#llvm.address_space<0>>,
                  !ptr.ptr<#llvm.address_space<1>>,
                  !ptr.ptr<#llvm.address_space<2>>)> {
  %0 = ptr.constant #ptr.null : !ptr.ptr<#llvm.address_space<0>>
  %1 = ptr.constant #ptr.address<0x1000> : !ptr.ptr<#llvm.address_space<1>>
  %2 = ptr.constant #ptr.address<3735928559> : !ptr.ptr<#llvm.address_space<2>>
  %3 = llvm.mlir.poison : !llvm.struct<(!ptr.ptr<#llvm.address_space<0>>, !ptr.ptr<#llvm.address_space<1>>, !ptr.ptr<#llvm.address_space<2>>)>
  %4 = llvm.insertvalue %0, %3[0] : !llvm.struct<(!ptr.ptr<#llvm.address_space<0>>, !ptr.ptr<#llvm.address_space<1>>, !ptr.ptr<#llvm.address_space<2>>)>
  %5 = llvm.insertvalue %1, %4[1] : !llvm.struct<(!ptr.ptr<#llvm.address_space<0>>, !ptr.ptr<#llvm.address_space<1>>, !ptr.ptr<#llvm.address_space<2>>)>
  %6 = llvm.insertvalue %2, %5[2] : !llvm.struct<(!ptr.ptr<#llvm.address_space<0>>, !ptr.ptr<#llvm.address_space<1>>, !ptr.ptr<#llvm.address_space<2>>)>
  llvm.return %6 : !llvm.struct<(!ptr.ptr<#llvm.address_space<0>>, !ptr.ptr<#llvm.address_space<1>>, !ptr.ptr<#llvm.address_space<2>>)>
}
```
Result of translation to LLVM IR:
```llvm
define { ptr, ptr addrspace(1), ptr addrspace(2) } @constant_address_op() {
  ret { ptr, ptr addrspace(1), ptr addrspace(2) } { ptr null, ptr addrspace(1) inttoptr (i64 4096 to ptr addrspace(1)), ptr addrspace(2) inttoptr (i64 3735928559 to ptr addrspace(2)) }
}
```



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list