This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Liberating structs from memory
- To: gcc at gcc dot gnu dot org
- Subject: Liberating structs from memory
- From: Greg McGary <greg at mcgary dot org>
- Date: Fri, 18 Aug 2000 13:34:09 -0700
I wish to begin discussion about how to improve gcc's handling of auto
variable structs whose address is never taken. Such structs need not
reside in memory, and would be better treated as if all members were
separate variables, individually assignable to registers.
My immediate motivation is to improve space and time overhead of
bounded pointers. Current overheads are in the range of 150%..300%.
A previous incarnation based on gcc-2.7.2 implemented BPs with a
special machine mode akin to complex numbers (yuck), and so was able
to handle BPs as three individually-register-assignable pointers.
Overhead for that implementation was dramatically better at 70%..100%,
even without optimizations to eliminate redundant bounds checks. With
such optimizations, I hope to achieve average overheads less than 50%
for both space and time (gcc itself will always be considerably worse
than average because is a heavy user of pointers).
Special consideration must be given to structs passed (and returned)
by value. On RISC machines, such structs need to be spilled to a
temporary in memory and the address of the temporary passed to the
callee. Similar for return values: the caller allocates an in-memory
temporary and passes a hidden first argument with its address. The
callee stuffs the return value into memory at that address. A naive
first implementation should probably consider a struct passed by value
as one whose address is taken.
However, even in a first implementation, I wish to treat BPs
specially: they should always be passed and returned by value in
registers whenever possible. When passing, they would be logically
treated as three consecutive simple pointer args. When returning,
they would be placed in three consecutive return-value registers. On
ix86, that would be %eax, %edx, %ecx. On PowerPC, that would be r3,
r4, r5. Even though MIPS ABI has only two value-return registers, we
can use `a0' as a third, since this entire BP-passing scheme goes
beyond the ABI.
It seems conceptually simple enough to implement: instead of DECL_RTL
being a MEM for the entire struct, make it some form of table (vector
or list or whatever) that holds an RTX for each member of the struct.
Expanding a COMPONENT_REF will do a lookup to find the proper RTX.
The table can be sparse, omitting RTXes for members that are unused.
If the struct's address is taken, we toss the table and revert to the
traditional MEM. Taking the address of a member should force only
that member into memory, not the entire struct.
Comments?
Greg