[cfe-commits] [QUESTION] vecreturn attribute question 1

Eli Friedman eli.friedman at gmail.com
Tue Aug 10 20:28:42 PDT 2010


On Tue, Aug 10, 2010 at 1:08 PM, John Thompson
<john.thompson.jtsoftware at gmail.com> wrote:
> Since this is what I believe is a custom attribute, to make sure we are on
> the same page, the vecreturn attribute is described as follows in our gcc
> doc:
>
> ***
> Returning a Vector Class in Registers
>
> According to the PPU ABI specifications, a class with a single member of
> vector type is returned in
> memory when used as the return value of a function. This results in
> inefficient code when implementing
> vector classes. To return the value in a single vector register, add the
> vecreturn attribute to the class
> definition. This attribute is also applicable to struct types.
>
> Example:
>
> struct Vector
> {
>   __vector float xyzw;
> } __attribute__((vecreturn));
>
> Vector Add(Vector lhs, Vector rhs)
> {
>   Vector result;
>   result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
>   return result; // This will be returned in a register
> }
> ***
>
> I believe I should be doing a little more checking to make sure the
> structure/class to which the vecreturn attribute is attached is of the
> proper kind, i.e. only has one data member, and the member is a vector.
>
> Is the enclosed patch the right way to do this checking, using the field
> iterator?
>
> If so, may I check it in?  Otherwise, please let me know the right way to do
> it.

It's the right approach.

+  CXXRecordDecl *record = static_cast<CXXRecordDecl*>(d);

The following is preferred:
CXXRecordDecl *record = cast<CXXRecordDecl>(d);

You probably want to check isPOD().

Would some check that the vector is small enough to be returned in a
single register be appropriate?

Is there some reason why vecreturn is only valid for C++?  If not, you
should check for a RecordDecl instead of a CXXRecordDecl.

-Eli




More information about the cfe-commits mailing list