This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: patch: vector_size attribute
everyone's suggestions taken.
and as a bonus, we now don't allow:
struct S { int a; };
struct S __attribute__((vector_size(16))) foo;
i don't care if they fit in an SI, that's just plain sick ;-) and the
documentation says so.
and... the testcase triggers the errors as joseph suggested (thanks).
oh, and btw-- as per our chat, NONE of the attributes (except this one)
use types. they all use decls, even the ones that shouldn't. should be
fixed.
bootstrapped on x86.
how's this one?
--
Aldy Hernandez E-mail: aldyh@redhat.com
Professional Gypsy
Red Hat, Inc.
2001-12-04 Aldy Hernandez <aldyh@redhat.com>
* extend.texi (Variable Attributes): Document vector_size.
* gcc.dg/altivec-2.c: New.
* attribs.c (c_common_attribute_table): Add vector_size.
(handle_vector_size_attribute): New.
Index: attribs.c
===================================================================
RCS file: /cvs/uberbaum/gcc/attribs.c,v
retrieving revision 1.4
diff -c -p -r1.4 attribs.c
*** attribs.c 2001/11/04 02:51:21 1.4
--- attribs.c 2001/12/05 20:04:06
*************** static tree handle_no_limit_stack_attrib
*** 84,89 ****
--- 84,91 ----
bool *));
static tree handle_pure_attribute PARAMS ((tree *, tree, tree, int,
bool *));
+ static tree handle_vector_size_attribute PARAMS ((tree *, tree, tree, int,
+ bool *));
/* Table of machine-independent attributes common to all C-like languages. */
static const struct attribute_spec c_common_attribute_table[] =
*************** static const struct attribute_spec c_com
*** 139,144 ****
--- 141,148 ----
handle_no_limit_stack_attribute },
{ "pure", 0, 0, true, false, false,
handle_pure_attribute },
+ { "vector_size", 1, 1, false, true, false,
+ handle_vector_size_attribute },
{ NULL, 0, 0, false, false, false, NULL }
};
*************** handle_pure_attribute (node, name, args,
*** 1153,1158 ****
--- 1157,1230 ----
*no_add_attrs = true;
}
+ return NULL_TREE;
+ }
+
+ /* Handle a "vector_size" attribute; arguments as in
+ struct attribute_spec.handler. */
+
+ static tree
+ handle_vector_size_attribute (node, name, args, flags, no_add_attrs)
+ tree *node;
+ tree name;
+ tree args;
+ int flags ATTRIBUTE_UNUSED;
+ bool *no_add_attrs;
+ {
+ unsigned int vecsize, nunits;
+ enum machine_mode mode, orig_mode, new_mode;
+ tree type = *node, new_type;
+
+ *no_add_attrs = true;
+
+ if (TREE_CODE (TREE_VALUE (args)) != INTEGER_CST)
+ {
+ warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
+ return NULL_TREE;
+ }
+
+ /* Get the vector size (in bytes). */
+ vecsize = TREE_INT_CST_LOW (TREE_VALUE (args));
+
+ /* Get the mode of the type being modified. */
+ orig_mode = TYPE_MODE (type);
+
+ if (TREE_CODE (type) == RECORD_TYPE ||
+ (GET_MODE_CLASS (orig_mode) != MODE_FLOAT
+ && GET_MODE_CLASS (orig_mode) != MODE_INT))
+ {
+ error ("invalid vector type for attribute `%s'",
+ IDENTIFIER_POINTER (name));
+ return NULL_TREE;
+ }
+
+ /* Calculate how many units fit in the vector. */
+ nunits = vecsize / TREE_INT_CST_LOW (TYPE_SIZE_UNIT (type));
+
+ /* Find a suitably sized vector. */
+ new_mode = VOIDmode;
+ for (mode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_mode) == MODE_INT
+ ? MODE_VECTOR_INT
+ : MODE_VECTOR_FLOAT);
+ mode != VOIDmode;
+ mode = GET_MODE_WIDER_MODE (mode))
+ if (vecsize == GET_MODE_SIZE (mode) && nunits == GET_MODE_NUNITS (mode))
+ {
+ new_mode = mode;
+ break;
+ }
+
+ if (new_mode == VOIDmode)
+ error ("no vector mode with the size and type specified could be found");
+ else
+ {
+ new_type = type_for_mode (new_mode, TREE_UNSIGNED (type));
+ if (!new_type)
+ error ("no vector mode with the size and type specified could be found");
+ else
+ *node = new_type;
+ }
+
return NULL_TREE;
}
Index: testsuite/gcc.dg/altivec-2.c
===================================================================
RCS file: altivec-2.c
diff -N altivec-2.c
*** /dev/null Tue May 5 13:32:27 1998
--- altivec-2.c Wed Dec 5 12:04:06 2001
***************
*** 0 ****
--- 1,16 ----
+ /* { dg-do compile { target powerpc-*-* } } */
+ /* { dg-options "-maltivec" } */
+
+ /* Program to test the vector_size attribute. This needs to run on a
+ target that has vectors, so use AltiVec. */
+
+ #define vector __attribute__((vector_size(16)))
+
+ vector int foobar;
+
+ /* Only floats and integrals allowed. We don't care if they map to SIs. */
+ struct X { int frances; };
+ vector struct X hotdog; /* { dg-bogus "invalid vector type" "case 1" } */
+
+ /* We don't have a V2DF. */
+ vector double x; /* { dg-bogus "no vector mode" "case 2" } */
Index: doc/extend.texi
===================================================================
RCS file: /cvs/uberbaum/gcc/doc/extend.texi,v
retrieving revision 1.37
diff -c -p -r1.37 extend.texi
*** extend.texi 2001/11/18 03:30:55 1.37
--- extend.texi 2001/12/05 20:04:07
*************** section.
*** 2826,2839 ****
The keyword @code{__attribute__} allows you to specify special
attributes of variables or structure fields. This keyword is followed
! by an attribute specification inside double parentheses. Eight
attributes are currently defined for variables: @code{aligned},
@code{mode}, @code{nocommon}, @code{packed}, @code{section},
! @code{transparent_union}, @code{unused}, and @code{weak}. Some other
! attributes are defined for variables on particular target systems. Other
! attributes are available for functions (@pxref{Function Attributes}) and
! for types (@pxref{Type Attributes}). Other front ends might define more
! attributes (@pxref{C++ Extensions,,Extensions to the C++ Language}).
You may also specify attributes with @samp{__} preceding and following
each keyword. This allows you to use them in header files without
--- 2826,2840 ----
The keyword @code{__attribute__} allows you to specify special
attributes of variables or structure fields. This keyword is followed
! by an attribute specification inside double parentheses. Nine
attributes are currently defined for variables: @code{aligned},
@code{mode}, @code{nocommon}, @code{packed}, @code{section},
! @code{transparent_union}, @code{unused}, @code{vector_size}, and
! @code{weak}. Some other attributes are defined for variables on
! particular target systems. Other attributes are available for functions
! (@pxref{Function Attributes}) and for types (@pxref{Type Attributes}).
! Other front ends might define more attributes (@pxref{C++
! Extensions,,Extensions to the C++ Language}).
You may also specify attributes with @samp{__} preceding and following
each keyword. This allows you to use them in header files without
*************** applies to all function parameters with
*** 3034,3039 ****
--- 3035,3065 ----
This attribute, attached to a variable, means that the variable is meant
to be possibly unused. GCC will not produce a warning for this
variable.
+
+ @item vector_size (@var{bytes})
+ This attribute specifies the vector size for the variable, measured in
+ bytes. For example, the declaration:
+
+ @smallexample
+ int foo __attribute__ ((vector_size (16)));
+ @end smallexample
+
+ @noindent
+ causes the compiler to set the mode for @code{foo}, to be 16 bytes,
+ divided into @code{int} sized units. Assuming a 32-bit int (a vector of
+ 4 units of 4 bytes), the corresponding mode of @code{foo} will be V4SI@.
+
+ This attribute is only applicable to integral and float scalars.
+ Aggregates with this attribute are invalid, even if they are the same
+ size as a corresponding scalar. For example, the declaration:
+
+ @smallexample
+ struct S { int a; };
+ struct S __attribute__ ((vector_size (16))) foo;
+ @end smallexample
+
+ @noindent
+ is invalid.
@item weak
The @code{weak} attribute is described in @xref{Function Attributes}.