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: FX Coudert <fxcoudert at gmail dot com>
- To: Sa Liu <SALIU at de dot ibm dot com>
- Cc: fortran at gcc dot gnu dot org
- Date: Fri, 29 Feb 2008 16:52:39 +0000
- Subject: Re: Where to attach backend builtin decl?
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:in-reply-to:references:mime-version:content-type:message-id:cc:content-transfer-encoding:from:subject:date:to:x-mailer; bh=hE17UHbBpQbVoNw7d39kUC1YepD2BSd5K6F0YCX7ME8=; b=cf1xC1ar9qmOYTBV3S3klOatVWi8r/nFlWH2WHpt+3OC4P7MAMixwk5DzN6pIzbNsoMYnetZthS5hkkXiZ2KFoy9tTksl79wGgYXUQ+9oBza8F5srGxuJ16t0DaW9ZSS5BKe2kfoYWE4xKW9Dyu3ytlYPvZmVsPwyxxwhB+JgPA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=in-reply-to:references:mime-version:content-type:message-id:cc:content-transfer-encoding:from:subject:date:to:x-mailer; b=Zc92gwh2qXqEqCgbqGhsuZhK941a3dRKteVEssJdJG8JwpxCp6T0MWMdzpiQrFVn3A3C22umk3rxxGRquyR6m2Rsssj9qTMGSkn9CN653h1VcZ6aHFIfHKI/4chWc4xsgMqNwB6f67RwraL15rwsFGuhN7L9eLHnIx/jiuTW9pk=
- 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>
The standard intrinsics can be found in built_in_decls[], while the
backend decls are saved in some backend arrays. But they are once
initialized in frontend. What I did is to define a new namepsace
called gfc_backend_builtin_ns, and save all backend builtins' decls
in that namespace. Latter in gfc_get_extern_fucntion_decl() I look
up this namespace and find out its corresponding decl. Perhaps an
array could do the same job. Actually in f95-lang.c function
gfc_builtin_function() pushes the decl in current_binding_level.
Can we get it again from the binding_level? That would avoid the
trouble with the new namespace.
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/