Is there any documentation for how StructArgument/StructReturn work and should be used? I'm a little unclear about when to use multiple arguments and multiple returns vs these aggregate AbiParams. Thanks! I've been really enjoying using cranelift so far :)
You will have to look up the abi specification document for your target and see if the type in question needs to be returned using a return pointer (=> use pointerStructReturn
as first argument and write the return value there) or using multiple registers (=> use multiple returns). And similar for struct arguments. You can also look at how rustc lowers your type to llvm ir and reproduce this in clif ir.
Or alternatively you can take the relevant file at https://github.com/rust-lang/rust/tree/master/compiler/rustc_target/src/abi/call and try to reproduce the logic in there.
Thanks!
Not fully related, but are zero-sized stack slots allowed by cranelift? If not of course I can just not emit them, but I wanted to see if I can leave my code as-is
AFAIK Cranelift doesn't have any issues with zero-sized stack slots. If it does we should either fix it or add a verifier check for it.
bjorn3 said:
You will have to look up the abi specification document for your target and see if the type in question needs to be returned using a return pointer (=> use pointer
StructReturn
as first argument and write the return value there) or using multiple registers (=> use multiple returns). And similar for struct arguments. You can also look at how rustc lowers your type to llvm ir and reproduce this in clif ir.
Oh following up about this: Why does StructArgument require a size but StructReturn does not? And for both of them, I should use a pointer for the AbiParam's type?
StructReturn only changes the register in which the pointer is stored. StructArgument doesn't actually pass a pointer around, instead it copies an area of the given size pointed to by the pointer you pass as user to a specific location on the stack where the callee expects it.
Oh, so I should put the type of the StructArgument as a pointer but then it will automatically handle the copying? Do I then access the data through a load
on the argument?
I'm just a bit unclear where the copied data ends up
Yes, the type of a StructArgument should be a pointer. Cranelift handles the copying automatically as part of the call instruction. The copied data ends up somewhere on the stack which is kept alive until the callee returns.
Last updated: Nov 22 2024 at 17:03 UTC