This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] fix fallout from CALL_EXPR_ARGS removal
- From: Nathan Froyd <froydnj at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 19 May 2010 06:40:52 -0700
- Subject: [PATCH] fix fallout from CALL_EXPR_ARGS removal
My recent patch to remove CALL_EXPR_ARGS failed to notice that there
were two other calls to targetm.fold_builtin/TARGET_FOLD_BUILTIN that
needed updating, as well as having slightly bogus Alpha changes. This
patch addresses those problems by changing the interface to
TARGET_FOLD_BUILTIN: its signature is now:
tree (* fold_builtin) (tree fndecl, int nargs, tree *argp, bool ignore);
which ensures that the other two callsites (that were trying to fold an
array of trees and a gimple stmt) don't have to cons a TREE_LIST or a
CALL_EXPR solely for folding purposes.
Tested with cross to sparc-solaris and sanity-checked by building a
cross cc1 for Alpha. OK to commit?
-Nathan
* hooks.h (hook_tree_tree_tree_bool_null): Rename to...
(hook_tree_tree_int_treep_bool_null): ...this. Update signature.
* hooks.c: Likewise.
* target-def.h (TARGET_FOLD_BUILTIN): Define to
hook_tree_tree_int_treep_bool_null.
* target.h: (struct gcc_target): Update signature of fold_builtin
field.
* doc/tm.texi (TARGET_FOLD_BUILTIN): Update description and signature.
* builtins.c (fold_call_expr): Pass call_expr_nargs and CALL_EXPR_ARGP
instead of the call expression.
(fold_builtin_call_array): Pass n and argarray directly.
(fold_call_stmt): Pass nargs and gimple_call_arg_ptr instead of
consing a list.
* config/alpha/alpha.c (alpha_fold_builtin): Update signature. Lift
MAX_ARGS check out of the loop. Delete declaration of `arity', declare
`i' and use it in place of `arity'.
* config/sparc/sparc.c (sparc_fold_builtin): Update signature.
Dereference `args' directly.
* config/xtensa/xtensa (xtensa_fold_builtin): Likewise.
Index: doc/tm.texi
===================================================================
--- doc/tm.texi (revision 159554)
+++ doc/tm.texi (working copy)
@@ -10784,14 +10784,14 @@ another @code{CALL_EXPR}.
@var{arglist} really has type @samp{VEC(tree,gc)*}
@end deftypefn
-@deftypefn {Target Hook} tree TARGET_FOLD_BUILTIN (tree @var{fndecl}, tree @var{call}, bool @var{ignore})
+@deftypefn {Target Hook} tree TARGET_FOLD_BUILTIN (tree @var{fndecl}, int @var{n_args}, tree *@var{argp}, bool @var{ignore})
Fold a call to a machine specific built-in function that was set up by
@samp{TARGET_INIT_BUILTINS}. @var{fndecl} is the declaration of the
-built-in function. @var{call} is the @code{CALL_EXPR} representing
-the call. The result is another tree containing a
-simplified expression for the call's result. If @var{ignore} is true
-the value will be ignored.
+built-in function. @var{n_args} is the number of arguments passed to
+the function; the arguments themselves are pointed to by @var{argp}.
+The result is another tree containing a simplified expression for the
+call's result. If @var{ignore} is true the value will be ignored.
@end deftypefn
@deftypefn {Target Hook} {const char *} TARGET_INVALID_WITHIN_DOLOOP (const_rtx @var{insn})
Index: hooks.c
===================================================================
--- hooks.c (revision 159554)
+++ hooks.c (working copy)
@@ -299,9 +299,10 @@ hook_constcharptr_const_tree_null (const
}
tree
-hook_tree_tree_tree_bool_null (tree t0 ATTRIBUTE_UNUSED,
- tree t1 ATTRIBUTE_UNUSED,
- bool ignore ATTRIBUTE_UNUSED)
+hook_tree_tree_int_treep_bool_null (tree t0 ATTRIBUTE_UNUSED,
+ int i ATTRIBUTE_UNUSED,
+ tree *p ATTRIBUTE_UNUSED,
+ bool ignore ATTRIBUTE_UNUSED)
{
return NULL;
}
Index: hooks.h
===================================================================
--- hooks.h (revision 159554)
+++ hooks.h (working copy)
@@ -71,7 +71,7 @@ extern tree hook_tree_const_tree_null (c
extern tree hook_tree_tree_tree_null (tree, tree);
extern tree hook_tree_tree_tree_tree_null (tree, tree, tree);
extern tree hook_tree_tree_tree_tree_3rd_identity (tree, tree, tree);
-extern tree hook_tree_tree_tree_bool_null (tree, tree, bool);
+extern tree hook_tree_tree_int_treep_bool_null (tree, int, tree *, bool);
extern unsigned hook_uint_uint_constcharptrptr_0 (unsigned, const char **);
Index: target.h
===================================================================
--- target.h (revision 159554)
+++ target.h (working copy)
@@ -616,7 +616,7 @@ struct gcc_target
tree decl, void *params);
/* Fold a target-specific builtin. */
- tree (* fold_builtin) (tree fndecl, tree arglist, bool ignore);
+ tree (* fold_builtin) (tree fndecl, int nargs, tree *argp, bool ignore);
/* Returns a code for a target-specific builtin that implements
reciprocal of the function, or NULL_TREE if not available. */
Index: builtins.c
===================================================================
--- builtins.c (revision 159554)
+++ builtins.c (working copy)
@@ -10702,7 +10702,8 @@ fold_call_expr (location_t loc, tree exp
return NULL_TREE;
if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
- return targetm.fold_builtin (fndecl, exp, ignore);
+ return targetm.fold_builtin (fndecl, call_expr_nargs (exp),
+ CALL_EXPR_ARGP (exp), ignore);
else
{
if (nargs <= MAX_ARGS_TO_FOLD_BUILTIN)
@@ -10766,7 +10767,6 @@ fold_builtin_call_array (location_t loc,
tree *argarray)
{
tree ret = NULL_TREE;
- int i;
tree exp;
if (TREE_CODE (fn) == ADDR_EXPR)
@@ -10790,12 +10790,10 @@ fold_builtin_call_array (location_t loc,
return build_call_array_loc (loc, type, fn, n, argarray);
if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
{
- tree arglist = NULL_TREE;
- for (i = n - 1; i >= 0; i--)
- arglist = tree_cons (NULL_TREE, argarray[i], arglist);
- ret = targetm.fold_builtin (fndecl, arglist, false);
- if (ret)
- return ret;
+ ret = targetm.fold_builtin (fndecl, n, argarray, false);
+ if (ret)
+ return ret;
+
return build_call_array_loc (loc, type, fn, n, argarray);
}
else if (n <= MAX_ARGS_TO_FOLD_BUILTIN)
@@ -13698,14 +13696,10 @@ fold_call_stmt (gimple stmt, bool ignore
if (avoid_folding_inline_builtin (fndecl))
return NULL_TREE;
- /* FIXME: Don't use a list in this interface. */
if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
{
- tree arglist = NULL_TREE;
- int i;
- for (i = nargs - 1; i >= 0; i--)
- arglist = tree_cons (NULL_TREE, gimple_call_arg (stmt, i), arglist);
- return targetm.fold_builtin (fndecl, arglist, ignore);
+ return targetm.fold_builtin (fndecl, nargs,
+ gimple_call_arg_ptr (stmt, 0), ignore);
}
else
{
Index: ChangeLog
===================================================================
Index: target-def.h
===================================================================
--- target-def.h (revision 159554)
+++ target-def.h (working copy)
@@ -456,7 +456,7 @@
#define TARGET_INIT_BUILTINS hook_void_void
#define TARGET_EXPAND_BUILTIN default_expand_builtin
#define TARGET_RESOLVE_OVERLOADED_BUILTIN NULL
-#define TARGET_FOLD_BUILTIN hook_tree_tree_tree_bool_null
+#define TARGET_FOLD_BUILTIN hook_tree_tree_int_treepbool_null
#define TARGET_BUILTIN_DECL NULL
/* In tree-ssa-math-opts.c */
Index: config/alpha/alpha.c
===================================================================
--- config/alpha/alpha.c (revision 159554)
+++ config/alpha/alpha.c (working copy)
@@ -7138,26 +7138,27 @@ alpha_fold_builtin_ctpop (unsigned HOST_
/* Fold one of our builtin functions. */
static tree
-alpha_fold_builtin (tree fndecl, tree call, bool ignore ATTRIBUTE_UNUSED)
+alpha_fold_builtin (tree fndecl, int n_args, tree *op,
+ bool ignore ATTRIBUTE_UNUSED)
{
- tree *op = CALL_EXPR_ARGP (call);
unsigned HOST_WIDE_INT opint[MAX_ARGS];
long op_const = 0;
- int arity;
+ int i;
+
+ if (n_args >= MAX_ARGS)
+ return NULL;
- for (i = 0; i < call_expr_nargs (call); i++)
+ for (i = 0; i < n_args; i++)
{
- tree arg = CALL_EXPR_ARG (call, i);
+ tree arg = op[i];
if (arg == error_mark_node)
return NULL;
- if (arity >= MAX_ARGS)
- return NULL;
- opint[arity] = 0;
+ opint[i] = 0;
if (TREE_CODE (arg) == INTEGER_CST)
{
- op_const |= 1L << arity;
- opint[arity] = int_cst_value (arg);
+ op_const |= 1L << i;
+ opint[i] = int_cst_value (arg);
}
}
Index: config/sparc/sparc.c
===================================================================
--- config/sparc/sparc.c (revision 159554)
+++ config/sparc/sparc.c (working copy)
@@ -386,7 +386,7 @@ static void sparc_init_libfuncs (void);
static void sparc_init_builtins (void);
static void sparc_vis_init_builtins (void);
static rtx sparc_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
-static tree sparc_fold_builtin (tree, tree, bool);
+static tree sparc_fold_builtin (tree, int, tree *, bool);
static int sparc_vis_mul8x16 (int, int);
static tree sparc_handle_vis_mul8x16 (int, tree, tree, tree);
static void sparc_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
@@ -8372,7 +8372,8 @@ sparc_handle_vis_mul8x16 (int fncode, tr
function could not be folded. */
static tree
-sparc_fold_builtin (tree fndecl, tree call, bool ignore)
+sparc_fold_builtin (tree fndecl, int n_args ATTRIBUTE_UNUSED,
+ tree *args, bool ignore)
{
tree arg0, arg1, arg2;
tree rtype = TREE_TYPE (TREE_TYPE (fndecl));
@@ -8386,7 +8387,7 @@ sparc_fold_builtin (tree fndecl, tree ca
switch (icode)
{
case CODE_FOR_fexpand_vis:
- arg0 = CALL_EXPR_ARG (call, 0);
+ arg0 = args[0];
STRIP_NOPS (arg0);
if (TREE_CODE (arg0) == VECTOR_CST)
@@ -8409,8 +8410,8 @@ sparc_fold_builtin (tree fndecl, tree ca
case CODE_FOR_fmul8x16_vis:
case CODE_FOR_fmul8x16au_vis:
case CODE_FOR_fmul8x16al_vis:
- arg0 = CALL_EXPR_ARG (call, 0);
- arg1 = CALL_EXPR_ARG (call, 1);
+ arg0 = args[0];
+ arg1 = args[1];
STRIP_NOPS (arg0);
STRIP_NOPS (arg1);
@@ -8427,8 +8428,8 @@ sparc_fold_builtin (tree fndecl, tree ca
break;
case CODE_FOR_fpmerge_vis:
- arg0 = CALL_EXPR_ARG (call, 0);
- arg1 = CALL_EXPR_ARG (call, 1);
+ arg0 = args[0];
+ arg1 = args[1];
STRIP_NOPS (arg0);
STRIP_NOPS (arg1);
@@ -8450,9 +8451,9 @@ sparc_fold_builtin (tree fndecl, tree ca
break;
case CODE_FOR_pdist_vis:
- arg0 = CALL_EXPR_ARG (call, 0);
- arg1 = CALL_EXPR_ARG (call, 1);
- arg2 = CALL_EXPR_ARG (call, 2);
+ arg0 = args[0];
+ arg1 = args[1];
+ arg2 = args[2];
STRIP_NOPS (arg0);
STRIP_NOPS (arg1);
STRIP_NOPS (arg2);
Index: config/xtensa/xtensa.c
===================================================================
--- config/xtensa/xtensa.c (revision 159554)
+++ config/xtensa/xtensa.c (working copy)
@@ -142,7 +142,7 @@ static tree xtensa_gimplify_va_arg_expr
gimple_seq *);
static rtx xtensa_function_value (const_tree, const_tree, bool);
static void xtensa_init_builtins (void);
-static tree xtensa_fold_builtin (tree, tree, bool);
+static tree xtensa_fold_builtin (tree, int, tree *, bool);
static rtx xtensa_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
static void xtensa_va_start (tree, rtx);
static bool xtensa_frame_pointer_required (void);
@@ -3000,7 +3000,8 @@ xtensa_init_builtins (void)
static tree
-xtensa_fold_builtin (tree fndecl, tree call, bool ignore ATTRIBUTE_UNUSED)
+xtensa_fold_builtin (tree fndecl, int n_args ATTRIBUTE_UNUSED, tree *args,
+ bool ignore ATTRIBUTE_UNUSED)
{
unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
tree arg0, arg1;
@@ -3008,8 +3009,8 @@ xtensa_fold_builtin (tree fndecl, tree c
switch (fcode)
{
case XTENSA_BUILTIN_UMULSIDI3:
- arg0 = CALL_EXPR_ARG (call, 0);
- arg1 = CALL_EXPR_ARG (call, 1);
+ arg0 = args[0];
+ arg1 = args[1];
if ((TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
|| TARGET_MUL32_HIGH)
return fold_build2 (MULT_EXPR, unsigned_intDI_type_node,