Hi! As discussed earlier, I'd like to pass __OPENMP_TARGET__ argument to all of GOMP_target{,_data,_update}, so that all those functions can get at the offloading data section in the shared library or binary making the call, so that the first time they encounter such a call in the shared library or binary, it can attempt to actually offload it to the target (and, if that fails, remember it, and do host fallback). The reason to pass this also to GOMP_target_data and GOMP_target_update is that even for those calls the global vars will already need to be mapped, and to make sure e.g. GOMP_target_data doesn't perform on the target device, while GOMP_target with the same device clause is performed as host fallback (that could result in wrong code, e.g. when target data copies data from device to host at the end, while target construct would modify the host copies, thus the current host copy would be overwritten by stale target copy).
As weak undefined hidden symbols don't seem to work as I hoped they would do, I'm just passing NULL for now, we'll need to wait until we have a linker plugin that will create the offloading section for us and add hidden __OPENMP_TARGET__ symbol. 2013-09-18 Jakub Jelinek <ja...@redhat.com> * omp-builtins.def (BUILT_IN_GOMP_TARGET_DATA, BUILT_IN_GOMP_TARGET_UPDATE): Use BT_FN_VOID_INT_PTR_SIZE_PTR_PTR_PTR rather than BT_FN_VOID_INT_SIZE_PTR_PTR_PTR. * builtin-types.def (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR): Remove. (BT_FN_VOID_INT_PTR_SIZE_PTR_PTR_PTR): New. * omp-low.c (expand_omp_target): Remove fnname argument from GOMP_target, add openmp_target argument to GOMP_target, GOMP_target_data and GOMP_target_update calls. gcc/fortran/ * types.def (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR): Remove. (BT_FN_VOID_INT_PTR_SIZE_PTR_PTR_PTR): New. libgomp/ * libgomp_g.h (GOMP_target): Change 3rd argument to const void *. (GOMP_target_data, GOMP_target_update): Add openmp_target argument. * target.c (GOMP_target): Change fnname argument to openmp_target, with const void * type. (GOMP_target_data, GOMP_target_update): Add openmp_target argument. --- gcc/omp-builtins.def.jj 2013-09-05 09:19:03.000000000 +0200 +++ gcc/omp-builtins.def 2013-09-18 14:16:38.522988068 +0200 @@ -229,10 +229,10 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TARGET, BT_FN_VOID_INT_OMPFN_PTR_SIZE_PTR_PTR_PTR, ATTR_NOTHROW_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TARGET_DATA, "GOMP_target_data", - BT_FN_VOID_INT_SIZE_PTR_PTR_PTR, ATTR_NOTHROW_LIST) + BT_FN_VOID_INT_PTR_SIZE_PTR_PTR_PTR, ATTR_NOTHROW_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TARGET_END_DATA, "GOMP_target_end_data", BT_FN_VOID, ATTR_NOTHROW_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TARGET_UPDATE, "GOMP_target_update", - BT_FN_VOID_INT_SIZE_PTR_PTR_PTR, ATTR_NOTHROW_LIST) + BT_FN_VOID_INT_PTR_SIZE_PTR_PTR_PTR, ATTR_NOTHROW_LIST) DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TEAMS, "GOMP_teams", BT_FN_VOID_UINT_UINT, ATTR_NOTHROW_LIST) --- gcc/builtin-types.def.jj 2013-09-05 09:19:03.000000000 +0200 +++ gcc/builtin-types.def 2013-09-18 14:17:20.964764926 +0200 @@ -473,8 +473,6 @@ DEF_FUNCTION_TYPE_5 (BT_FN_BOOL_VPTR_PTR DEF_FUNCTION_TYPE_5 (BT_FN_VOID_OMPFN_PTR_UINT_UINT_UINT, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, BT_UINT, BT_UINT) -DEF_FUNCTION_TYPE_5 (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR, - BT_VOID, BT_INT, BT_SIZE, BT_PTR, BT_PTR, BT_PTR) DEF_FUNCTION_TYPE_6 (BT_FN_INT_STRING_SIZE_INT_SIZE_CONST_STRING_VALIST_ARG, BT_INT, BT_STRING, BT_SIZE, BT_INT, BT_SIZE, @@ -502,6 +500,8 @@ DEF_FUNCTION_TYPE_6 (BT_FN_BOOL_VPTR_PTR BT_INT) DEF_FUNCTION_TYPE_6 (BT_FN_BOOL_SIZE_VPTR_PTR_PTR_INT_INT, BT_BOOL, BT_SIZE, BT_VOLATILE_PTR, BT_PTR, BT_PTR, BT_INT, BT_INT) +DEF_FUNCTION_TYPE_6 (BT_FN_VOID_INT_PTR_SIZE_PTR_PTR_PTR, + BT_VOID, BT_INT, BT_PTR, BT_SIZE, BT_PTR, BT_PTR, BT_PTR) DEF_FUNCTION_TYPE_7 (BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG_UINT, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, --- gcc/fortran/types.def.jj 2013-09-05 09:19:03.000000000 +0200 +++ gcc/fortran/types.def 2013-09-18 14:23:23.914822416 +0200 @@ -168,8 +168,6 @@ DEF_FUNCTION_TYPE_5 (BT_FN_BOOL_LONG_LON BT_PTR_LONG, BT_PTR_LONG) DEF_FUNCTION_TYPE_5 (BT_FN_VOID_SIZE_VPTR_PTR_PTR_INT, BT_VOID, BT_SIZE, BT_VOLATILE_PTR, BT_PTR, BT_PTR, BT_INT) -DEF_FUNCTION_TYPE_5 (BT_FN_VOID_INT_SIZE_PTR_PTR_PTR, - BT_VOID, BT_INT, BT_SIZE, BT_PTR, BT_PTR, BT_PTR) DEF_FUNCTION_TYPE_6 (BT_FN_BOOL_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR, BT_BOOL, BT_LONG, BT_LONG, BT_LONG, BT_LONG, @@ -194,6 +192,8 @@ DEF_FUNCTION_TYPE_6 (BT_FN_BOOL_VPTR_PTR BT_INT) DEF_FUNCTION_TYPE_6 (BT_FN_BOOL_SIZE_VPTR_PTR_PTR_INT_INT, BT_BOOL, BT_SIZE, BT_VOLATILE_PTR, BT_PTR, BT_PTR, BT_INT, BT_INT) +DEF_FUNCTION_TYPE_6 (BT_FN_VOID_INT_PTR_SIZE_PTR_PTR_PTR, + BT_VOID, BT_INT, BT_PTR, BT_SIZE, BT_PTR, BT_PTR, BT_PTR) DEF_FUNCTION_TYPE_7 (BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG_UINT, BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, --- gcc/omp-low.c.jj 2013-09-18 12:43:23.000000000 +0200 +++ gcc/omp-low.c 2013-09-18 14:49:01.708727891 +0200 @@ -7900,23 +7900,19 @@ expand_omp_target (struct omp_region *re } gimple g; + /* FIXME: This will be address of + extern char __OPENMP_TARGET__[] __attribute__((visibility ("hidden"))) + symbol, as soon as the linker plugin is able to create it for us. */ + tree openmp_target = build_zero_cst (ptr_type_node); if (kind == GF_OMP_TARGET_KIND_REGION) { tree fnaddr = build_fold_addr_expr (child_fn); - unsigned fnnamelen = IDENTIFIER_LENGTH (DECL_NAME (child_fn)); - tree fnname = build_string (fnnamelen, - IDENTIFIER_POINTER (DECL_NAME (child_fn))); - TREE_TYPE (fnname) = build_array_type_nelts (char_type_node, - fnnamelen); - TREE_READONLY (fnname) = 1; - TREE_STATIC (fnname) = 1; - fnname = build_fold_addr_expr (fnname); g = gimple_build_call (builtin_decl_explicit (start_ix), 7, - device, fnaddr, fnname, t1, t2, t3, t4); + device, fnaddr, openmp_target, t1, t2, t3, t4); } else - g = gimple_build_call (builtin_decl_explicit (start_ix), 5, - device, t1, t2, t3, t4); + g = gimple_build_call (builtin_decl_explicit (start_ix), 6, + device, openmp_target, t1, t2, t3, t4); gimple_set_location (g, gimple_location (entry_stmt)); gsi_insert_before (&gsi, g, GSI_SAME_STMT); if (kind != GF_OMP_TARGET_KIND_REGION) --- libgomp/target.c.jj 2013-09-16 10:10:07.000000000 +0200 +++ libgomp/target.c 2013-09-18 15:03:41.752244012 +0200 @@ -406,14 +406,15 @@ gomp_update (size_t mapnum, void **hosta /* Called when encountering a target directive. If DEVICE is -1, it means use device-var ICV. If it is -2 (or any other value larger than last available hw device, use host fallback. - FN is address of host code, FNNAME corresponding name to lookup - in the target code. HOSTADDRS, SIZES and KINDS are arrays + FN is address of host code, OPENMP_TARGET contains value of the + __OPENMP_TARGET__ symbol in the shared library or binary that invokes + GOMP_target. HOSTADDRS, SIZES and KINDS are arrays with MAPNUM entries, with addresses of the host objects, sizes of the host objects (resp. for pointer kind pointer bias and assumed sizeof (void *) size) and kinds. */ void -GOMP_target (int device, void (*fn) (void *), const char *fnname, +GOMP_target (int device, void (*fn) (void *), const void *openmp_target, size_t mapnum, void **hostaddrs, size_t *sizes, unsigned char *kinds) { @@ -434,8 +435,8 @@ GOMP_target (int device, void (*fn) (voi } void -GOMP_target_data (int device, size_t mapnum, void **hostaddrs, size_t *sizes, - unsigned char *kinds) +GOMP_target_data (int device, const void *openmp_target, size_t mapnum, + void **hostaddrs, size_t *sizes, unsigned char *kinds) { device = resolve_device (device); if (device == -1) @@ -479,8 +480,8 @@ GOMP_target_end_data (void) } void -GOMP_target_update (int device, size_t mapnum, void **hostaddrs, size_t *sizes, - unsigned char *kinds) +GOMP_target_update (int device, const void *openmp_target, size_t mapnum, + void **hostaddrs, size_t *sizes, unsigned char *kinds) { device = resolve_device (device); if (device == -1) --- libgomp/libgomp_g.h.jj 2013-09-05 09:19:03.000000000 +0200 +++ libgomp/libgomp_g.h 2013-09-18 15:03:22.800341890 +0200 @@ -201,12 +201,13 @@ extern void GOMP_single_copy_end (void * /* target.c */ -extern void GOMP_target (int, void (*) (void *), const char *, +extern void GOMP_target (int, void (*) (void *), const void *, size_t, void **, size_t *, unsigned char *); -extern void GOMP_target_data (int, size_t, void **, size_t *, unsigned char *); +extern void GOMP_target_data (int, const void *, + size_t, void **, size_t *, unsigned char *); extern void GOMP_target_end_data (void); -extern void GOMP_target_update (int, size_t, void **, size_t *, - unsigned char *); +extern void GOMP_target_update (int, const void *, + size_t, void **, size_t *, unsigned char *); extern void GOMP_teams (unsigned int, unsigned int); #endif /* LIBGOMP_G_H */ Jakub