Does anyone know more about how rust <-> JIT'd CLIF interop works?
I know it's possible to return values from CLIF to rust, but:
Slightly unrelated question: will excessive Variable
s from cranelift_frontend be allocated on the stack when necessary?
I may have a lot more questions, I've been trying to answer them myself but it's difficult to get much information in some places.
extern "C"
like all interaction with the jitted code. The default rust abi is unstable. You can use the call_indirect clif instruction.For the last question, the register allocator will spill values to the stack if necessary.
Ah, great. That mostly lines up with what I was thinking. I'm still confused about the StructReturn/StructArgument ones though, what do you mean by "matches the C ABI for returning structs"? I thought it's just passing around a pointer, are they somehow passing it around in a more complex way or have some kind of further restrictions on what they can do with the pointer?
For returning structs, most ABI's pass in a pointer. Some ABI's however don't pass it in a regular argument register, but pass it in one dedicated for this purpose. StructReturn ensures that this register is used on targets that have a dedicated return pointer register.
For passing in structs, ABI's generally either expand it into multiple register values (you have to do this yourself) or if that isn't possible due to for example the size they often pass it on a specific place on the stack. StructArgument copies the value pointed to by the pointer argument to the right place on the stack. (or just passes it as pointer on ABI's that pass using pointers rather than specific stack offsets) On the callee side the StructArgument pointer will point to the stack location where the argument was copied rather than the original pointer that was pass to the call instruction on the callers side.
Last updated: Nov 22 2024 at 16:03 UTC