I was playing with varargs and was wondering why the va_list variable
in C is lowered by the frontend to a *i8 (x86) or a struct (x86_64)? I
mean, if it depends on the architecture, it is more logical to have an
IR intrinsic for va_list and let the backend lowering it to the right
On many architectures, the IR support for variadic function calls is
quite limited due to the complexity of the ABIs involved. As the
frontend is then responsible for the doing the right thing esp. for
va_arg, it most of intimate knowledge already.
Yes, it does seem more logical.
Unfortunately, this is not possible, at least with the current state of LLVM. Note in particular that function calls are also handled specially by the clang frontend for many architectures. On the LLVM side, there’s not enough information to properly represent the function call convention for many architectures, as the calling conventions depend on C type information, and after converting the C types into LLVM types, some of the necessary information has been lost.
I think it would be great to move more of the calling convention logic down to LLVM – and I have some half-baked ideas on how it could be done without pushing the entire C type system down. But, it’s certainly not trivial.