Passing structs by value on the Cray T3E
Roman Lechtchinsky
rl@cs.tu-berlin.de
Thu Apr 12 00:27:00 GMT 2001
Hi,
in my quest to port GCC to the Cray T3E I've encountered a problem with
passing structures by value. On this architecture, structures are passed
on the stack if they don't fit in two registers. Space for outgoing
arguments is preallocated on the stack by the prologue (i.e.
ACCUMULATE_OUTGOING_ARGS is defined), including space for arguments that
are actually passed in registers (i.e. REG_PARM_STACK_SPACE is defined,
too). Now, for larger structs, emit_push_insn uses memcpy to copy the data
to the stack. However, emit_library_call saves the 48 bytes reserved for
register arguments before the call to memcpy and restores them afterwards.
This doesn't work if the target of memcpy includes this 48 byte area.
This problem is similar to the one described in
http://gcc.gnu.org/ml/gcc/2000-04/msg00062.html
The patch in
http://gcc.gnu.org/ml/gcc-patches/2000-12/msg01279.html
is supposed to solve it by first copying the part of the struct which goes
into REG_PARM_STACK_SPACE and then the rest. It doesn't really work for
me, however. First, it assumes that such arguments are passed both in
registers and on the stack which is not the case on the T3E. Second, it
uses the same source and target addresses for the two calls to
emit_push_insn which is obviously wrong. I can fix this such that it will
work on the T3E but I'm sure I will break other architectures in the
process. Maybe someone more knowledgeable than me could look into this and
point me to The Right Way to do this. Actually, I'm somewhat surprised
that the T3E is the only architecture that exposes this problem.
As an aside, is anyone beside me interested in a T3E port? I hope to have
a patch ready (for the C stuff only, no C++ or Java yet) within the next
month and would be really glad if others could test it.
Bye
Roman
More information about the Gcc
mailing list