* [PATCH] remove build_call_list from Ada/Java/middle-end
@ 2010-05-17 0:40 Nathan Froyd
2010-05-17 9:49 ` Richard Guenther
2010-05-17 10:12 ` Eric Botcazou
0 siblings, 2 replies; 4+ messages in thread
From: Nathan Froyd @ 2010-05-17 0:40 UTC (permalink / raw)
To: gcc-patches, java-patches
The patch below removes all calls to build_call_list from the Ada and
Java front-ends. Since those are the last remaining uses of
build_call_list, build_call_list can be removed from the compiler
entirely. One less obstacle to removing TREE_LIST...
Regtested on x86_64-unknown-linux-gnu. OK to commit?
-Nathan
gcc/
* tree.h (build_call_list): Remove.
* tree.c (build_call_list): Remove.
gcc/ada/
* gcc-interface/trans.c (call_to_gnu): Use build_call_vec instead of
build_call_list.
* gcc-interface/utils.c (build_function_stub): Likewise.
gcc/java/
* expr.c (expand_java_multianewarray): Use build_call_vec instead of
build_call_list.
(pop_arguments): Return a VEC instead of a tree. Take a method type
rather than a list of argument types.
(rewrite_rule): Change signature. of rewrite_arglist member.
(rewrite_arglist_getcaller): Update signature.
(rewrite_arglist_getclass): Likewise.
(maybe_rewrite_invocation): Update for rewrite_arglist change.
(build_known_method_ref): Take a VEC instead of a tree.
(invoke_build_dtable): Likewise.
(expand_invoke): Update calls to pop_arguments. Use build_call_vec
instead of build_call_list.
(build_jni_stub): Use build_call_vec instead of build_call_list.
* java-tree.h (maybe_rewrite_invocation): Update declaration.
(build_known_method_ref): Likewise.
(invoke_build_dtable): Likewise.
gcc/cp/
* tree.c (build_min_non_dep_call_vec): Update comment.
diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c
index c6bad43..22772b9 100644
--- a/gcc/ada/gcc-interface/trans.c
+++ b/gcc/ada/gcc-interface/trans.c
@@ -2619,7 +2619,7 @@ call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target)
tree gnu_subprog_addr = build_unary_op (ADDR_EXPR, NULL_TREE, gnu_subprog);
Entity_Id gnat_formal;
Node_Id gnat_actual;
- tree gnu_actual_list = NULL_TREE;
+ VEC(tree,gc) *gnu_actual_vec = NULL;
tree gnu_name_list = NULL_TREE;
tree gnu_before_list = NULL_TREE;
tree gnu_after_list = NULL_TREE;
@@ -2969,11 +2969,11 @@ call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target)
gnu_actual = convert (DECL_ARG_TYPE (gnu_formal), gnu_actual);
}
- gnu_actual_list = tree_cons (NULL_TREE, gnu_actual, gnu_actual_list);
+ VEC_safe_push (tree, gc, gnu_actual_vec, gnu_actual);
}
- gnu_call = build_call_list (TREE_TYPE (gnu_subprog_type), gnu_subprog_addr,
- nreverse (gnu_actual_list));
+ gnu_call = build_call_vec (TREE_TYPE (gnu_subprog_type), gnu_subprog_addr,
+ gnu_actual_vec);
set_expr_location_from_node (gnu_call, gnat_node);
/* If it's a function call, the result is the call expression unless a target
diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c
index 4b11923..4e91542 100644
--- a/gcc/ada/gcc-interface/utils.c
+++ b/gcc/ada/gcc-interface/utils.c
@@ -3245,12 +3245,12 @@ void
build_function_stub (tree gnu_subprog, Entity_Id gnat_subprog)
{
tree gnu_subprog_type, gnu_subprog_addr, gnu_subprog_call;
- tree gnu_stub_param, gnu_param_list, gnu_arg_types, gnu_param;
+ tree gnu_stub_param, gnu_arg_types, gnu_param;
tree gnu_stub_decl = DECL_FUNCTION_STUB (gnu_subprog);
tree gnu_body;
+ VEC(tree,gc) *gnu_param_vec = NULL;
gnu_subprog_type = TREE_TYPE (gnu_subprog);
- gnu_param_list = NULL_TREE;
begin_subprog_body (gnu_stub_decl);
gnat_pushlevel ();
@@ -3274,7 +3274,7 @@ build_function_stub (tree gnu_subprog, Entity_Id gnat_subprog)
else
gnu_param = gnu_stub_param;
- gnu_param_list = tree_cons (NULL_TREE, gnu_param, gnu_param_list);
+ VEC_safe_push (tree, gc, gnu_param_vec, gnu_param);
}
gnu_body = end_stmt_group ();
@@ -3282,9 +3282,8 @@ build_function_stub (tree gnu_subprog, Entity_Id gnat_subprog)
/* Invoke the internal subprogram. */
gnu_subprog_addr = build1 (ADDR_EXPR, build_pointer_type (gnu_subprog_type),
gnu_subprog);
- gnu_subprog_call = build_call_list (TREE_TYPE (gnu_subprog_type),
- gnu_subprog_addr,
- nreverse (gnu_param_list));
+ gnu_subprog_call = build_call_vec (TREE_TYPE (gnu_subprog_type),
+ gnu_subprog_addr, gnu_param_vec);
/* Propagate the return value, if any. */
if (VOID_TYPE_P (TREE_TYPE (gnu_subprog_type)))
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 67bbd60..bfe65b8 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -1905,9 +1905,9 @@ build_min_non_dep (enum tree_code code, tree non_dep, ...)
return t;
}
-/* Similar to `build_call_list', but for template definitions of non-dependent
- expressions. NON_DEP is the non-dependent expression that has been
- built. */
+/* Similar to `build_nt_call_vec', but for template definitions of
+ non-dependent expressions. NON_DEP is the non-dependent expression
+ that has been built. */
tree
build_min_non_dep_call_vec (tree non_dep, tree fn, VEC(tree,gc) *argvec)
diff --git a/gcc/java/expr.c b/gcc/java/expr.c
index a6a3f39..5eacd64 100644
--- a/gcc/java/expr.c
+++ b/gcc/java/expr.c
@@ -75,7 +75,7 @@ static void expand_cond (enum tree_code, tree, int);
static void expand_java_goto (int);
static tree expand_java_switch (tree, int);
static void expand_java_add_case (tree, int, int);
-static tree pop_arguments (tree);
+static VEC(tree,gc) *pop_arguments (tree);
static void expand_invoke (int, int, int);
static void expand_java_field_op (int, int, int);
static void java_push_constant_from_pool (struct JCF *, int);
@@ -1128,20 +1128,21 @@ static void
expand_java_multianewarray (tree class_type, int ndim)
{
int i;
- tree args = build_tree_list( NULL_TREE, null_pointer_node );
+ VEC(tree,gc) *args = NULL;
- for( i = 0; i < ndim; i++ )
- args = tree_cons (NULL_TREE, pop_value (int_type_node), args);
+ VEC_safe_grow (tree, gc, args, 3 + ndim);
- args = tree_cons (NULL_TREE,
- build_class_ref (class_type),
- tree_cons (NULL_TREE,
- build_int_cst (NULL_TREE, ndim),
- args));
+ VEC_replace (tree, args, 0, build_class_ref (class_type));
+ VEC_replace (tree, args, 1, build_int_cst (NULL_TREE, ndim));
- push_value (build_call_list (promote_type (class_type),
- build_address_of (soft_multianewarray_node),
- args));
+ for(i = ndim - 1; i >= 0; i-- )
+ VEC_replace (tree, args, (unsigned)(2 + i), pop_value (int_type_node));
+
+ VEC_replace (tree, args, 2 + ndim, null_pointer_node);
+
+ push_value (build_call_vec (promote_type (class_type),
+ build_address_of (soft_multianewarray_node),
+ args));
}
/* ARRAY[INDEX] <- RHS. build_java_check_indexed_type makes sure that
@@ -1931,16 +1932,28 @@ expand_java_add_case (tree switch_expr, int match, int target_pc)
append_to_statement_list (x, &SWITCH_BODY (switch_expr));
}
-static tree
-pop_arguments (tree arg_types)
+static VEC(tree,gc) *
+pop_arguments (tree method_type)
{
- if (arg_types == end_params_node)
- return NULL_TREE;
- if (TREE_CODE (arg_types) == TREE_LIST)
+ function_args_iterator fnai;
+ tree type;
+ VEC(tree,gc) *args = NULL;
+ int arity;
+
+ FOREACH_FUNCTION_ARGS (method_type, type, fnai)
+ {
+ /* XXX: leaky abstraction. */
+ if (type == void_type_node)
+ break;
+
+ VEC_safe_push (tree, gc, args, type);
+ }
+
+ arity = VEC_length (tree, typestack);
+
+ while (arity--)
{
- tree tail = pop_arguments (TREE_CHAIN (arg_types));
- tree type = TREE_VALUE (arg_types);
- tree arg = pop_value (type);
+ tree arg = pop_value (VEC_index (tree, args, arity));
/* We simply cast each argument to its proper type. This is
needed since we lose type information coming out of the
@@ -1952,9 +1965,11 @@ pop_arguments (tree arg_types)
&& TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
&& INTEGRAL_TYPE_P (type))
arg = convert (integer_type_node, arg);
- return tree_cons (NULL_TREE, arg, tail);
+
+ VEC_replace (tree, args, arity, arg);
}
- gcc_unreachable ();
+
+ return args;
}
/* Attach to PTR (a block) the declaration found in ENTRY. */
@@ -2079,34 +2094,30 @@ typedef struct
const char *new_classname;
const char *new_signature;
int flags;
- tree (*rewrite_arglist) (tree arglist);
+ void (*rewrite_arglist) (VEC(tree,gc) **);
} rewrite_rule;
/* Add __builtin_return_address(0) to the end of an arglist. */
-static tree
-rewrite_arglist_getcaller (tree arglist)
+static void
+rewrite_arglist_getcaller (VEC(tree,gc) **arglist)
{
tree retaddr
= build_call_expr (built_in_decls[BUILT_IN_RETURN_ADDRESS],
1, integer_zero_node);
DECL_UNINLINABLE (current_function_decl) = 1;
-
- return chainon (arglist,
- tree_cons (NULL_TREE, retaddr,
- NULL_TREE));
+
+ VEC_safe_push (tree, gc, *arglist, retaddr);
}
/* Add this.class to the end of an arglist. */
-static tree
-rewrite_arglist_getclass (tree arglist)
+static void
+rewrite_arglist_getclass (VEC(tree,gc) **arglist)
{
- return chainon (arglist,
- tree_cons (NULL_TREE, build_class_ref (output_class),
- NULL_TREE));
+ VEC_safe_push (tree, gc, *arglist, build_class_ref (output_class));
}
static rewrite_rule rules[] =
@@ -2157,7 +2168,7 @@ special_method_p (tree candidate_method)
method, update SPECIAL.*/
void
-maybe_rewrite_invocation (tree *method_p, tree *arg_list_p,
+maybe_rewrite_invocation (tree *method_p, VEC(tree,gc) **arg_list_p,
tree *method_signature_p, tree *special)
{
tree context = DECL_NAME (TYPE_NAME (DECL_CONTEXT (*method_p)));
@@ -2190,7 +2201,7 @@ maybe_rewrite_invocation (tree *method_p, tree *arg_list_p,
*method_p = maybe_method;
gcc_assert (*method_p);
if (p->rewrite_arglist)
- *arg_list_p = p->rewrite_arglist (*arg_list_p);
+ p->rewrite_arglist (arg_list_p);
*method_signature_p = get_identifier (p->new_signature);
*special = integer_one_node;
@@ -2205,7 +2216,7 @@ maybe_rewrite_invocation (tree *method_p, tree *arg_list_p,
tree
build_known_method_ref (tree method, tree method_type ATTRIBUTE_UNUSED,
tree self_type, tree method_signature ATTRIBUTE_UNUSED,
- tree arg_list ATTRIBUTE_UNUSED, tree special)
+ VEC(tree,gc) *arg_list ATTRIBUTE_UNUSED, tree special)
{
tree func;
if (is_compiled_class (self_type))
@@ -2282,18 +2293,19 @@ build_known_method_ref (tree method, tree method_type ATTRIBUTE_UNUSED,
}
tree
-invoke_build_dtable (int is_invoke_interface, tree arg_list)
+invoke_build_dtable (int is_invoke_interface, VEC(tree,gc) *arg_list)
{
tree dtable, objectref;
+ tree saved = save_expr (VEC_index (tree, arg_list, 0));
- TREE_VALUE (arg_list) = save_expr (TREE_VALUE (arg_list));
+ VEC_replace (tree, arg_list, 0, saved);
/* If we're dealing with interfaces and if the objectref
argument is an array then get the dispatch table of the class
Object rather than the one from the objectref. */
objectref = (is_invoke_interface
- && is_array_type_p (TREE_TYPE (TREE_VALUE (arg_list)))
- ? build_class_ref (object_type_node) : TREE_VALUE (arg_list));
+ && is_array_type_p (TREE_TYPE (saved))
+ ? build_class_ref (object_type_node) : saved);
if (dtable_ident == NULL_TREE)
dtable_ident = get_identifier ("vtable");
@@ -2461,7 +2473,8 @@ expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
method_ref_index));
const char *const self_name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (self_type)));
- tree call, func, method, arg_list, method_type;
+ tree call, func, method, method_type;
+ VEC(tree,gc) *arg_list;
tree check = NULL_TREE;
tree special = NULL_TREE;
@@ -2568,7 +2581,7 @@ expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
just pop the arguments, push a properly-typed zero, and
continue. */
method_type = get_type_from_signature (method_signature);
- pop_arguments (TYPE_ARG_TYPES (method_type));
+ pop_arguments (method_type);
if (opcode != OPCODE_invokestatic)
pop_type (self_type);
method_type = promote_type (TREE_TYPE (method_type));
@@ -2577,7 +2590,7 @@ expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
}
method_type = TREE_TYPE (method);
- arg_list = pop_arguments (TYPE_ARG_TYPES (method_type));
+ arg_list = pop_arguments (method_type);
flush_quick_stack ();
maybe_rewrite_invocation (&method, &arg_list, &method_signature,
@@ -2602,8 +2615,8 @@ expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
We do omit the check if we're calling <init>. */
/* We use a SAVE_EXPR here to make sure we only evaluate
the new `self' expression once. */
- tree save_arg = save_expr (TREE_VALUE (arg_list));
- TREE_VALUE (arg_list) = save_arg;
+ tree save_arg = save_expr (VEC_index (tree, arg_list, 0));
+ VEC_replace (tree, arg_list, 0, save_arg);
check = java_check_reference (save_arg, ! DECL_INIT_P (method));
func = build_known_method_ref (method, method_type, self_type,
method_signature, arg_list, special);
@@ -2623,7 +2636,7 @@ expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
else
func = build1 (NOP_EXPR, build_pointer_type (method_type), func);
- call = build_call_list (TREE_TYPE (method_type), func, arg_list);
+ call = build_call_vec (TREE_TYPE (method_type), func, arg_list);
TREE_SIDE_EFFECTS (call) = 1;
call = check_for_builtin (method, call);
@@ -2648,14 +2661,14 @@ expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
tree
build_jni_stub (tree method)
{
- tree jnifunc, call, args, body, method_sig, arg_types;
+ tree jnifunc, call, body, method_sig, arg_types;
tree jniarg0, jniarg1, jniarg2, jniarg3;
tree jni_func_type, tem;
tree env_var, res_var = NULL_TREE, block;
tree method_args;
tree meth_var;
tree bind;
-
+ VEC(tree,gc) *args = NULL;
int args_size = 0;
tree klass = DECL_CONTEXT (method);
@@ -2689,10 +2702,22 @@ build_jni_stub (tree method)
build_address_of (soft_getjnienvnewframe_node),
1, klass));
+ /* The JNIEnv structure is the first argument to the JNI function. */
+ args_size += int_size_in_bytes (TREE_TYPE (env_var));
+ VEC_safe_push (tree, gc, args, env_var);
+
+ /* For a static method the second argument is the class. For a
+ non-static method the second argument is `this'; that is already
+ available in the argument list. */
+ if (METHOD_STATIC (method))
+ {
+ args_size += int_size_in_bytes (TREE_TYPE (klass));
+ VEC_safe_push (tree, gc, args, klass);
+ }
+
/* All the arguments to this method become arguments to the
underlying JNI function. If we had to wrap object arguments in a
special way, we would do that here. */
- args = NULL_TREE;
for (tem = method_args; tem != NULL_TREE; tem = TREE_CHAIN (tem))
{
int arg_bits = TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tem)));
@@ -2702,24 +2727,14 @@ build_jni_stub (tree method)
#endif
args_size += (arg_bits / BITS_PER_UNIT);
- args = tree_cons (NULL_TREE, tem, args);
+ VEC_safe_push (tree, gc, args, tem);
}
- args = nreverse (args);
arg_types = TYPE_ARG_TYPES (TREE_TYPE (method));
- /* For a static method the second argument is the class. For a
- non-static method the second argument is `this'; that is already
- available in the argument list. */
+ /* Argument types for static methods and the JNIEnv structure.
+ FIXME: Write and use build_function_type_vec to avoid this. */
if (METHOD_STATIC (method))
- {
- args_size += int_size_in_bytes (TREE_TYPE (klass));
- args = tree_cons (NULL_TREE, klass, args);
- arg_types = tree_cons (NULL_TREE, object_ptr_type_node, arg_types);
- }
-
- /* The JNIEnv structure is the first argument to the JNI function. */
- args_size += int_size_in_bytes (TREE_TYPE (env_var));
- args = tree_cons (NULL_TREE, env_var, args);
+ arg_types = tree_cons (NULL_TREE, object_ptr_type_node, arg_types);
arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types);
/* We call _Jv_LookupJNIMethod to find the actual underlying
@@ -2774,8 +2789,7 @@ build_jni_stub (tree method)
/* Now we make the actual JNI call via the resulting function
pointer. */
- call = build_call_list (TREE_TYPE (TREE_TYPE (method)),
- jnifunc, args);
+ call = build_call_vec (TREE_TYPE (TREE_TYPE (method)), jnifunc, args);
/* If the JNI call returned a result, capture it here. If we had to
unwrap JNI object results, we would do that here. */
diff --git a/gcc/java/java-tree.h b/gcc/java/java-tree.h
index 8ffe242..26e6268 100644
--- a/gcc/java/java-tree.h
+++ b/gcc/java/java-tree.h
@@ -1067,14 +1067,14 @@ extern void initialize_builtins (void);
extern tree lookup_name (tree);
extern bool special_method_p (tree);
-extern void maybe_rewrite_invocation (tree *, tree *, tree *, tree *);
-extern tree build_known_method_ref (tree, tree, tree, tree, tree, tree);
+extern void maybe_rewrite_invocation (tree *, VEC(tree,gc) **, tree *, tree *);
+extern tree build_known_method_ref (tree, tree, tree, tree, VEC(tree,gc) *, tree);
extern tree build_class_init (tree, tree);
extern int attach_init_test_initialization_flags (void **, void *);
extern tree build_invokevirtual (tree, tree, tree);
extern tree build_invokeinterface (tree, tree);
extern tree build_jni_stub (tree);
-extern tree invoke_build_dtable (int, tree);
+extern tree invoke_build_dtable (int, VEC(tree,gc) *);
extern tree build_field_ref (tree, tree, tree);
extern tree java_modify_addr_for_volatile (tree);
extern void pushdecl_force_head (tree);
diff --git a/gcc/tree.c b/gcc/tree.c
index c45e807..a7e483e 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -9501,27 +9501,6 @@ build_vl_exp_stat (enum tree_code code, int len MEM_STAT_DECL)
return t;
}
-
-/* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE
- and FN and a null static chain slot. ARGLIST is a TREE_LIST of the
- arguments. */
-
-tree
-build_call_list (tree return_type, tree fn, tree arglist)
-{
- tree t;
- int i;
-
- t = build_vl_exp (CALL_EXPR, list_length (arglist) + 3);
- TREE_TYPE (t) = return_type;
- CALL_EXPR_FN (t) = fn;
- CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
- for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++)
- CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist);
- process_call_operands (t);
- return t;
-}
-
/* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
FN and a null static chain slot. NARGS is the number of call arguments
which are specified as "..." arguments. */
diff --git a/gcc/tree.h b/gcc/tree.h
index 7eed68f..253e6ef 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4040,7 +4040,6 @@ extern tree build_omp_clause (location_t, enum omp_clause_code);
extern tree build_vl_exp_stat (enum tree_code, int MEM_STAT_DECL);
#define build_vl_exp(c,n) build_vl_exp_stat (c,n MEM_STAT_INFO)
-extern tree build_call_list (tree, tree, tree);
extern tree build_call_nary (tree, tree, int, ...);
extern tree build_call_valist (tree, tree, int, va_list);
#define build_call_array(T1,T2,N,T3)\
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] remove build_call_list from Ada/Java/middle-end
2010-05-17 0:40 [PATCH] remove build_call_list from Ada/Java/middle-end Nathan Froyd
@ 2010-05-17 9:49 ` Richard Guenther
2010-05-17 9:53 ` Andrew Haley
2010-05-17 10:12 ` Eric Botcazou
1 sibling, 1 reply; 4+ messages in thread
From: Richard Guenther @ 2010-05-17 9:49 UTC (permalink / raw)
To: Nathan Froyd; +Cc: gcc-patches, java-patches
On Mon, May 17, 2010 at 2:40 AM, Nathan Froyd <froydnj@codesourcery.com> wrote:
> The patch below removes all calls to build_call_list from the Ada and
> Java front-ends. Since those are the last remaining uses of
> build_call_list, build_call_list can be removed from the compiler
> entirely. One less obstacle to removing TREE_LIST...
>
> Regtested on x86_64-unknown-linux-gnu. OK to commit?
The middle-end parts are ok.
Thanks,
Richard.
> -Nathan
>
> gcc/
> * tree.h (build_call_list): Remove.
> * tree.c (build_call_list): Remove.
>
> gcc/ada/
> * gcc-interface/trans.c (call_to_gnu): Use build_call_vec instead of
> build_call_list.
> * gcc-interface/utils.c (build_function_stub): Likewise.
>
> gcc/java/
> * expr.c (expand_java_multianewarray): Use build_call_vec instead of
> build_call_list.
> (pop_arguments): Return a VEC instead of a tree. Take a method type
> rather than a list of argument types.
> (rewrite_rule): Change signature. of rewrite_arglist member.
> (rewrite_arglist_getcaller): Update signature.
> (rewrite_arglist_getclass): Likewise.
> (maybe_rewrite_invocation): Update for rewrite_arglist change.
> (build_known_method_ref): Take a VEC instead of a tree.
> (invoke_build_dtable): Likewise.
> (expand_invoke): Update calls to pop_arguments. Use build_call_vec
> instead of build_call_list.
> (build_jni_stub): Use build_call_vec instead of build_call_list.
> * java-tree.h (maybe_rewrite_invocation): Update declaration.
> (build_known_method_ref): Likewise.
> (invoke_build_dtable): Likewise.
>
> gcc/cp/
> * tree.c (build_min_non_dep_call_vec): Update comment.
>
> diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c
> index c6bad43..22772b9 100644
> --- a/gcc/ada/gcc-interface/trans.c
> +++ b/gcc/ada/gcc-interface/trans.c
> @@ -2619,7 +2619,7 @@ call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target)
> tree gnu_subprog_addr = build_unary_op (ADDR_EXPR, NULL_TREE, gnu_subprog);
> Entity_Id gnat_formal;
> Node_Id gnat_actual;
> - tree gnu_actual_list = NULL_TREE;
> + VEC(tree,gc) *gnu_actual_vec = NULL;
> tree gnu_name_list = NULL_TREE;
> tree gnu_before_list = NULL_TREE;
> tree gnu_after_list = NULL_TREE;
> @@ -2969,11 +2969,11 @@ call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target)
> gnu_actual = convert (DECL_ARG_TYPE (gnu_formal), gnu_actual);
> }
>
> - gnu_actual_list = tree_cons (NULL_TREE, gnu_actual, gnu_actual_list);
> + VEC_safe_push (tree, gc, gnu_actual_vec, gnu_actual);
> }
>
> - gnu_call = build_call_list (TREE_TYPE (gnu_subprog_type), gnu_subprog_addr,
> - nreverse (gnu_actual_list));
> + gnu_call = build_call_vec (TREE_TYPE (gnu_subprog_type), gnu_subprog_addr,
> + gnu_actual_vec);
> set_expr_location_from_node (gnu_call, gnat_node);
>
> /* If it's a function call, the result is the call expression unless a target
> diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c
> index 4b11923..4e91542 100644
> --- a/gcc/ada/gcc-interface/utils.c
> +++ b/gcc/ada/gcc-interface/utils.c
> @@ -3245,12 +3245,12 @@ void
> build_function_stub (tree gnu_subprog, Entity_Id gnat_subprog)
> {
> tree gnu_subprog_type, gnu_subprog_addr, gnu_subprog_call;
> - tree gnu_stub_param, gnu_param_list, gnu_arg_types, gnu_param;
> + tree gnu_stub_param, gnu_arg_types, gnu_param;
> tree gnu_stub_decl = DECL_FUNCTION_STUB (gnu_subprog);
> tree gnu_body;
> + VEC(tree,gc) *gnu_param_vec = NULL;
>
> gnu_subprog_type = TREE_TYPE (gnu_subprog);
> - gnu_param_list = NULL_TREE;
>
> begin_subprog_body (gnu_stub_decl);
> gnat_pushlevel ();
> @@ -3274,7 +3274,7 @@ build_function_stub (tree gnu_subprog, Entity_Id gnat_subprog)
> else
> gnu_param = gnu_stub_param;
>
> - gnu_param_list = tree_cons (NULL_TREE, gnu_param, gnu_param_list);
> + VEC_safe_push (tree, gc, gnu_param_vec, gnu_param);
> }
>
> gnu_body = end_stmt_group ();
> @@ -3282,9 +3282,8 @@ build_function_stub (tree gnu_subprog, Entity_Id gnat_subprog)
> /* Invoke the internal subprogram. */
> gnu_subprog_addr = build1 (ADDR_EXPR, build_pointer_type (gnu_subprog_type),
> gnu_subprog);
> - gnu_subprog_call = build_call_list (TREE_TYPE (gnu_subprog_type),
> - gnu_subprog_addr,
> - nreverse (gnu_param_list));
> + gnu_subprog_call = build_call_vec (TREE_TYPE (gnu_subprog_type),
> + gnu_subprog_addr, gnu_param_vec);
>
> /* Propagate the return value, if any. */
> if (VOID_TYPE_P (TREE_TYPE (gnu_subprog_type)))
> diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
> index 67bbd60..bfe65b8 100644
> --- a/gcc/cp/tree.c
> +++ b/gcc/cp/tree.c
> @@ -1905,9 +1905,9 @@ build_min_non_dep (enum tree_code code, tree non_dep, ...)
> return t;
> }
>
> -/* Similar to `build_call_list', but for template definitions of non-dependent
> - expressions. NON_DEP is the non-dependent expression that has been
> - built. */
> +/* Similar to `build_nt_call_vec', but for template definitions of
> + non-dependent expressions. NON_DEP is the non-dependent expression
> + that has been built. */
>
> tree
> build_min_non_dep_call_vec (tree non_dep, tree fn, VEC(tree,gc) *argvec)
> diff --git a/gcc/java/expr.c b/gcc/java/expr.c
> index a6a3f39..5eacd64 100644
> --- a/gcc/java/expr.c
> +++ b/gcc/java/expr.c
> @@ -75,7 +75,7 @@ static void expand_cond (enum tree_code, tree, int);
> static void expand_java_goto (int);
> static tree expand_java_switch (tree, int);
> static void expand_java_add_case (tree, int, int);
> -static tree pop_arguments (tree);
> +static VEC(tree,gc) *pop_arguments (tree);
> static void expand_invoke (int, int, int);
> static void expand_java_field_op (int, int, int);
> static void java_push_constant_from_pool (struct JCF *, int);
> @@ -1128,20 +1128,21 @@ static void
> expand_java_multianewarray (tree class_type, int ndim)
> {
> int i;
> - tree args = build_tree_list( NULL_TREE, null_pointer_node );
> + VEC(tree,gc) *args = NULL;
>
> - for( i = 0; i < ndim; i++ )
> - args = tree_cons (NULL_TREE, pop_value (int_type_node), args);
> + VEC_safe_grow (tree, gc, args, 3 + ndim);
>
> - args = tree_cons (NULL_TREE,
> - build_class_ref (class_type),
> - tree_cons (NULL_TREE,
> - build_int_cst (NULL_TREE, ndim),
> - args));
> + VEC_replace (tree, args, 0, build_class_ref (class_type));
> + VEC_replace (tree, args, 1, build_int_cst (NULL_TREE, ndim));
>
> - push_value (build_call_list (promote_type (class_type),
> - build_address_of (soft_multianewarray_node),
> - args));
> + for(i = ndim - 1; i >= 0; i-- )
> + VEC_replace (tree, args, (unsigned)(2 + i), pop_value (int_type_node));
> +
> + VEC_replace (tree, args, 2 + ndim, null_pointer_node);
> +
> + push_value (build_call_vec (promote_type (class_type),
> + build_address_of (soft_multianewarray_node),
> + args));
> }
>
> /* ARRAY[INDEX] <- RHS. build_java_check_indexed_type makes sure that
> @@ -1931,16 +1932,28 @@ expand_java_add_case (tree switch_expr, int match, int target_pc)
> append_to_statement_list (x, &SWITCH_BODY (switch_expr));
> }
>
> -static tree
> -pop_arguments (tree arg_types)
> +static VEC(tree,gc) *
> +pop_arguments (tree method_type)
> {
> - if (arg_types == end_params_node)
> - return NULL_TREE;
> - if (TREE_CODE (arg_types) == TREE_LIST)
> + function_args_iterator fnai;
> + tree type;
> + VEC(tree,gc) *args = NULL;
> + int arity;
> +
> + FOREACH_FUNCTION_ARGS (method_type, type, fnai)
> + {
> + /* XXX: leaky abstraction. */
> + if (type == void_type_node)
> + break;
> +
> + VEC_safe_push (tree, gc, args, type);
> + }
> +
> + arity = VEC_length (tree, typestack);
> +
> + while (arity--)
> {
> - tree tail = pop_arguments (TREE_CHAIN (arg_types));
> - tree type = TREE_VALUE (arg_types);
> - tree arg = pop_value (type);
> + tree arg = pop_value (VEC_index (tree, args, arity));
>
> /* We simply cast each argument to its proper type. This is
> needed since we lose type information coming out of the
> @@ -1952,9 +1965,11 @@ pop_arguments (tree arg_types)
> && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
> && INTEGRAL_TYPE_P (type))
> arg = convert (integer_type_node, arg);
> - return tree_cons (NULL_TREE, arg, tail);
> +
> + VEC_replace (tree, args, arity, arg);
> }
> - gcc_unreachable ();
> +
> + return args;
> }
>
> /* Attach to PTR (a block) the declaration found in ENTRY. */
> @@ -2079,34 +2094,30 @@ typedef struct
> const char *new_classname;
> const char *new_signature;
> int flags;
> - tree (*rewrite_arglist) (tree arglist);
> + void (*rewrite_arglist) (VEC(tree,gc) **);
> } rewrite_rule;
>
> /* Add __builtin_return_address(0) to the end of an arglist. */
>
>
> -static tree
> -rewrite_arglist_getcaller (tree arglist)
> +static void
> +rewrite_arglist_getcaller (VEC(tree,gc) **arglist)
> {
> tree retaddr
> = build_call_expr (built_in_decls[BUILT_IN_RETURN_ADDRESS],
> 1, integer_zero_node);
>
> DECL_UNINLINABLE (current_function_decl) = 1;
> -
> - return chainon (arglist,
> - tree_cons (NULL_TREE, retaddr,
> - NULL_TREE));
> +
> + VEC_safe_push (tree, gc, *arglist, retaddr);
> }
>
> /* Add this.class to the end of an arglist. */
>
> -static tree
> -rewrite_arglist_getclass (tree arglist)
> +static void
> +rewrite_arglist_getclass (VEC(tree,gc) **arglist)
> {
> - return chainon (arglist,
> - tree_cons (NULL_TREE, build_class_ref (output_class),
> - NULL_TREE));
> + VEC_safe_push (tree, gc, *arglist, build_class_ref (output_class));
> }
>
> static rewrite_rule rules[] =
> @@ -2157,7 +2168,7 @@ special_method_p (tree candidate_method)
> method, update SPECIAL.*/
>
> void
> -maybe_rewrite_invocation (tree *method_p, tree *arg_list_p,
> +maybe_rewrite_invocation (tree *method_p, VEC(tree,gc) **arg_list_p,
> tree *method_signature_p, tree *special)
> {
> tree context = DECL_NAME (TYPE_NAME (DECL_CONTEXT (*method_p)));
> @@ -2190,7 +2201,7 @@ maybe_rewrite_invocation (tree *method_p, tree *arg_list_p,
> *method_p = maybe_method;
> gcc_assert (*method_p);
> if (p->rewrite_arglist)
> - *arg_list_p = p->rewrite_arglist (*arg_list_p);
> + p->rewrite_arglist (arg_list_p);
> *method_signature_p = get_identifier (p->new_signature);
> *special = integer_one_node;
>
> @@ -2205,7 +2216,7 @@ maybe_rewrite_invocation (tree *method_p, tree *arg_list_p,
> tree
> build_known_method_ref (tree method, tree method_type ATTRIBUTE_UNUSED,
> tree self_type, tree method_signature ATTRIBUTE_UNUSED,
> - tree arg_list ATTRIBUTE_UNUSED, tree special)
> + VEC(tree,gc) *arg_list ATTRIBUTE_UNUSED, tree special)
> {
> tree func;
> if (is_compiled_class (self_type))
> @@ -2282,18 +2293,19 @@ build_known_method_ref (tree method, tree method_type ATTRIBUTE_UNUSED,
> }
>
> tree
> -invoke_build_dtable (int is_invoke_interface, tree arg_list)
> +invoke_build_dtable (int is_invoke_interface, VEC(tree,gc) *arg_list)
> {
> tree dtable, objectref;
> + tree saved = save_expr (VEC_index (tree, arg_list, 0));
>
> - TREE_VALUE (arg_list) = save_expr (TREE_VALUE (arg_list));
> + VEC_replace (tree, arg_list, 0, saved);
>
> /* If we're dealing with interfaces and if the objectref
> argument is an array then get the dispatch table of the class
> Object rather than the one from the objectref. */
> objectref = (is_invoke_interface
> - && is_array_type_p (TREE_TYPE (TREE_VALUE (arg_list)))
> - ? build_class_ref (object_type_node) : TREE_VALUE (arg_list));
> + && is_array_type_p (TREE_TYPE (saved))
> + ? build_class_ref (object_type_node) : saved);
>
> if (dtable_ident == NULL_TREE)
> dtable_ident = get_identifier ("vtable");
> @@ -2461,7 +2473,8 @@ expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
> method_ref_index));
> const char *const self_name
> = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (self_type)));
> - tree call, func, method, arg_list, method_type;
> + tree call, func, method, method_type;
> + VEC(tree,gc) *arg_list;
> tree check = NULL_TREE;
>
> tree special = NULL_TREE;
> @@ -2568,7 +2581,7 @@ expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
> just pop the arguments, push a properly-typed zero, and
> continue. */
> method_type = get_type_from_signature (method_signature);
> - pop_arguments (TYPE_ARG_TYPES (method_type));
> + pop_arguments (method_type);
> if (opcode != OPCODE_invokestatic)
> pop_type (self_type);
> method_type = promote_type (TREE_TYPE (method_type));
> @@ -2577,7 +2590,7 @@ expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
> }
>
> method_type = TREE_TYPE (method);
> - arg_list = pop_arguments (TYPE_ARG_TYPES (method_type));
> + arg_list = pop_arguments (method_type);
> flush_quick_stack ();
>
> maybe_rewrite_invocation (&method, &arg_list, &method_signature,
> @@ -2602,8 +2615,8 @@ expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
> We do omit the check if we're calling <init>. */
> /* We use a SAVE_EXPR here to make sure we only evaluate
> the new `self' expression once. */
> - tree save_arg = save_expr (TREE_VALUE (arg_list));
> - TREE_VALUE (arg_list) = save_arg;
> + tree save_arg = save_expr (VEC_index (tree, arg_list, 0));
> + VEC_replace (tree, arg_list, 0, save_arg);
> check = java_check_reference (save_arg, ! DECL_INIT_P (method));
> func = build_known_method_ref (method, method_type, self_type,
> method_signature, arg_list, special);
> @@ -2623,7 +2636,7 @@ expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
> else
> func = build1 (NOP_EXPR, build_pointer_type (method_type), func);
>
> - call = build_call_list (TREE_TYPE (method_type), func, arg_list);
> + call = build_call_vec (TREE_TYPE (method_type), func, arg_list);
> TREE_SIDE_EFFECTS (call) = 1;
> call = check_for_builtin (method, call);
>
> @@ -2648,14 +2661,14 @@ expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
> tree
> build_jni_stub (tree method)
> {
> - tree jnifunc, call, args, body, method_sig, arg_types;
> + tree jnifunc, call, body, method_sig, arg_types;
> tree jniarg0, jniarg1, jniarg2, jniarg3;
> tree jni_func_type, tem;
> tree env_var, res_var = NULL_TREE, block;
> tree method_args;
> tree meth_var;
> tree bind;
> -
> + VEC(tree,gc) *args = NULL;
> int args_size = 0;
>
> tree klass = DECL_CONTEXT (method);
> @@ -2689,10 +2702,22 @@ build_jni_stub (tree method)
> build_address_of (soft_getjnienvnewframe_node),
> 1, klass));
>
> + /* The JNIEnv structure is the first argument to the JNI function. */
> + args_size += int_size_in_bytes (TREE_TYPE (env_var));
> + VEC_safe_push (tree, gc, args, env_var);
> +
> + /* For a static method the second argument is the class. For a
> + non-static method the second argument is `this'; that is already
> + available in the argument list. */
> + if (METHOD_STATIC (method))
> + {
> + args_size += int_size_in_bytes (TREE_TYPE (klass));
> + VEC_safe_push (tree, gc, args, klass);
> + }
> +
> /* All the arguments to this method become arguments to the
> underlying JNI function. If we had to wrap object arguments in a
> special way, we would do that here. */
> - args = NULL_TREE;
> for (tem = method_args; tem != NULL_TREE; tem = TREE_CHAIN (tem))
> {
> int arg_bits = TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (tem)));
> @@ -2702,24 +2727,14 @@ build_jni_stub (tree method)
> #endif
> args_size += (arg_bits / BITS_PER_UNIT);
>
> - args = tree_cons (NULL_TREE, tem, args);
> + VEC_safe_push (tree, gc, args, tem);
> }
> - args = nreverse (args);
> arg_types = TYPE_ARG_TYPES (TREE_TYPE (method));
>
> - /* For a static method the second argument is the class. For a
> - non-static method the second argument is `this'; that is already
> - available in the argument list. */
> + /* Argument types for static methods and the JNIEnv structure.
> + FIXME: Write and use build_function_type_vec to avoid this. */
> if (METHOD_STATIC (method))
> - {
> - args_size += int_size_in_bytes (TREE_TYPE (klass));
> - args = tree_cons (NULL_TREE, klass, args);
> - arg_types = tree_cons (NULL_TREE, object_ptr_type_node, arg_types);
> - }
> -
> - /* The JNIEnv structure is the first argument to the JNI function. */
> - args_size += int_size_in_bytes (TREE_TYPE (env_var));
> - args = tree_cons (NULL_TREE, env_var, args);
> + arg_types = tree_cons (NULL_TREE, object_ptr_type_node, arg_types);
> arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types);
>
> /* We call _Jv_LookupJNIMethod to find the actual underlying
> @@ -2774,8 +2789,7 @@ build_jni_stub (tree method)
>
> /* Now we make the actual JNI call via the resulting function
> pointer. */
> - call = build_call_list (TREE_TYPE (TREE_TYPE (method)),
> - jnifunc, args);
> + call = build_call_vec (TREE_TYPE (TREE_TYPE (method)), jnifunc, args);
>
> /* If the JNI call returned a result, capture it here. If we had to
> unwrap JNI object results, we would do that here. */
> diff --git a/gcc/java/java-tree.h b/gcc/java/java-tree.h
> index 8ffe242..26e6268 100644
> --- a/gcc/java/java-tree.h
> +++ b/gcc/java/java-tree.h
> @@ -1067,14 +1067,14 @@ extern void initialize_builtins (void);
>
> extern tree lookup_name (tree);
> extern bool special_method_p (tree);
> -extern void maybe_rewrite_invocation (tree *, tree *, tree *, tree *);
> -extern tree build_known_method_ref (tree, tree, tree, tree, tree, tree);
> +extern void maybe_rewrite_invocation (tree *, VEC(tree,gc) **, tree *, tree *);
> +extern tree build_known_method_ref (tree, tree, tree, tree, VEC(tree,gc) *, tree);
> extern tree build_class_init (tree, tree);
> extern int attach_init_test_initialization_flags (void **, void *);
> extern tree build_invokevirtual (tree, tree, tree);
> extern tree build_invokeinterface (tree, tree);
> extern tree build_jni_stub (tree);
> -extern tree invoke_build_dtable (int, tree);
> +extern tree invoke_build_dtable (int, VEC(tree,gc) *);
> extern tree build_field_ref (tree, tree, tree);
> extern tree java_modify_addr_for_volatile (tree);
> extern void pushdecl_force_head (tree);
> diff --git a/gcc/tree.c b/gcc/tree.c
> index c45e807..a7e483e 100644
> --- a/gcc/tree.c
> +++ b/gcc/tree.c
> @@ -9501,27 +9501,6 @@ build_vl_exp_stat (enum tree_code code, int len MEM_STAT_DECL)
> return t;
> }
>
> -
> -/* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE
> - and FN and a null static chain slot. ARGLIST is a TREE_LIST of the
> - arguments. */
> -
> -tree
> -build_call_list (tree return_type, tree fn, tree arglist)
> -{
> - tree t;
> - int i;
> -
> - t = build_vl_exp (CALL_EXPR, list_length (arglist) + 3);
> - TREE_TYPE (t) = return_type;
> - CALL_EXPR_FN (t) = fn;
> - CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
> - for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++)
> - CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist);
> - process_call_operands (t);
> - return t;
> -}
> -
> /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
> FN and a null static chain slot. NARGS is the number of call arguments
> which are specified as "..." arguments. */
> diff --git a/gcc/tree.h b/gcc/tree.h
> index 7eed68f..253e6ef 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -4040,7 +4040,6 @@ extern tree build_omp_clause (location_t, enum omp_clause_code);
> extern tree build_vl_exp_stat (enum tree_code, int MEM_STAT_DECL);
> #define build_vl_exp(c,n) build_vl_exp_stat (c,n MEM_STAT_INFO)
>
> -extern tree build_call_list (tree, tree, tree);
> extern tree build_call_nary (tree, tree, int, ...);
> extern tree build_call_valist (tree, tree, int, va_list);
> #define build_call_array(T1,T2,N,T3)\
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] remove build_call_list from Ada/Java/middle-end
2010-05-17 9:49 ` Richard Guenther
@ 2010-05-17 9:53 ` Andrew Haley
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Haley @ 2010-05-17 9:53 UTC (permalink / raw)
To: Richard Guenther; +Cc: Nathan Froyd, gcc-patches, java-patches
On 05/17/2010 10:49 AM, Richard Guenther wrote:
> On Mon, May 17, 2010 at 2:40 AM, Nathan Froyd <froydnj@codesourcery.com> wrote:
>> The patch below removes all calls to build_call_list from the Ada and
>> Java front-ends. Since those are the last remaining uses of
>> build_call_list, build_call_list can be removed from the compiler
>> entirely. One less obstacle to removing TREE_LIST...
>>
>> Regtested on x86_64-unknown-linux-gnu. OK to commit?
>
> The middle-end parts are ok.
OK for Java.
Andrew.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] remove build_call_list from Ada/Java/middle-end
2010-05-17 0:40 [PATCH] remove build_call_list from Ada/Java/middle-end Nathan Froyd
2010-05-17 9:49 ` Richard Guenther
@ 2010-05-17 10:12 ` Eric Botcazou
1 sibling, 0 replies; 4+ messages in thread
From: Eric Botcazou @ 2010-05-17 10:12 UTC (permalink / raw)
To: Nathan Froyd; +Cc: gcc-patches, java-patches
> gcc/ada/
> * gcc-interface/trans.c (call_to_gnu): Use build_call_vec instead of
> build_call_list.
> * gcc-interface/utils.c (build_function_stub): Likewise.
OK, thanks.
--
Eric Botcazou
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-05-17 10:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-17 0:40 [PATCH] remove build_call_list from Ada/Java/middle-end Nathan Froyd
2010-05-17 9:49 ` Richard Guenther
2010-05-17 9:53 ` Andrew Haley
2010-05-17 10:12 ` Eric Botcazou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).