-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation of MIR_T_BLK #332
Comments
Unfortunately, it is complicated because ABIs can be complicated too. For example. structure with two int members is passed through 2 integer regs on x86-64 and structure with one integer and one fp member are passed through 1 int reg and fp reg (nested structures can complicate passing even more). MIR_T_BLK+xxx are used as enumeration of all possible methods of passing structures and they described different passing methods heavily depended on a target. I decided to use MIR_T_BLK+xxx approach instead of introducing structure/union types as in LLVM IR. It is a simpler solution, imho. I'll try to document MIR_T_BLK+xxx for different targets for the next MIR release which will be probably be at the end of summer or begging of fall. |
Ok, thank you for the answer. Can you tell me which MIR_T_BLK should I use if I generate code for x86_64 ? I would also appreciate a location to look in the code where the passing argument method depends on the BLK type. |
You can find how to use blk types for x86-64 in o MIR_BLK + 1 is used for passing unions/structures (of size <= 16) with integer members Depending on MIR_BLK type, the args can be passed (partially or fully) through integer or fp regs or on the stack. Please look at SYSV ABI for this. You can also find how blk type are generated by |
@vnmakarov would using MIR_BLK for all cases work even though it would be sub-optimal? |
Yes. I believe it should work. The problem will be only when you try to call external C functions (unfortunately there is no way to force a C compiler even with all implemented GCC extensions to accept MIR_BLK parameter passing for any type parameter). |
Alright. This is exactly the use case I'm trying to solve unfortunately. So if i understand this: i have to change what type of BLK instruction i'm using depending on the architecture? |
@vnmakarov several question around passing struct/union by value:
|
Actually returning structures is less complicated than passing. Address of the function result is set up as the first argument. So if func returns 16-byte structure, the func will be one arg function and look like
The return from
or something analogous. The call of
Here How the Ret_Addr passed is machine dependent (defined by the target C ABI). It can be really passed through a reg or calculated from the stack pointer.
I don't remember exactly C ABI on aarch64 but it seems so. Generally speaking
Yes, it is complicated. You should read x86-64 SYSV ABI. It was designed by Jan Hibicka ( a GCC developer) when AMD introduced its 64-bit architecture. The major goal was performance. I hope recent Intel extension APX (adding another 16 general purpose registers) will not result in changing SYSV ABI. |
I want to generate a function that takes a C struct as parameter and returns another C struct.
As far as I understand, the argument can be of type MIR_T_BLK. Can we have more documentation on the usage of MIR_T_BLK, MIR_T_RBLK and some examples in the mir-tests folder ?
Also the documentation is not clear on what is the difference between MIR_T_BLK and MIR_T_BLK + xxx.
The text was updated successfully, but these errors were encountered: