Where to attach backend builtin decl?
Sa Liu
SALIU@de.ibm.com
Thu Feb 28 23:58:00 GMT 2008
> > The following is an example:
> >
> > module spu_intrinsics
> > use, intrinsic :: iso_c_binding
> > implicit none
> > contains
> > function builtin_spu_add_int(a, b) result(c) bind(c,
> > name="__builtin_spu_add_1")
> > integer (c_int), intent(in):: a(4), b(4)
> > integer(c_int) :: c(4)
> > end function builtin_vec_add_int
> > end module spu_intrinsics
> > In trans-decl.c function
> > gfc_get_extern_function_decl builds a new decl for the this function.
>
> I would have said that you should interrupt the current codepath
> before we get into gfc_get_extern_function_decl: check where that is
> called, and when the symbol name starts with "__builtin_", instead of
> calling gfc_get_extern_function_decl() call your own function that
> looks up for the right intrinsic decl.
I looked at the code again and found out that
gfc_get_extern_function_decl() is called, when a Fortran program calls the
binding C function builtin_spu_add_int, which is handled as an external
Fortran procedure. In this case the generated code is a brach to the
backend intrinsic __builtin_spu_add_1.
But the expansion of the builtin function should take place when resolving
the module function builtin_spu_add_int. The function
build_function_decl() is called at that time to generate a new decl for
it, and the symbol it handles has name builtin_spu_add_int, with
binding_label __builtin_spu_add_1. The decl I got from backend intrinsic,
instead, has name __builtin_spu_add_1. In build_function_decl() I can not
simply replace fndecl by the backend decl, since they have many different
fields and attributes, and even names. I still have no idea where to
insert the backend decl to expand the intrinsic function. Perhaps you know
the internals code better...
Thanks!
Sa
More information about the Fortran
mailing list