[LLVMdev] PPC calling convention -- how to provide an environment pointer?

Stuart Hastings stuart at apple.com
Tue Jan 27 08:59:38 PST 2009


> Message: 5
> Date: Mon, 26 Jan 2009 21:47:12 -0500
> From: "Jonathan S. Shapiro" <shap at eros-os.com>
> Subject: [LLVMdev] PPC calling convention -- how to provide an
> 	environment	pointer?
> To: LLVM Developers Mailing List <llvmdev at cs.uiuc.edu>
> Message-ID: <1233024432.24380.11.camel at vmx>
> Content-Type: text/plain
>
> This is not, strictly speaking, an LLVM issue, but it is an
> implementation matter that a compiler using LLVM needs to handle. I've
> got resolutions for other platforms, but I'm not seeing how to get  
> this
> done for PowerPC, and I'ld appreciate suggestions or pointers.
>
> For BitC procedures that require an environment pointer, our general
> approach has been to construct a heap-allocated assembly code  
> fragment.
> This fragment operates as follows:
>
>   loads the environment pointer into a register that is
>     call clobbered but not perturbed by the preamble.
>   branches to a stub procedure
>
> The stub procedure then:
>
>   copies the env ptr from the transient register into a local, and
>   calls an implementation procedure that expects the environment
>     as an explicit argument, passing the other arguments along
>     unmodified.
>   [This stub exists entirely because of register rotation in the
>    calling convention.]
>
> On every architecture that we have considered prior to PowerPC, there
> have been at least two registers that we could safely abuse in the
> heap-allocated fragment. Typically these are registers that are held
> back for use by the dynamic linking logic for the target architecture.
>
> At the moment, we're looking at the MachO/Darwin calling convention  
> and
> we're pretty stumped about which, if any, of the registers can be
> borrowed safely in this way.
>
> Can anyone suggest an appropriate way to do this, or point us at some
> existing implementation of something similar that we can study?
>
>
> Thanks.
>
>
> shap

I assume you're talking about the 32-bit PowerPC.

AFAIK, the OS X dynamic linker does not "own" any registers.  Here are  
some links to the Darwin ABI.  Let me know if these links don't work  
for you:

	http://developer.apple.com/documentation/developertools/Conceptual/LowLevelABI/100-32-bit_PowerPC_Function_Calling_Conventions/32bitPowerPC.html

	http://developer.apple.com/documentation/developertools/Conceptual/LowLevelABI/Mac_OS_X_ABI_Function_Call_Guide.pdf

You may be able to use R11, R12, or R0.  I assume you're aware that R0  
reads as zero in some instruction fields; AFAIK, Darwin only uses R0  
as a zero.

Good Luck,

stuart



More information about the llvm-dev mailing list