Where to attach backend builtin decl?
FX Coudert
fxcoudert@gmail.com
Fri Feb 29 16:03:00 GMT 2008
>> If I replace the decl with its backend builtin decl, which has name
>> "__builtin_spu_add_1",later the function is not expanded.
>
> That is weird (and slightly worrying). Can you show me the tree dump
> for the function call, where you have manually replaced the decl by
> the builtin decl?
I was so intrigued that this doesn't work that I have tried it
myself... and it works! I use the following code:
> module m
> implicit none
>
> interface
> function sqrt_builtin (a) result(c) bind(c, name="__builtin_sqrt")
> use iso_c_binding
> real(c_double), intent(in), value :: a
> real(c_double) :: c
> end function
> end interface
> end module
>
> program test
> use m
> use iso_c_binding
> real(c_double) :: x
>
> x = 2
> x = sqrt_builtin (x)
> print *, x
> end
and I have made the following crude modification to trans-decl.c to
substitute the builtin fndecl instead of creating a call to an
external function, just like I explained in my previous mails:
> Index: trans-decl.c
> ===================================================================
> --- trans-decl.c (revision 132578)
> +++ trans-decl.c (working copy)
> @@ -1118,6 +1118,10 @@
> 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)
> + return (sym->backend_decl = built_in_decls[BUILT_IN_SQRT]);
> +
> if (sym->attr.intrinsic)
> {
> /* Call the resolution function to get the actual name.
> This is
Without the patch, compiling fails with "Undefined symbols:
___builtin_sqrt", but with the patch, both the tree dump (-fdump-
original-tree) and assembler show it working fine:
[excerpt from the tree dump]
> x = 2.0e+0;
> x = __builtin_sqrt (x);
[excerpt from the assembler code generated]
> movsd %xmm0, -16(%ebp)
> movsd -16(%ebp), %xmm0
> sqrtsd %xmm0, %xmm0
> movsd %xmm0, -16(%ebp)
Now, to the question of why this fails for you... that I can't say,
but I hope I have given enough information to help you track it down!
FX
--
François-Xavier Coudert
http://www.homepages.ucl.ac.uk/~uccafco/
More information about the Fortran
mailing list