From: Tobias Burnus Date: Mon, 28 Sep 2020 16:08:05 +0000 (+0200) Subject: OpenMP: Handle cpp_implicit_alias in declare-target discovery (PR96390) X-Git-Tag: upstream/12.2.0~13449 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2a10a2c0689db280ee3a94164504b7196b8370f4;p=platform%2Fupstream%2Fgcc.git OpenMP: Handle cpp_implicit_alias in declare-target discovery (PR96390) gcc/ChangeLog: PR middle-end/96390 * omp-offload.c (omp_discover_declare_target_tgt_fn_r): Handle alias nodes. libgomp/ChangeLog: PR middle-end/96390 * testsuite/libgomp.c++/pr96390.C: New test. * testsuite/libgomp.c-c++-common/pr96390.c: New test. --- diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c index 32c2485..a89275b 100644 --- a/gcc/omp-offload.c +++ b/gcc/omp-offload.c @@ -196,21 +196,53 @@ omp_declare_target_var_p (tree decl) static tree omp_discover_declare_target_tgt_fn_r (tree *tp, int *walk_subtrees, void *data) { - if (TREE_CODE (*tp) == FUNCTION_DECL - && !omp_declare_target_fn_p (*tp) - && !lookup_attribute ("omp declare target host", DECL_ATTRIBUTES (*tp))) + if (TREE_CODE (*tp) == FUNCTION_DECL) { + tree decl = *tp; tree id = get_identifier ("omp declare target"); - if (!DECL_EXTERNAL (*tp) && DECL_SAVED_TREE (*tp)) - ((vec *) data)->safe_push (*tp); - DECL_ATTRIBUTES (*tp) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (*tp)); symtab_node *node = symtab_node::get (*tp); if (node != NULL) { + while (node->alias_target) + { + if (!omp_declare_target_fn_p (node->decl) + && !lookup_attribute ("omp declare target host", + DECL_ATTRIBUTES (node->decl))) + { + node->offloadable = 1; + DECL_ATTRIBUTES (node->decl) + = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (node->decl)); + } + node = symtab_node::get (node->alias_target); + } + symtab_node *new_node = node->ultimate_alias_target (); + decl = new_node->decl; + while (node != new_node) + { + if (!omp_declare_target_fn_p (node->decl) + && !lookup_attribute ("omp declare target host", + DECL_ATTRIBUTES (node->decl))) + { + node->offloadable = 1; + DECL_ATTRIBUTES (node->decl) + = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (node->decl)); + } + gcc_assert (node->alias && node->analyzed); + node = node->get_alias_target (); + } node->offloadable = 1; if (ENABLE_OFFLOADING) g->have_offload = true; } + if (omp_declare_target_fn_p (decl) + || lookup_attribute ("omp declare target host", + DECL_ATTRIBUTES (decl))) + return NULL_TREE; + + if (!DECL_EXTERNAL (decl) && DECL_SAVED_TREE (decl)) + ((vec *) data)->safe_push (decl); + DECL_ATTRIBUTES (decl) = tree_cons (id, NULL_TREE, + DECL_ATTRIBUTES (decl)); } else if (TYPE_P (*tp)) *walk_subtrees = 0; diff --git a/libgomp/testsuite/libgomp.c++/pr96390.C b/libgomp/testsuite/libgomp.c++/pr96390.C new file mode 100644 index 0000000..8c770ec --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/pr96390.C @@ -0,0 +1,49 @@ +/* { dg-additional-options "-O0 -fdump-tree-omplower" } */ +/* { dg-xfail-if "PR 97106/PR 97102 - .alias not (yet) supported for nvptx" { offload_target_nvptx } } */ + +#include +#include + +template struct V { + int version_called; + + template::type> + V () + { + version_called = 1; + } + + template::type>::value)>::type> + V (TArg0) + { + version_called = 2; + } +}; + +template struct S { + V v; +}; + +int +main () +{ + int version_set[2] = {-1, -1}; + +#pragma omp target map(from: version_set[0:2]) + { + S<0> s; + version_set[0] = s.v.version_called; + V<1> v2((unsigned long) 1); + version_set[1] = v2.version_called; + } + + if (version_set[0] != 1 || version_set[1] != 2) + abort (); + return 0; +} + +/* "3" for S<0>::S, V<0>::V<>, and V<1>::V: */ +/* { dg-final { scan-tree-dump-times "__attribute__..omp declare target" 3 "omplower" } } */ diff --git a/libgomp/testsuite/libgomp.c-c++-common/pr96390.c b/libgomp/testsuite/libgomp.c-c++-common/pr96390.c new file mode 100644 index 0000000..692bd73 --- /dev/null +++ b/libgomp/testsuite/libgomp.c-c++-common/pr96390.c @@ -0,0 +1,26 @@ +/* { dg-additional-options "-O0 -fdump-tree-omplower" } */ +/* { dg-xfail-if "PR 97102/PR 97106 - .alias not (yet) supported for nvptx" { offload_target_nvptx } } */ + +#ifdef __cplusplus +extern "C" { +#endif + +int foo () { return 42; } +int bar () __attribute__((alias ("foo"))); +int baz () __attribute__((alias ("bar"))); + +#ifdef __cplusplus +} +#endif + + +int +main () +{ + int n; + #pragma omp target map(from:n) + n = baz (); + if (n != 42) + __builtin_abort (); +} +/* { dg-final { scan-tree-dump-times "__attribute__..omp declare target" 1 "omplower" } } */