This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] ARM: __attribute__ ((reg_return))


Paul Brook wrote:
I really don't think it is possible to make it a function attribute, for
one language reason and one QoI reason.  The language reason:  if we did
it your way, this fragment would be acceptable code:

    struct S { int a, b; };
    struct S foo(void) __attribute__ ((reg_return));
    struct S (*ptr)(void) = foo;

But any caller of 'ptr' will be looking for the return value in the
normal place, not where 'foo' will put it.  Therefore, that last
assignment needs to be a type error.  My way, we get that for free.  I
don't believe we have any way of requiring that function attributes
match in function pointer assignment.

This can't be a new problem. x86 has at least 2 function attributes that effect the ABI (stdcall and regparm).

And on x86, assigning a regparm function to a non-regparm function pointer does get me an 'incompatible types in assignment' warning. I'll have a look how x86 does that and maybe I can figure something out.


The QoI reason: any function that returns a structure must (yes, I know
there are exceptions) declare a local variable with the same type as the
structure.  On ARM, local variables with a structure type larger than
two words are normally put on the stack.  This produces suboptimal code
when the structure is going to be returned in registers; GCC is (even in
4.3) not able to eliminate all the memory accesses or the stack slot.
This is why I invented the override_record_mode target hook, to force
reg_return structures to be kept in registers.  Obviously, if we make
the attribute be on the function, there is no way to do that.

Yuck. This suggests that the attribute is somewhat mis-named. It effects code generation as well as the ABI. On a related note, we need documentation for the new attribute.

Well, I'd love to avoid the target hook and just make the optimizer smarter, do you have any thoughts on that?


zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]