[LLVMdev] struct as a function argument
Chris Lattner
sabre at nondot.org
Tue Oct 2 08:17:53 PDT 2007
On Oct 2, 2007, at 1:03 AM, Domagoj Babic wrote:
> Hi all,
>
> I have the same problem. My guess is that when a structure
> is passed as a parameter, you cast it into an array for optimization
> reasons (less parameters, less stack space).
This is not an optimization. This behavior is to be ABI complaint
when emitting code for your OS.
That said, this is not a very good way to do this. Rafael is working
on adding the 'byref' attribute which will support this much more
gracefully in the future.
> This is, certainly, a reasonable optimization, but makes
> inter-procedural static analysis more complex. Is there a way to
> disable it (my guess is that this should be doable by passing
> some parameter to llvm-gcc)?
The easiest way to disable this is to hack it out of llvm-gcc.
Change this (gcc/llvm-abi.h):
#ifndef LLVM_SHOULD_PASS_AGGREGATE_IN_INTEGER_REGS
#define LLVM_SHOULD_PASS_AGGREGATE_IN_INTEGER_REGS(X) \
!isSingleElementStructOrArray(type)
#endif
to:
#undef LLVM_SHOULD_PASS_AGGREGATE_IN_INTEGER_REGS
#define LLVM_SHOULD_PASS_AGGREGATE_IN_INTEGER_REGS(X) 0
Note that you won't be able to mix and match .o files with GCC where
structs are passed by value.
-Chris
More information about the llvm-dev
mailing list