[all-commits] [llvm/llvm-project] 1a65e6: [mlir][ptr] Add ConstantOp with NullAttr and Addre...
Fabian Mora via All-commits
all-commits at lists.llvm.org
Sun Sep 14 08:45:21 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 1a65e63c596d9459f49e4495e92cdecac2795f71
https://github.com/llvm/llvm-project/commit/1a65e63c596d9459f49e4495e92cdecac2795f71
Author: Fabian Mora <fmora.dev at gmail.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 (#157347)
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)) }
}
```
This patch also changes all the `convert*` occurrences in function names
or comments to `translate` in the PtrToLLVM file.
---------
Co-authored-by: Mehdi Amini <joker.eph at gmail.com>
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