Reputation: 5510
LLVM allows call
instructions and define
s to specify a calling convention. Does the IR itself already need to adhere to the specified convention? For example when using ccc
, I believe that the return value would need to fit in the 64-bit eax
on my OS/architecture. Am I allowed to write LLVM IR code that returns a struct of 3 i32
's? Does LLVM convert that to something that adheres to the C calling convention? Could I change the calling convention without changing any other code?
When I look at the output of compiling a C file with -emit-llvm
, the IR generator already applied the calling convention, and would allocate at the call site, and convert the return value as a pointer parameter. Is that absolutely necessary at this stage? What does LLVM do with the information of which calling convention to use at the next stage, -emit-obj
?
Upvotes: 2
Views: 2620
Reputation: 9324
There are many things mixed here, unfortunately. The calling convention is usually defined in terms of the source language. And many necessary details are already lost when converting to LLVM IR. So, in order to preserve the ABI and calling convention frontend is supposed to properly lay out arguments / return values so they will be properly codegen'ed at LLVM level.
So, making long story short: the calling convention contains both high-level (source language) and low-level requirements. The former are handled by frontend and the latter – by the backend. You can change the LLVM IR, but you need to make sure that the code generated will be indeed compatible with your C code. And on some platforms this might be complicated.
Upvotes: 2