From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29400 invoked by alias); 23 May 2011 14:05:44 -0000 Received: (qmail 29380 invoked by uid 22791); 23 May 2011 14:05:41 -0000 X-SWARE-Spam-Status: No, hits=-0.2 required=5.0 tests=AWL,BAYES_60,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SARE_SUB_GETRID,TW_BJ,TW_FN,TW_RG,TW_TJ,TW_TM X-Spam-Check-By: sourceware.org Received: from mail-ww0-f51.google.com (HELO mail-ww0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 May 2011 14:05:24 +0000 Received: by wwf26 with SMTP id 26so5658973wwf.8 for ; Mon, 23 May 2011 07:05:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.55.74 with SMTP id t10mr2299268wbg.91.1306159522447; Mon, 23 May 2011 07:05:22 -0700 (PDT) Received: by 10.227.38.129 with HTTP; Mon, 23 May 2011 07:05:22 -0700 (PDT) In-Reply-To: <20110523135324.GA13949@nightcrawler> References: <20110523135324.GA13949@nightcrawler> Date: Mon, 23 May 2011 14:57:00 -0000 Message-ID: Subject: Re: [PATCH] get rid of some TYPE_ARG_TYPES usage by introducing nth_arg_type From: Richard Guenther To: Nathan Froyd Cc: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org, jason@redhat.com, mikestump@comcast.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg01630.txt.bz2 On Mon, May 23, 2011 at 3:53 PM, Nathan Froyd wr= ote: > Various places in the compiler grab TYPE_ARG_TYPES and grovel through it > when what they're really trying to do is index into the list of argument > types. =A0The patch below introduces nth_arg_type for such situatiosn and > changes a hodgepodge of places to use it. =A0You could, of course, use > function_args_iterator, but I think this approach is somewhat clearer. > > Tested on x86_64-unknown-linux-gnu. =A0OK to commit? See below > -Nathan > > gcc/ > =A0 =A0 =A0 =A0* tree.h (nth_arg_type): Declare. > =A0 =A0 =A0 =A0* tree.c (nth_arg_type): Define. > =A0 =A0 =A0 =A0* dbxout.c (dbxout_type_method_1): Call it. > =A0 =A0 =A0 =A0* dwarf2out.c (decl_class_context): Likewise. > =A0 =A0 =A0 =A0* tree-ssa-math-opts.c (execute_optimize_bswap): Likewise. > > gcc/cp/ > =A0 =A0 =A0 =A0* cp-tree.h (DECL_CONST_MEMFUNC_P): Call nth_arg_type. > =A0 =A0 =A0 =A0(DECL_VOLATILE_MEMFUNC_P, type_of_this_parm): Likewise. > > gcc/fortran/ > =A0 =A0 =A0 =A0* trans-decl.c (create_main_function): Call nth_arg_type. > > gcc/objc/ > =A0 =A0 =A0 =A0* objc-next-runtime-abi-01.c (next_sjlj_build_enter_and_se= tjmp): > =A0 =A0 =A0 =A0Call nth_arg_type. > > diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h > index ada01fb..53848c3 100644 > --- a/gcc/cp/cp-tree.h > +++ b/gcc/cp/cp-tree.h > @@ -2256,15 +2256,13 @@ struct GTY((variable_size)) lang_decl { > =A0 =A0has `this' as const X *const. =A0*/ > =A0#define DECL_CONST_MEMFUNC_P(NODE) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0\ > =A0 (DECL_NONSTATIC_MEMBER_FUNCTION_P (NODE) =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0\ > - =A0 && CP_TYPE_CONST_P (TREE_TYPE (TREE_VALUE =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0\ > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (TYPE_A= RG_TYPES (TREE_TYPE (NODE)))))) > + =A0 && CP_TYPE_CONST_P (TREE_TYPE (nth_arg_type (TREE_TYPE (NODE), 0)))) > > =A0/* Nonzero for FUNCTION_DECL means that this member function > =A0 =A0has `this' as volatile X *const. =A0*/ > =A0#define DECL_VOLATILE_MEMFUNC_P(NODE) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \ > =A0 (DECL_NONSTATIC_MEMBER_FUNCTION_P (NODE) =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0\ > - =A0 && CP_TYPE_VOLATILE_P (TREE_TYPE (TREE_VALUE =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \ > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (TYPE_A= RG_TYPES (TREE_TYPE (NODE)))))) > + =A0 && CP_TYPE_VOLATILE_P (TREE_TYPE (nth_arg_type (TREE_TYPE (NODE), 0= )))) > > =A0/* Nonzero for a DECL means that this member is a non-static member. = =A0*/ > =A0#define DECL_NONSTATIC_MEMBER_P(NODE) =A0 =A0 =A0 =A0 =A0\ > @@ -4660,10 +4658,8 @@ struct GTY(()) tinst_level { > =A0static inline tree > =A0type_of_this_parm (const_tree fntype) > =A0{ > - =A0function_args_iterator iter; > =A0 gcc_assert (TREE_CODE (fntype) =3D=3D METHOD_TYPE); > - =A0function_args_iter_init (&iter, fntype); > - =A0return function_args_iter_cond (&iter); > + =A0return nth_arg_type (fntype, 0); > =A0} > > =A0/* Return the class of the `this' parameter of FNTYPE. =A0*/ > diff --git a/gcc/dbxout.c b/gcc/dbxout.c > index 3190803..f5e985e 100644 > --- a/gcc/dbxout.c > +++ b/gcc/dbxout.c > @@ -1585,7 +1585,7 @@ dbxout_type_method_1 (tree decl) > =A0 =A0 c2 =3D '?'; > =A0 else /* it's a METHOD_TYPE. =A0*/ > =A0 =A0 { > - =A0 =A0 =A0tree firstarg =3D TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (dec= l))); > + =A0 =A0 =A0tree firstarg =3D nth_arg_type (TREE_TYPE (decl), 0); > =A0 =A0 =A0 /* A for normal functions. > =A0 =A0 =A0 =A0 B for `const' member functions. > =A0 =A0 =A0 =A0 C for `volatile' member functions. > diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c > index b85a55e..d95c3f4 100644 > --- a/gcc/dwarf2out.c > +++ b/gcc/dwarf2out.c > @@ -7484,7 +7484,7 @@ decl_class_context (tree decl) > =A0 =A0 context =3D DECL_CONTEXT (decl); > =A0 else > =A0 =A0 context =3D TYPE_MAIN_VARIANT > - =A0 =A0 =A0(TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); > + =A0 =A0 =A0(TREE_TYPE (nth_arg_type (TREE_TYPE (decl), 0))); > > =A0 if (context && !TYPE_P (context)) > =A0 =A0 context =3D NULL_TREE; > diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c > index d771484..19d3e03 100644 > --- a/gcc/fortran/trans-decl.c > +++ b/gcc/fortran/trans-decl.c > @@ -4518,7 +4518,7 @@ create_main_function (tree fndecl) > =A0{ > =A0 tree old_context; > =A0 tree ftn_main; > - =A0tree tmp, decl, result_decl, argc, argv, typelist, arglist; > + =A0tree tmp, decl, result_decl, argc, argv, fntype, arglist; > =A0 stmtblock_t body; > > =A0 old_context =3D current_function_decl; > @@ -4559,21 +4559,20 @@ create_main_function (tree fndecl) > =A0 /* Get the arguments. =A0*/ > > =A0 arglist =3D NULL_TREE; > - =A0typelist =3D TYPE_ARG_TYPES (TREE_TYPE (ftn_main)); > + =A0fntype =3D TREE_TYPE (ftn_main); > > - =A0tmp =3D TREE_VALUE (typelist); > + =A0tmp =3D nth_arg_type (fntype, 0); > =A0 argc =3D build_decl (input_location, PARM_DECL, get_identifier ("argc= "), tmp); > =A0 DECL_CONTEXT (argc) =3D ftn_main; > - =A0DECL_ARG_TYPE (argc) =3D TREE_VALUE (typelist); > + =A0DECL_ARG_TYPE (argc) =3D tmp; > =A0 TREE_READONLY (argc) =3D 1; > =A0 gfc_finish_decl (argc); > =A0 arglist =3D chainon (arglist, argc); > > - =A0typelist =3D TREE_CHAIN (typelist); > - =A0tmp =3D TREE_VALUE (typelist); > + =A0tmp =3D nth_arg_type (fntype, 1); > =A0 argv =3D build_decl (input_location, PARM_DECL, get_identifier ("argv= "), tmp); > =A0 DECL_CONTEXT (argv) =3D ftn_main; > - =A0DECL_ARG_TYPE (argv) =3D TREE_VALUE (typelist); > + =A0DECL_ARG_TYPE (argv) =3D tmp; > =A0 TREE_READONLY (argv) =3D 1; > =A0 DECL_BY_REFERENCE (argv) =3D 1; > =A0 gfc_finish_decl (argv); > diff --git a/gcc/objc/objc-next-runtime-abi-01.c b/gcc/objc/objc-next-run= time-abi-01.c > index d5b795f..37b2b10 100644 > --- a/gcc/objc/objc-next-runtime-abi-01.c > +++ b/gcc/objc/objc-next-runtime-abi-01.c > @@ -2584,7 +2584,7 @@ next_sjlj_build_enter_and_setjmp (struct objc_try_c= ontext **ctcp) > =A0#ifdef OBJCPLUS > =A0 /* Convert _setjmp argument to type that is expected. =A0*/ > =A0 if (prototype_p (TREE_TYPE (objc_setjmp_decl))) > - =A0 =A0t =3D convert (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (objc_setjm= p_decl))), t); > + =A0 =A0t =3D convert (nth_arg_type (TREE_TYPE (objc_setjmp_decl), 0), t= ); > =A0 else > =A0 =A0 t =3D convert (ptr_type_node, t); > =A0#else > diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c > index b9f631e..5e6feb1 100644 > --- a/gcc/tree-ssa-math-opts.c > +++ b/gcc/tree-ssa-math-opts.c > @@ -1181,13 +1181,13 @@ execute_optimize_bswap (void) > =A0 if (bswap32_p) > =A0 =A0 { > =A0 =A0 =A0 tree fndecl =3D built_in_decls[BUILT_IN_BSWAP32]; > - =A0 =A0 =A0bswap32_type =3D TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fnde= cl))); > + =A0 =A0 =A0bswap32_type =3D nth_arg_type (TREE_TYPE (fndecl), 0); > =A0 =A0 } > > =A0 if (bswap64_p) > =A0 =A0 { > =A0 =A0 =A0 tree fndecl =3D built_in_decls[BUILT_IN_BSWAP64]; > - =A0 =A0 =A0bswap64_type =3D TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fnde= cl))); > + =A0 =A0 =A0bswap64_type =3D nth_arg_type (TREE_TYPE (fndecl), 0); > =A0 =A0 } > > =A0 memset (&bswap_stats, 0, sizeof (bswap_stats)); > diff --git a/gcc/tree.c b/gcc/tree.c > index 3357d84..2925e13 100644 > --- a/gcc/tree.c > +++ b/gcc/tree.c > @@ -10704,6 +10704,29 @@ prototype_p (tree fntype) > =A0 return (t !=3D NULL_TREE); > =A0} > > +/* Return the Nth argument type from FNTYPE. =A0*/ > + > +tree > +nth_arg_type (const_tree fntype, int n) > +{ > + =A0function_args_iterator iter; > + =A0tree t; > + =A0int i; > + > + =A0gcc_assert (fntype !=3D NULL_TREE); > + =A0gcc_assert (n >=3D 0); Please merge the asserts and do s/gcc_assert/gcc_checking_assert/ And if n should be >=3D 0 why not pass it in as unsigned? The patch is ok with both changes. Thanks, Richard. > + =A0i =3D 0; > + =A0FOREACH_FUNCTION_ARGS (fntype, t, iter) > + =A0 =A0{ > + =A0 =A0 =A0if (n =3D=3D i) > + =A0 =A0 =A0 return t; > + =A0 =A0 =A0i++; > + =A0 =A0} > + > + =A0gcc_unreachable (); > +} > + > =A0/* If BLOCK is inlined from an __attribute__((__artificial__)) > =A0 =A0routine, return pointer to location from where it has been > =A0 =A0called. =A0*/ > diff --git a/gcc/tree.h b/gcc/tree.h > index 805fe06..9788071 100644 > --- a/gcc/tree.h > +++ b/gcc/tree.h > @@ -5074,6 +5074,7 @@ extern tree create_artificial_label (location_t); > =A0extern const char *get_name (tree); > =A0extern bool stdarg_p (const_tree); > =A0extern bool prototype_p (tree); > +extern tree nth_arg_type (const_tree, int); > =A0extern bool is_typedef_decl (tree x); > =A0extern bool typedef_variant_p (tree); > =A0extern bool auto_var_in_fn_p (const_tree, const_tree); >