[Mlir-commits] [mlir] [mlir][LLVM] Add support for constant struct with multiple fields (PR #102752)
Tobias Gysi
llvmlistbot at llvm.org
Tue Aug 13 00:22:49 PDT 2024
gysit wrote:
> The layout of a P2MF is ABI-specific and currently we're focusing on the Itanium ABI which defines the layout as something like struct { intptr_t, ptrdiff_t }. The two members are both integers, but their types may differ.
I would expect that once you are at the LLVM dialect level you probably want to know the size of these integers (e.g. by querying the data layout)? So from an LLVM dialect point of view the problem is about a simple struct with two integer elements?
> This makes a lot sense and the pointer problem indeed renders a complete support for arbitrary struct impossible. But for the pointer problem, IMHO it is not really related to the changes here -- you can't produce a constant pointer scalar via llvm.mlir.constant either, could you? LLVM itself does not have pointer constants (other than null pointer constants) and that's a more related problem IMO. Besides, llvm.mlir.constant is already being used for creating aggregates like vectors (but not arrays or structs yet). So one of the motivation of this PR is that I would expect llvm.mlir.constant to be able to produce any constant value supported by LLVM.
A nullptr is represented by:
`%1 = llvm.mlir.zero : !llvm.ptr`
There are similar operations for undef / poison values (not just pointers).
I am not completely opposed to supporting constant structs. If we do it, we need have a proper verifier and the documentation should clearly specify what kind of structs are supported. E.g. we could initially support structs without pointers and without nesting.
I just wanted to point out that there are already alternative ways to express struct constants that work out of the box and that support arbitrary structs. The advantage of your PR is mainly that it simplifies generating struct constants and that folding is potentially easier.
https://github.com/llvm/llvm-project/pull/102752
More information about the Mlir-commits
mailing list