As part of our LFortran compiler development, we need to be able to interface with C, including the complex type. In LLVM the complex type is represented as {float, float}
and {double, double}
. However, when passing these to C functions and returning from C functions, one must rewrite them into one of <2 x float>
, i64
, pass by reference, etc., and it is different on every platform (different on Windows / MSVC, Linux, macOS Intel and macOS ARM).
We currently do this in the frontend, based on the target architecture. This design adds complexity to the front end. It seems this is a really low level detail that would be best handled by LLVM itself.
Is there another solution that would be simpler? Would it make sense to try to write an LLVM pass that takes {float, float}
and converts into one of the target specific C ABI conventions for passing structures by value?
Related issues and discussions: