5 ms·
At times I feel that LLVM is quite a monster, and I really like your goals of keeping things small & simple. Kudos! Can you expand on your point about "LLVM do
by riscy 10y ago
At times I feel that LLVM is quite a monster, and I really like your goals of keeping things small & simple. Kudos!
Can you expand on your point about "LLVM does NOT provide full C compatibility for you"? I have specifically been hacking on calling conventions/ABI stuff recently in LLVM and this "well known" problem is news to me.
- andrewchambers 10y agoIn llvm you cannot just pass or return structs, every frontend needs to explicitly handle the details of when and how to registerize structs to handle the system V abi for example. That code is not so trivial to do yourself actually.
- riscy 10y agoLLVM supports passing/returning structs (I'm using 3.8.1): https://ghostbin.com/paste/ozsh3 https://ghostbin.com/paste/ozsh3 Furthermore, the output does match the System V ABI: https://ghostbin.com/paste/4a5ms https://ghostbin.com/paste/4a5ms Notice how the struct is placed on the stack and the pointer to it is placed in %rdi for call/return. If you reduce the number of i32's in the struct to 3, the struct's fields are passed via registers since the type fewer than four eightbytes. My older clang does indeed produce wonky LLVM IR code that seems to try and do this classification in the frontend, so ABI compatibility may have been a problem in the past, but I'm not convinced it's a problem in current versions of LLVM.
- andrewchambers 10y agoThanks, i need to look at when this changed, because previously it was a nightmare.
- mpu 10y agoHi, thanks for the information, but LLVM still does not provide ABI compatibility. If you reduce the struct to 3 i32, it is passed in edi, esi, and edx on my machine. However according to the ABI it should be packed in rdi and rsi. Checkout the QBE transcription and what it will compile to http://c9x.me/paste/mGOO http://c9x.me/paste/mGOO (there is a bit of register shuffling because hinting in regalloc is not very mature yet, but note that SSA form for the input is not required!).
- riscy 10y agoAhh, good catch! Luckily, I don't use SysV struct passing. :)