[flang-commits] [flang] [flang] Add struct passing target rewrite hooks and partial X86-64 impl (PR #74829)

via flang-commits flang-commits at lists.llvm.org
Fri Dec 8 08:11:13 PST 2023


jeanPerier wrote:

> I found one nit and one compilation error that needs to be fixed.

Thanks @psteinfeld. I fixed the assert issue. What is the nit you mentionned?

>-> Are you looking for help implementing the target specific parts for other targets?

Currently no. I briefly looked at Aarch64 rules, and it seems similar/much simpler. Derived type bigger than 16 bytes are passed in memory (without the byval). And smaller structs gets rewritten in a single LLVM array argument `[size x eleTy] align`.

My long term hope is for some C/C++ compiler to increase support for C ABI in MLIR or for someone to go through the big project of extracting/bridging with clang ABIInfo class (https://github.com/llvm/llvm-project/blame/46a56931251eba767929f6a2110da5b1bcbc5eb9/clang/lib/CodeGen/ABIInfo.h#L68) that is not even public right now. But right now this would side track us a lot from Fortran language support for little gain (BIND(C) VALUE seems to still be a corner case that is not very used).

> -> The summary talks specifically about BIND(C) here, but doesn't the rules apply to derived types passed by value (with VALUE attribute) in general. Say a derived type that looks like a complex type internally, wouldn't that need some target specific handling like Complex?

Without the BIND(C) attribute, derived type by value are passed in memory in lowering. Three reasons for this:
- to support the OPTIONAL VALUE case that is not possible with BIND(C) (Fortran 2015 C865).
- the ABI is much simpler/target independent.
- that is what most compilers are doing.

So the need to pass a derived type as a C struct is a corner case that only occurs with BIND(C) + VALUE.




https://github.com/llvm/llvm-project/pull/74829


More information about the flang-commits mailing list