Re: [PATCH] use build_function_type_list in the spu backend

2011-04-21 Thread Ulrich Weigand
Nathan Froyd wrote:

for (parm = 1; d-parm[parm] != SPU_BTI_END_OF_PARAMS; parm++)
   ;
  
 -  p = void_list_node;
 +  gcc_assert (parm = (SPU_MAX_ARGS_TO_BUILTIN + 1));
 +
 +  for (i = 0; i  ARRAY_SIZE (args); i++)
 + args[i] = NULL_TREE;
 +
while (parm  1)
 - p = tree_cons (NULL_TREE, spu_builtin_types[d-parm[--parm]], p);
 + {
 +   tree arg = spu_builtin_types[d-parm[--parm]];
 +   args[parm-1] = arg;
 + }
  
 -  p = build_function_type (spu_builtin_types[d-parm[0]], p);
 +  ftype = build_function_type_list (spu_builtin_types[d-parm[0]],
 + args[0], args[1], args[2], NULL_TREE);

This looks really odd now.  The reason for running through parms twice,
first forwards and then backwards, is just that you need build up the
linked tree using tree_cons from the end.

With the new scheme, all of that is now unnecessary.  Why not simply
something along the lines of:

  for (i = 0; i  ARRAY_SIZE (args)  d-parm[i] != SPU_BTI_END_OF_PARAMS; i++)
args[i] = spu_builtin_types[d-parm[i]];

  for (; i  ARRAY_SIZE (args); i++)
args[i] = NULL;

  ftype = build_function_type_list (args[0], args[1], args[2], args[3], 
NULL_TREE);

(As an aside, the SPU_MAX_ARGS_TO_BUILTIN define appears to imply a generality
that is not really there: the call to build_function_type in itself implies an
upper bound on the number of supported arguments.)

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  ulrich.weig...@de.ibm.com


[PATCH] use build_function_type_list in the spu backend

2011-04-20 Thread Nathan Froyd
As $SUBJECT suggests.  The only tricky bit is initializing all the args
to NULL_TREE so that we can safely pass all the args to
build_function_type_list.

Tested with cross to spu-elf; I couldn't build all of libgcc, but that
appears to be a pre-existing problem.  OK to commit?

-Nathan

* config/spu/spu.c (spu_init_builtins): Call build_function_type_list
instead of build_function_type.  Rearrange gathering of args to
do so.
* config/spu/spu-builtins.def (SPU_MAX_ARGS_TO_BUILTIN): Define.

diff --git a/gcc/config/spu/spu-builtins.def b/gcc/config/spu/spu-builtins.def
index 4d01d94..6dfdf8c 100644
--- a/gcc/config/spu/spu-builtins.def
+++ b/gcc/config/spu/spu-builtins.def
@@ -23,6 +23,8 @@
 #define _A3(a,b,c)   {a, b, c, SPU_BTI_END_OF_PARAMS}
 #define _A4(a,b,c,d) {a, b, c, d, SPU_BTI_END_OF_PARAMS}
 
+#define SPU_MAX_ARGS_TO_BUILTIN 3
+
 /* definitions to support si intrinsic functions: (These and other builtin
  * definitions must precede definitions of the overloaded generic intrinsics */
 
diff --git a/gcc/config/spu/spu.c b/gcc/config/spu/spu.c
index 941194b..ea9d580 100644
--- a/gcc/config/spu/spu.c
+++ b/gcc/config/spu/spu.c
@@ -5777,9 +5777,10 @@ spu_init_builtins (void)
  sure nodes are shared. */
   for (i = 0, d = spu_builtins; i  NUM_SPU_BUILTINS; i++, d++)
 {
-  tree p;
+  tree ftype;
   char name[64];   /* build_function will make a copy. */
-  int parm;
+  int parm, i;
+  tree args[SPU_MAX_ARGS_TO_BUILTIN];
 
   if (d-name == 0)
continue;
@@ -5788,15 +5789,23 @@ spu_init_builtins (void)
   for (parm = 1; d-parm[parm] != SPU_BTI_END_OF_PARAMS; parm++)
;
 
-  p = void_list_node;
+  gcc_assert (parm = (SPU_MAX_ARGS_TO_BUILTIN + 1));
+
+  for (i = 0; i  ARRAY_SIZE (args); i++)
+   args[i] = NULL_TREE;
+
   while (parm  1)
-   p = tree_cons (NULL_TREE, spu_builtin_types[d-parm[--parm]], p);
+   {
+ tree arg = spu_builtin_types[d-parm[--parm]];
+ args[parm-1] = arg;
+   }
 
-  p = build_function_type (spu_builtin_types[d-parm[0]], p);
+  ftype = build_function_type_list (spu_builtin_types[d-parm[0]],
+   args[0], args[1], args[2], NULL_TREE);
 
   sprintf (name, __builtin_%s, d-name);
   spu_builtin_decls[i] =
-   add_builtin_function (name, p, i, BUILT_IN_MD, NULL, NULL_TREE);
+   add_builtin_function (name, ftype, i, BUILT_IN_MD, NULL, NULL_TREE);
   if (d-fcode == SPU_MASK_FOR_LOAD)
TREE_READONLY (spu_builtin_decls[i]) = 1;