This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[lto] PATCH: small CALL_EXPR cleanups
- From: Sandra Loosemore <sandra at codesourcery dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 11 Aug 2006 13:26:33 -0400
- Subject: [lto] PATCH: small CALL_EXPR cleanups
Here are some small CALL_EXPR-related tweaks; making the argument iterators
inlines and the other things from Paolo's list, and stomping on a couple places
where CALL_EXPR_ARGS was being used to construct a temporary list. Already
committed as "obvious".
-Sandra
2006-08-11 Sandra Loosemore <sandra@codesourcery.com>
* gcc/tree.h (call_expr_arg_iterator, FOR_EACH_CALL_EXPR_ARG):
Move towards bottom of file to be near other iterator declarations.
(tree_size, tree_code_size): Update comments.
(init_call_expr_arg_iterator): Change from extern to static inline.
(first_call_expr_arg): Likewise.
(next_call_expr_arg): Likewise.
(more_call_expr_args_p): Likewise.
* gcc/tree.c (tree_code_size): Update comments.
(init_call_expr_arg_iterator): Moved to tree.h as static inline.
(first_call_expr_arg): Likewise.
(next_call_expr_arg): Likewise.
(more_call_expr_args_p): Likewise.
* gcc/cp/tree.c (build_cplus_new): Use different call constructor
to avoid constructing a temporary arglist.
* gcc/tree-ssa-pre.c (temp_copy_call_expr): Use obstack_copy instead
of obstac_alloc/memcpy.
* gcc/cp/pt.c (tsubst_copy): Rewrite CALL_EXPR case to avoid
constructing a temporary arglist.
(tsubst_copy_and_subst): Add FIXME comment on another temporary
arglist case.
* gcc/java/builtins.c (java_build_function_call_expr): Rewrite to
avoid constructing a temporary argument list.
* gcc/java/java-tree.def (NEW_CLASS_EXPR): Update comments.
Index: gcc/tree.h
===================================================================
*** gcc/tree.h (revision 116083)
--- gcc/tree.h (working copy)
*************** struct tree_constructor GTY(())
*** 1569,1587 ****
#define CALL_EXPR_ARGP(NODE) \
(&(TREE_OPERAND (VL_EXP_CHECK (NODE), 0)) + 3)
- typedef struct call_expr_arg_iterator_d GTY (())
- {
- tree t; /* the call_expr */
- int n; /* argument count */
- int i; /* next argument index */
- } call_expr_arg_iterator;
-
- /* Iterate through each argument ARG of CALL_EXPR CALL, using variable ITER
- (of type call_expr_arg_iterator) to hold the iteration state. */
- #define FOR_EACH_CALL_EXPR_ARG(arg, iter, call) \
- for ((arg) = first_call_expr_arg ((call), &(iter)); (arg); \
- (arg) = next_call_expr_arg (&(iter)))
-
/* OpenMP directive and clause accessors. */
#define OMP_BODY(NODE) \
--- 1569,1574 ----
*************** enum ptrmemfunc_vbit_where_t
*** 3464,3477 ****
extern tree decl_assembler_name (tree);
! /* Compute the number of bytes occupied by 'node'. This routine only
! looks at TREE_CODE and, if the code is TREE_VEC, TREE_VEC_LENGTH. */
!
extern size_t tree_size (tree);
! /* Compute the number of bytes occupied by a tree with code CODE. This
! function cannot be used for TREE_VEC, PHI_NODE, or CALL_EXPR codes,
! which are of variable length. */
extern size_t tree_code_size (enum tree_code);
/* Compute the number of operands in an expression node NODE. For
--- 3451,3463 ----
extern tree decl_assembler_name (tree);
! /* Compute the number of bytes occupied by NODE. This routine only
! looks at TREE_CODE, except for those nodes that have variable sizes. */
extern size_t tree_size (tree);
! /* Compute the number of bytes occupied by a tree with code CODE.
! This function cannot be used for nodes that have variable sizes,
! including TREE_VEC, PHI_NODE, STRING_CST, and CALL_EXPR. */
extern size_t tree_code_size (enum tree_code);
/* Compute the number of operands in an expression node NODE. For
*************** extern tree lower_bound_in_type (tree, t
*** 4198,4207 ****
extern int operand_equal_for_phi_arg_p (tree, tree);
extern bool empty_body_p (tree);
extern bool stdarg_p (tree);
- extern void init_call_expr_arg_iterator (tree, call_expr_arg_iterator *);
- extern tree first_call_expr_arg (tree, call_expr_arg_iterator *);
- extern tree next_call_expr_arg (call_expr_arg_iterator *);
- extern bool more_call_expr_args_p (const call_expr_arg_iterator *);
extern tree call_expr_arglist (tree);
extern tree *nth_parm_type_ptr (tree, int);
extern tree alloc_parm_types (int);
--- 4184,4189 ----
*************** extern unsigned HOST_WIDE_INT compute_bu
*** 4652,4655 ****
--- 4634,4698 ----
/* In expr.c. */
extern unsigned HOST_WIDE_INT highest_pow2_factor (tree);
+
+ /* Abstract iterators for CALL_EXPRs. These static inline definitions
+ have to go towards the end of tree.h so that union tree_node is fully
+ defined by this point. */
+
+ /* Structure containing iterator state. */
+ typedef struct call_expr_arg_iterator_d GTY (())
+ {
+ tree t; /* the call_expr */
+ int n; /* argument count */
+ int i; /* next argument index */
+ } call_expr_arg_iterator;
+
+ /* Initialize the abstract argument list iterator object ITER with the
+ arguments from CALL_EXPR node EXP. */
+ static inline void
+ init_call_expr_arg_iterator (tree exp, call_expr_arg_iterator *iter)
+ {
+ iter->t = exp;
+ iter->n = call_expr_nargs (exp);
+ iter->i = 0;
+ }
+
+ /* Return the next argument from abstract argument list iterator object ITER,
+ and advance its state. Return NULL_TREE if there are no more arguments. */
+ static inline tree
+ next_call_expr_arg (call_expr_arg_iterator *iter)
+ {
+ tree result;
+ if (iter->i >= iter->n)
+ return NULL_TREE;
+ result = CALL_EXPR_ARG (iter->t, iter->i);
+ iter->i++;
+ return result;
+ }
+
+ /* Initialize the abstract argument list iterator object ITER, then advance
+ past and return the first argument. Useful in for expressions, e.g.
+ for (arg = first_call_expr_arg (exp, &iter); arg;
+ arg = next_call_expr_arg (&iter)) */
+ static inline tree
+ first_call_expr_arg (tree exp, call_expr_arg_iterator *iter)
+ {
+ init_call_expr_arg_iterator (exp, iter);
+ return next_call_expr_arg (iter);
+ }
+
+ /* Test whether there are more arguments in abstract argument list iterator
+ ITER, without changing its state. */
+ static inline bool
+ more_call_expr_args_p (const call_expr_arg_iterator *iter)
+ {
+ return (iter->i < iter->n);
+ }
+
+ /* Iterate through each argument ARG of CALL_EXPR CALL, using variable ITER
+ (of type call_expr_arg_iterator) to hold the iteration state. */
+ #define FOR_EACH_CALL_EXPR_ARG(arg, iter, call) \
+ for ((arg) = first_call_expr_arg ((call), &(iter)); (arg); \
+ (arg) = next_call_expr_arg (&(iter)))
+
#endif /* GCC_TREE_H */
Index: gcc/tree.c
===================================================================
*** gcc/tree.c (revision 116083)
--- gcc/tree.c (working copy)
*************** decl_assembler_name (tree decl)
*** 309,316 ****
}
/* Compute the number of bytes occupied by a tree with code CODE.
! This function cannot be used for TREE_VEC, PHI_NODE, or STRING_CST
! codes, which are of variable length. */
size_t
tree_code_size (enum tree_code code)
{
--- 309,316 ----
}
/* Compute the number of bytes occupied by a tree with code CODE.
! This function cannot be used for nodes that have variable sizes,
! including TREE_VEC, PHI_NODE, STRING_CST, and CALL_EXPR. */
size_t
tree_code_size (enum tree_code code)
{
*************** stdarg_p (tree fntype)
*** 7905,7956 ****
&& nth_parm_type (parm_types, len - 1) != void_type_node);
}
- /* Initialize the abstract argument list iterator object ITER with the argument
- list from CALL_EXPR node EXP. */
-
- void
- init_call_expr_arg_iterator (tree exp, call_expr_arg_iterator *iter)
- {
- iter->t = exp;
- iter->n = call_expr_nargs (exp);
- iter->i = 0;
- }
-
- /* Initialize the abstract argument list iterator object ITER, then advance
- past and return the first argument. Useful in for expressions, e.g.
- for (arg = first_call_expr_arg (exp, &iter); arg;
- arg = next_call_expr_arg (&iter)) */
-
- tree
- first_call_expr_arg (tree exp, call_expr_arg_iterator *iter)
- {
- init_call_expr_arg_iterator (exp, iter);
- return next_call_expr_arg (iter);
- }
-
- /* Return the next argument from abstract argument list iterator object ITER,
- and advance its state. Return NULL_TREE if there are no more arguments. */
-
- tree
- next_call_expr_arg (call_expr_arg_iterator *iter)
- {
- tree result;
- if (iter->i >= iter->n)
- return NULL_TREE;
- result = CALL_EXPR_ARG (iter->t, iter->i);
- iter->i++;
- return result;
- }
-
- /* Test whether there are more arguments in abstract argument list iterator
- ITER, without changing its state. */
-
- bool
- more_call_expr_args_p (const call_expr_arg_iterator *iter)
- {
- return (iter->i < iter->n);
- }
-
/* Build and return a TREE_LIST of arguments in the CALL_EXPR exp.
FIXME: don't use this function. It exists for compatibility with
the old representation of CALL_EXPRs where a list was used to hold the
--- 7905,7910 ----
Index: gcc/cp/tree.c
===================================================================
*** gcc/cp/tree.c (revision 116083)
--- gcc/cp/tree.c (working copy)
*************** build_cplus_new (tree type, tree init)
*** 304,311 ****
type, don't mess with AGGR_INIT_EXPR. */
if (is_ctor || TREE_ADDRESSABLE (type))
{
! rval = build_call_list (AGGR_INIT_EXPR, void_type_node, fn,
! CALL_EXPR_ARGS (init));
AGGR_INIT_EXPR_SLOT (rval) = slot;
TREE_SIDE_EFFECTS (rval) = 1;
AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
--- 304,312 ----
type, don't mess with AGGR_INIT_EXPR. */
if (is_ctor || TREE_ADDRESSABLE (type))
{
! rval = build_call_array (AGGR_INIT_EXPR, void_type_node, fn,
! call_expr_nargs (init),
! CALL_EXPR_ARGP (init));
AGGR_INIT_EXPR_SLOT (rval) = slot;
TREE_SIDE_EFFECTS (rval) = 1;
AGGR_INIT_VIA_CTOR_P (rval) = is_ctor;
Index: gcc/tree-ssa-pre.c
===================================================================
*** gcc/tree-ssa-pre.c (revision 116083)
--- gcc/tree-ssa-pre.c (working copy)
*************** fully_constant_expression (tree t)
*** 964,981 ****
return t;
}
-
/* Make a temporary copy of a CALL_EXPR object NODE. */
static tree
temp_copy_call_expr (tree node)
{
! tree new = (tree) obstack_alloc (&temp_call_expr_obstack, tree_size (node));
! memcpy (new, node, tree_size (node));
! return new;
}
-
/* Translate the vuses in the VUSES vector backwards through phi
nodes, so that they have the value they would have in BLOCK. */
--- 964,977 ----
return t;
}
/* Make a temporary copy of a CALL_EXPR object NODE. */
static tree
temp_copy_call_expr (tree node)
{
! return (tree) obstack_copy (&temp_call_expr_obstack, node, tree_size (node));
}
/* Translate the vuses in the VUSES vector backwards through phi
nodes, so that they have the value they would have in BLOCK. */
Index: gcc/cp/pt.c
===================================================================
*** gcc/cp/pt.c (revision 116083)
--- gcc/cp/pt.c (working copy)
*************** tsubst_copy (tree t, tree args, tsubst_f
*** 7888,7900 ****
NULL_TREE, NULL_TREE);
case CALL_EXPR:
! /* FIXME: It should be possible to do this without consing up
! lists for the arguments. */
! return build_nt_call_list (CALL_EXPR,
! tsubst_copy (CALL_EXPR_FN (t), args,
! complain, in_decl),
! tsubst_copy (CALL_EXPR_ARGS (t), args,
! complain, in_decl));
case COND_EXPR:
case MODOP_EXPR:
--- 7888,7902 ----
NULL_TREE, NULL_TREE);
case CALL_EXPR:
! {
! int n = VL_EXP_OPERAND_LENGTH (t);
! tree result = build_vl_exp (CALL_EXPR, n);
! int i;
! for (i = 0; i < n; i++)
! TREE_OPERAND (t, i) = tsubst_copy (TREE_OPERAND (t, i), args,
! complain, in_decl);
! return result;
! }
case COND_EXPR:
case MODOP_EXPR:
*************** tsubst_copy_and_build (tree t,
*** 8802,8807 ****
--- 8804,8810 ----
qualified_p = true;
}
+ /* FIXME: Rewrite this so as not to construct an arglist. */
call_args = RECUR (CALL_EXPR_ARGS (t));
/* We do not perform argument-dependent lookup if normal
Index: gcc/java/builtins.c
===================================================================
*** gcc/java/builtins.c (revision 116083)
--- gcc/java/builtins.c (working copy)
*************** abs_builtin (tree method_return_type, tr
*** 131,137 ****
static tree
java_build_function_call_expr (tree fn, tree orig_call)
{
! switch (call_expr_nargs (orig_call))
{
case 0:
return build_call_expr (fn, 0);
--- 131,138 ----
static tree
java_build_function_call_expr (tree fn, tree orig_call)
{
! int nargs = call_expr_nargs (orig_call);
! switch (nargs)
{
case 0:
return build_call_expr (fn, 0);
*************** java_build_function_call_expr (tree fn,
*** 147,153 ****
CALL_EXPR_ARG1 (orig_call),
CALL_EXPR_ARG2 (orig_call));
default:
! return build_function_call_expr (fn, CALL_EXPR_ARGS (orig_call));
}
}
--- 148,159 ----
CALL_EXPR_ARG1 (orig_call),
CALL_EXPR_ARG2 (orig_call));
default:
! {
! tree fntype = TREE_TYPE (fn);
! fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fn);
! return fold (build_call_array (CALL_EXPR, TREE_TYPE (fntype),
! fn, nargs, CALL_EXPR_ARGP (orig_call)));
! }
}
}
Index: gcc/java/java-tree.def
===================================================================
*** gcc/java/java-tree.def (revision 116083)
--- gcc/java/java-tree.def (working copy)
*************** DEFTREECODE (NEW_ANONYMOUS_ARRAY_EXPR, "
*** 34,41 ****
that of CALL_EXPRs. Operand 0 is an INTEGER_CST node containing the operand
count, operand 1 is the name of the class to be created. The argument
list used to select a constructor follows beginning with operand 3.
! There is no operand 2. That slot is used for the
! CALL_EXPR_RTL macro (see preexpand_calls).
The type should be the one of the created class. */
DEFTREECODE (NEW_CLASS_EXPR, "new_class_expr", tcc_vl_exp, 3)
--- 34,40 ----
that of CALL_EXPRs. Operand 0 is an INTEGER_CST node containing the operand
count, operand 1 is the name of the class to be created. The argument
list used to select a constructor follows beginning with operand 3.
! There is no operand 2.
The type should be the one of the created class. */
DEFTREECODE (NEW_CLASS_EXPR, "new_class_expr", tcc_vl_exp, 3)