[Mlir-commits] [mlir] [mlir][LLVM] Add support for constant struct with multiple fields (PR #102752)
Sirui Mu
llvmlistbot at llvm.org
Tue Aug 13 00:07:14 PDT 2024
Lancern wrote:
@gysit Thanks for your helpful comment on this topic!
> Can you elaborate on the use case for this change?
Well my actual use case is rather minor compared to the proposed changes here. I'm working on [clangir](https://github.com/llvm/clangir) which provides an MLIR dialect for modeling C/C++ language semantics, and recently I'm trying to work out the appropriate LLVMIR for [pointers to member functions (P2MF)](https://en.cppreference.com/w/cpp/language/pointer#Pointers_to_member_functions). 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 tried directly lower a P2MF constant into `llvm.mlir.constant` but I come across the current limitation on structure constants. That's the full story.
> I think the constant operation is only meant to produce constants of non-aggregate types.
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.
https://github.com/llvm/llvm-project/pull/102752
More information about the Mlir-commits
mailing list