[LLVMdev] PPC calling convention -- how to provide an environment pointer?
Jonathan S. Shapiro
shap at eros-os.com
Tue Jan 27 15:00:26 PST 2009
On Tue, 2009-01-27 at 08:59 -0800, Stuart Hastings wrote:
> I assume you're talking about the 32-bit PowerPC.
Also 64-bit, but the two register usage conventions are very close.
Someone previously pointed out that R0 is usable as a scratch register,
and the CTR can be used. CTR *must* be used for the branch destination
out of the ASM trampoline. R0 ends up getting used a lot for constant
loads; we can (and in fact must) use it as a scratch register, but we
cannot rely on it surviving past the prologue of the target function.
> AFAIK, the OS X dynamic linker does not "own" any registers. Here are
> some links to the Darwin ABI...
In SVR4 ABI, R11 and R12 can be used. In Darwin, these are reserved for
uses associated with dynamic code generation and/or indirect call using
dynamic code generation, which is conceptually related.
The part that is not clear to me is whether a call made by a C function
in Darwin is required to avoid R11 and R12 in order to allow for the
possibility that dynamic code generation may happen. As long as this is
required, we can safely use R11 or R12 for our purposes. That would be
great.
I should perhaps explain that the use-case which is driving the asm
design is a call from C code into a BitC procedure that requires a
closure record pointer. The problem is:
1. The C code is oblivious about the need for this "extra" argument,
and so cannot be expected to plan for it in register allocation.
2. We're trying to do a "generic" implementation at this point for
reasons of simplicity, but even if we were willing to do an
implementation that uses knowledge of the full calling convention,
there are still cases in which none of the "official" argument
registers is unused.
3. The design of most calling conventions doesn't consider the
requirements of modern language call compatibility, and
therefore doesn't reserve any register for this purpose.
So it sounds like we can use R11 or R12 provided none of the function
prologues also expect to use these. On SVR4 ABI this is true. Is it also
true for Darwin?
If not, is there some other technique that we should consider? The
obvious alternative would spill GPR3 into the parameter region, use
that, and then reload after saving the ENV ptr, but I'm not clear
whether the caller is obligated to have a parameter area in the case
where *none* of its callees take any arguments.
So: are R11 and R12 reserved enough on Darwin to be safe for our
purposes?
Thanks!
shap
More information about the llvm-dev
mailing list