This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Where to attach backend builtin decl?
- From: Sa Liu <SALIU at de dot ibm dot com>
- To: FX Coudert <fxcoudert at gmail dot com>
- Cc: fortran at gcc dot gnu dot org
- Date: Tue, 3 Jun 2008 16:59:35 +0200
- Subject: Re: Where to attach backend builtin decl?
- References: <OFA9E50C79.0DC0942A-ONC12573FC.006194E5-C12573FC.00788192@de.ibm.com> <B3BB27DA-AAF1-4421-9BC8-517E2F39B8E9@gmail.com> <OF20143E9F.7D425718-ONC12573FE.004E08C5-C12573FE.004FBAB5@de.ibm.com> <19c433eb0802290701u24bf3de7kc1300a1a99a99d27@mail.gmail.com> <4E0919C5-2914-4F08-BB78-DB296A244FFE@gmail.com> <OF69FD685F.53035F8A-ONC12573FE.0057C1B3-C12573FE.005A7E4A@de.ibm.com> <C4F03FA7-CF73-42AB-B3AB-2959A3456CA5@gmail.com>
FX,
Could you please check in this patch to mainline?
Thanks!
Sa
> With help from Jakub on IRC, I got the following working:
>
> Index: f95-lang.c
> ===================================================================
> --- f95-lang.c (revision 132578)
> +++ f95-lang.c (working copy)
> @@ -723,7 +723,20 @@
> implicit_built_in_decls[code] = decl;
> }
>
> +/* Look for a function decl with a given name. */
> +tree
> +find_fndecl_toplevel (tree name)
> +{
> + tree t;
>
> + for (t = global_binding_level->names; t; t = TREE_CHAIN (t))
> + if (TREE_CODE (t) == FUNCTION_DECL && DECL_NAME (t) == name)
> + return t;
> +
> + return NULL_TREE;
> +}
> +
> +
> #define DO_DEFINE_MATH_BUILTIN(code, name, argtype, tbase) \
> gfc_define_builtin ("__builtin_" name "l", tbase##longdouble
> [argtype], \
> BUILT_IN_ ## code ## L, name "l", true); \
> Index: trans.h
> ===================================================================
> --- trans.h (revision 132578)
> +++ trans.h (working copy)
> @@ -476,6 +476,7 @@
> tree gfc_build_library_function_decl (tree, tree, int, ...);
>
> /* somewhere! */
> +tree find_fndecl_toplevel (tree);
> tree pushdecl (tree);
> tree pushdecl_top_level (tree);
> void pushlevel (int);
> Index: trans-decl.c
> ===================================================================
> --- trans-decl.c (revision 132578)
> +++ trans-decl.c (working copy)
> @@ -1118,6 +1118,15 @@
> to know that. */
> gcc_assert (!(sym->attr.entry || sym->attr.entry_master));
>
> + if (sym->attr.is_bind_c == 1
> + && strncmp (sym->binding_label, "__builtin_", 10) == 0)
> + {
> + sym->backend_decl
> + = find_fndecl_toplevel (get_identifier (sym->binding_label));
> + if (sym->backend_decl)
> + return sym->backend_decl;
> + }
> +
> if (sym->attr.intrinsic)
> {
> /* Call the resolution function to get the actual name. This is
>
>
> The find_fndecl_toplevel() function does the job of getting decls
> back from the global_binding_level given their identifier. It works
> for the builtins I tried it with (like __builtin_sqrt), and I suppose
> it should also work with your backend builtins. That saves us from
> storing yet another namespace and using the already existing code.
> Can you try it and see if it works for you?
>
> And, in case it fails because the backend builtins are defined in a
> contained binding level, we can changed the function to look from the
> current binding level upwards, like this:
>
> > +/* Look for a function decl with a given name. */
> > +tree
> > +find_fndecl (tree name)
> > +{
> > + struct binding_level *b;
> > + tree t;
> > +
> > + for (b = current_binding_level; b; b = b->level_chain)
> > + for (t = b->names; t; t = TREE_CHAIN (t))
> > + if (TREE_CODE (t) == FUNCTION_DECL && DECL_NAME (t) == name)
> > + return t;
> > +
> > + return NULL_TREE;
> > +}
>
> (I have this code in my own tree because I use it for another patch,
> the decl merging issue.) If the first one doesn't work, try this one.
>
> > Following is the patch I have. Certainly in
> > gfc_get_extern_function_decl() we need to add a check for standard
> > intrinsics, before looking for backend intrinsics.
>
> I think the above solution, which handles all intrinsics without
> extra bookkeeping, is a better approach.
>
> >
> FX
>
>
> --
> François-Xavier Coudert
> http://www.homepages.ucl.ac.uk/~uccafco/
>