diff options
author | Tobias Burnus <tobias@codesourcery.com> | 2021-10-30 23:45:32 +0200 |
---|---|---|
committer | Tobias Burnus <tobias@codesourcery.com> | 2021-10-30 23:45:32 +0200 |
commit | 948d461954f2642ca187f86c19d297ba7a86320f (patch) | |
tree | 6e0bf27085917c296ca7e233a3b551d949ea4232 /gcc/omp-low.c | |
parent | 90ba129c9d787b985f338f70713f7be74aaa5091 (diff) | |
download | gcc-948d461954f2642ca187f86c19d297ba7a86320f.zip gcc-948d461954f2642ca187f86c19d297ba7a86320f.tar.gz gcc-948d461954f2642ca187f86c19d297ba7a86320f.tar.bz2 |
OpenMP: Add strictly nested API call check [PR102972]
The teams construct only permits omp_get_num_teams and omp_get_team_num
as API call in strictly nested regions - check for it.
Additionally, for Fortran, using DECL_NAME does not show the mangled
name, hence, DECL_ASSEMBLER_NAME had to be used to.
Finally, 'target device(ancestor:1)' wrongly rejected non-API calls
as well.
PR middle-end/102972
gcc/ChangeLog:
* omp-low.c (omp_runtime_api_call): Use DECL_ASSEMBLER_NAME to get
internal Fortran name; new permit_num_teams arg to permit
omp_get_num_teams and omp_get_team_num.
(scan_omp_1_stmt): Update call to it, add missing call for
reverse offload, and check for strictly nested API calls in teams.
gcc/testsuite/ChangeLog:
* c-c++-common/gomp/target-device-ancestor-3.c: Add non-API
routine test.
* gfortran.dg/gomp/order-6.f90: Add missing bind(C).
* c-c++-common/gomp/teams-3.c: New test.
* gfortran.dg/gomp/teams-3.f90: New test.
* gfortran.dg/gomp/teams-4.f90: New test.
libgomp/ChangeLog:
* testsuite/libgomp.c-c++-common/icv-3.c: Nest API calls inside
parallel construct.
* testsuite/libgomp.c-c++-common/icv-4.c: Likewise.
* testsuite/libgomp.c/target-3.c: Likewise.
* testsuite/libgomp.c/target-5.c: Likewise.
* testsuite/libgomp.c/target-6.c: Likewise.
* testsuite/libgomp.c/target-teams-1.c: Likewise.
* testsuite/libgomp.c/teams-1.c: Likewise.
* testsuite/libgomp.c/thread-limit-2.c: Likewise.
* testsuite/libgomp.c/thread-limit-3.c: Likewise.
* testsuite/libgomp.c/thread-limit-4.c: Likewise.
* testsuite/libgomp.c/thread-limit-5.c: Likewise.
* testsuite/libgomp.fortran/icv-3.f90: Likewise.
* testsuite/libgomp.fortran/icv-4.f90: Likewise.
* testsuite/libgomp.fortran/teams1.f90: Likewise.
Diffstat (limited to 'gcc/omp-low.c')
-rw-r--r-- | gcc/omp-low.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 15e4424..f58a191 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -3942,7 +3942,8 @@ omp_runtime_api_call (const_tree fndecl) "target_memcpy", "target_memcpy_rect", NULL, - /* Now omp_* calls that are available as omp_* and omp_*_. */ + /* Now omp_* calls that are available as omp_* and omp_*_; however, the + DECL_NAME is always omp_* without tailing underscore. */ "capture_affinity", "destroy_allocator", "destroy_lock", @@ -3994,7 +3995,8 @@ omp_runtime_api_call (const_tree fndecl) "unset_lock", "unset_nest_lock", NULL, - /* And finally calls available as omp_*, omp_*_ and omp_*_8_. */ + /* And finally calls available as omp_*, omp_*_ and omp_*_8_; however, + as DECL_NAME only omp_* and omp_*_8 appear. */ "display_env", "get_ancestor_thread_num", "init_allocator", @@ -4024,11 +4026,7 @@ omp_runtime_api_call (const_tree fndecl) size_t len = strlen (omp_runtime_apis[i]); if (strncmp (name + 4, omp_runtime_apis[i], len) == 0 && (name[4 + len] == '\0' - || (mode > 0 - && name[4 + len] == '_' - && (name[4 + len + 1] == '\0' - || (mode > 1 - && strcmp (name + 4 + len + 1, "8_") == 0))))) + || (mode > 1 && strcmp (name + 4 + len, "_8") == 0))) return true; } return false; @@ -4095,9 +4093,26 @@ scan_omp_1_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p, "OpenMP runtime API call %qD in a region with " "%<order(concurrent)%> clause", fndecl); } + if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS + && omp_runtime_api_call (fndecl) + && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) + != strlen ("omp_get_num_teams")) + || strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), + "omp_get_num_teams") != 0) + && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) + != strlen ("omp_get_team_num")) + || strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), + "omp_get_team_num") != 0)) + { + remove = true; + error_at (gimple_location (stmt), + "OpenMP runtime API call %qD strictly nested in a " + "%<teams%> region", fndecl); + } if (gimple_code (ctx->stmt) == GIMPLE_OMP_TARGET && (gimple_omp_target_kind (ctx->stmt) - == GF_OMP_TARGET_KIND_REGION)) + == GF_OMP_TARGET_KIND_REGION) + && omp_runtime_api_call (fndecl)) { tree tgt_clauses = gimple_omp_target_clauses (ctx->stmt); tree c = omp_find_clause (tgt_clauses, OMP_CLAUSE_DEVICE); |