This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[lto] tree.c: Introduce stdarg_p.
- From: Kazu Hirata <kazu at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 9 Jun 2006 06:39:52 -0700
- Subject: [lto] tree.c: Introduce stdarg_p.
Hi,
Attached is a patch to introduce stdarg_p.
In gcc, I find many instances of idiom
(TYPE_ARG_TYPES (fntype) != 0
&& (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
!= void_type_node));
This patch proposes to replace these with a simple function call to
improve readability and make it easier to transition to the
TREE_VEC-based TREE_ARG_TYPES by hiding implementation details of
TREE_ARG_TYPES.
Tested on x86_64-pc-linux-gnu. OK to apply to the LTO branch?
p.s.
I'll work on remaining occurrences (mostly in non-i386 backends) after
this patch.
Kazu Hirata
2006-06-09 Kazu Hirata <kazu@codesourcery.com>
* tree.c (stdarg_p): New.
* tree.h: Add a prototype for stdarg_p.
* builtins.c (fold_builtin_next_arg): Call stdarg_p.
* config/i386/i386.c (ix86_return_pops_args,
ix86_setup_incoming_varargs): Likewise.
* dwarf2out.c (gen_subprogram_die): Likewise.
* function.c (allocate_struct_function): Likewise.
Index: builtins.c
===================================================================
--- builtins.c (revision 114406)
+++ builtins.c (working copy)
@@ -9524,9 +9524,7 @@ fold_builtin_next_arg (tree arglist)
{
tree fntype = TREE_TYPE (current_function_decl);
- if (TYPE_ARG_TYPES (fntype) == 0
- || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
- == void_type_node))
+ if (!stdarg_p (fntype))
{
error ("%<va_start%> used in function with fixed args");
return true;
Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c (revision 114406)
+++ config/i386/i386.c (working copy)
@@ -2623,10 +2623,7 @@ ix86_return_pops_args (tree fundecl, tre
|| lookup_attribute ("fastcall", TYPE_ATTRIBUTES (funtype)))
rtd = 1;
- if (rtd
- && (TYPE_ARG_TYPES (funtype) == NULL_TREE
- || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (funtype)))
- == void_type_node)))
+ if (rtd && !stdarg_p (funtype))
return size;
}
@@ -4041,7 +4038,6 @@ ix86_setup_incoming_varargs (CUMULATIVE_
rtx nsse_reg;
int set;
tree fntype;
- int stdarg_p;
int i;
if (!TARGET_64BIT)
@@ -4056,14 +4052,11 @@ ix86_setup_incoming_varargs (CUMULATIVE_
cfun->stack_alignment_needed = 128;
fntype = TREE_TYPE (current_function_decl);
- stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
- && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
- != void_type_node));
/* For varargs, we do not want to skip the dummy va_dcl argument.
For stdargs, we do want to skip the last named argument. */
next_cum = *cum;
- if (stdarg_p)
+ if (stdarg_p (fntype))
function_arg_advance (&next_cum, mode, type, 1);
if (!no_rtl)
Index: dwarf2out.c
===================================================================
--- dwarf2out.c (revision 114406)
+++ dwarf2out.c (working copy)
@@ -11797,7 +11797,7 @@ gen_subprogram_die (tree decl, dw_die_re
if (fn_arg_types != NULL)
{
/* This is the prototyped case, check for.... */
- if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
+ if (stdarg_p (TREE_TYPE (decl)))
gen_unspecified_parameters_die (decl, subr_die);
}
else if (DECL_INITIAL (decl) == NULL_TREE)
Index: function.c
===================================================================
--- function.c (revision 114406)
+++ function.c (working copy)
@@ -3865,11 +3865,7 @@ allocate_struct_function (tree fndecl)
current_function_returns_pointer = POINTER_TYPE_P (TREE_TYPE (result));
- current_function_stdarg
- = (fntype
- && TYPE_ARG_TYPES (fntype) != 0
- && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
- != void_type_node));
+ current_function_stdarg = fntype && stdarg_p (fntype);
/* Assume all registers in stdarg functions need to be saved. */
cfun->va_list_gpr_size = VA_LIST_MAX_GPR_SIZE;
Index: tree.c
===================================================================
--- tree.c (revision 114406)
+++ tree.c (working copy)
@@ -7573,4 +7573,14 @@ empty_body_p (tree stmt)
return true;
}
+/* Return true if function type FNTYPE is a stdarg. */
+
+bool
+stdarg_p (tree fntype)
+{
+ return (TYPE_ARG_TYPES (fntype) != 0
+ && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
+ != void_type_node));
+}
+
#include "gt-tree.h"
Index: tree.h
===================================================================
--- tree.h (revision 114406)
+++ tree.h (working copy)
@@ -4125,6 +4125,7 @@ extern tree upper_bound_in_type (tree, t
extern tree lower_bound_in_type (tree, tree);
extern int operand_equal_for_phi_arg_p (tree, tree);
extern bool empty_body_p (tree);
+extern bool stdarg_p (tree);
/* In stmt.c */