]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP: Handle tofrom with target enter/exit data
authorTobias Burnus <tobias@codesourcery.com>
Tue, 5 Jul 2022 09:34:50 +0000 (11:34 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Tue, 5 Jul 2022 09:34:50 +0000 (11:34 +0200)
In 5.2, a map clause can be map-entering or map-exiting,
either containing 'tofrom'. The main reason for this is
permit 'map(x)' with 'omp target enter/exit data',
avoiding to specify 'to:/from:' explicitly. (OpenMP
defaults to 'tofrom'.)

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_target_enter_data,
c_parser_omp_target_exit_data): Accept tofrom
map-type modifier but use 'to' / 'from' internally.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_target_enter_data,
cp_parser_omp_target_exit_data): Accept tofrom
map-type modifier but use 'to' / 'from' internally.

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_omp_namelist): For the map-type,
also handle the always modifer and release/delete.
* openmp.cc (resolve_omp_clauses): Accept tofrom
map-type modifier for target enter/exit data,
but use 'to' / 'from' internally.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.2): Mark target enter/exit data
with fromto as implemented.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/target-data-2.c: New test.
* c-c++-common/gomp/target-data-3.c: New test.
* gfortran.dg/gomp/target-data-1.f90: New test.
* gfortran.dg/gomp/target-data-2.f90: New test.

(cherry picked from commit 9a668532fb19e7c57aa595a26ce3f0d95f9cbb1b)

14 files changed:
gcc/c/ChangeLog.omp
gcc/c/c-parser.cc
gcc/cp/ChangeLog.omp
gcc/cp/parser.cc
gcc/fortran/ChangeLog.omp
gcc/fortran/dump-parse-tree.cc
gcc/fortran/openmp.cc
gcc/testsuite/ChangeLog.omp
gcc/testsuite/c-c++-common/gomp/target-data-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/target-data-3.c [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/target-data-1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/target-data-2.f90 [new file with mode: 0644]
libgomp/ChangeLog.omp
libgomp/libgomp.texi

index 7d8a171a2f4fdde24b4ace45d0bb7a4b78100a94..cf45947a0a456a5fee96e92e23b01c9b68232a9f 100644 (file)
@@ -1,3 +1,12 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-07-01  Tobias Burnus  <tobias@codesourcery.com>
+
+       * c-parser.cc (c_parser_omp_target_enter_data,
+       c_parser_omp_target_exit_data): Accept tofrom
+       map-type modifier but use 'to' / 'from' internally.
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index 5a6bf797283a6a872bfd40716218d51f160b7b28..2ef391dbbb0e4bd6e51cc0bb141f4a2a70f5d427 100644 (file)
@@ -21326,6 +21326,14 @@ c_parser_omp_target_enter_data (location_t loc, c_parser *parser,
          case GOMP_MAP_ALLOC:
            map_seen = 3;
            break;
+         case GOMP_MAP_TOFROM:
+           OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_TO);
+           map_seen = 3;
+           break;
+         case GOMP_MAP_ALWAYS_TOFROM:
+           OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_ALWAYS_TO);
+           map_seen = 3;
+           break;
          case GOMP_MAP_FIRSTPRIVATE_POINTER:
          case GOMP_MAP_ALWAYS_POINTER:
          case GOMP_MAP_ATTACH_DETACH:
@@ -21334,7 +21342,7 @@ c_parser_omp_target_enter_data (location_t loc, c_parser *parser,
            map_seen |= 1;
            error_at (OMP_CLAUSE_LOCATION (*pc),
                      "%<#pragma omp target enter data%> with map-type other "
-                     "than %<to%> or %<alloc%> on %<map%> clause");
+                     "than %<to%>, %<tofrom%> or %<alloc%> on %<map%> clause");
            *pc = OMP_CLAUSE_CHAIN (*pc);
            continue;
          }
@@ -21417,6 +21425,14 @@ c_parser_omp_target_exit_data (location_t loc, c_parser *parser,
          case GOMP_MAP_DELETE:
            map_seen = 3;
            break;
+         case GOMP_MAP_TOFROM:
+           OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_FROM);
+           map_seen = 3;
+           break;
+         case GOMP_MAP_ALWAYS_TOFROM:
+           OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_ALWAYS_FROM);
+           map_seen = 3;
+           break;
          case GOMP_MAP_FIRSTPRIVATE_POINTER:
          case GOMP_MAP_ALWAYS_POINTER:
          case GOMP_MAP_ATTACH_DETACH:
@@ -21425,8 +21441,8 @@ c_parser_omp_target_exit_data (location_t loc, c_parser *parser,
            map_seen |= 1;
            error_at (OMP_CLAUSE_LOCATION (*pc),
                      "%<#pragma omp target exit data%> with map-type other "
-                     "than %<from%>, %<release%> or %<delete%> on %<map%>"
-                     " clause");
+                     "than %<from%>, %<tofrom%>, %<release%> or %<delete%> "
+                     "on %<map%> clause");
            *pc = OMP_CLAUSE_CHAIN (*pc);
            continue;
          }
index 0943c08f3ccfa96acf10e7777b06069fb7ea0083..0f29357f56205c19364f22aa1dbd4b27b39c08d8 100644 (file)
@@ -1,3 +1,12 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-07-01  Tobias Burnus  <tobias@codesourcery.com>
+
+       * parser.cc (cp_parser_omp_target_enter_data,
+       cp_parser_omp_target_exit_data): Accept tofrom
+       map-type modifier but use 'to' / 'from' internally.
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index b744033364c8c04f6e4b00f974781deffd39f757..e685d5f7c7b6c424d8c424de95b75932c6cc04b6 100644 (file)
@@ -44530,6 +44530,14 @@ cp_parser_omp_target_enter_data (cp_parser *parser, cp_token *pragma_tok,
          case GOMP_MAP_ALLOC:
            map_seen = 3;
            break;
+         case GOMP_MAP_TOFROM:
+           OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_TO);
+           map_seen = 3;
+           break;
+         case GOMP_MAP_ALWAYS_TOFROM:
+           OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_ALWAYS_TO);
+           map_seen = 3;
+           break;
          case GOMP_MAP_FIRSTPRIVATE_POINTER:
          case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
          case GOMP_MAP_ALWAYS_POINTER:
@@ -44539,7 +44547,7 @@ cp_parser_omp_target_enter_data (cp_parser *parser, cp_token *pragma_tok,
            map_seen |= 1;
            error_at (OMP_CLAUSE_LOCATION (*pc),
                      "%<#pragma omp target enter data%> with map-type other "
-                     "than %<to%> or %<alloc%> on %<map%> clause");
+                     "than %<to%>, %<tofrom%> or %<alloc%> on %<map%> clause");
            *pc = OMP_CLAUSE_CHAIN (*pc);
            continue;
          }
@@ -44626,6 +44634,14 @@ cp_parser_omp_target_exit_data (cp_parser *parser, cp_token *pragma_tok,
          case GOMP_MAP_DELETE:
            map_seen = 3;
            break;
+         case GOMP_MAP_TOFROM:
+           OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_FROM);
+           map_seen = 3;
+           break;
+         case GOMP_MAP_ALWAYS_TOFROM:
+           OMP_CLAUSE_SET_MAP_KIND (*pc, GOMP_MAP_ALWAYS_FROM);
+           map_seen = 3;
+           break;
          case GOMP_MAP_FIRSTPRIVATE_POINTER:
          case GOMP_MAP_FIRSTPRIVATE_REFERENCE:
          case GOMP_MAP_ALWAYS_POINTER:
@@ -44635,8 +44651,8 @@ cp_parser_omp_target_exit_data (cp_parser *parser, cp_token *pragma_tok,
            map_seen |= 1;
            error_at (OMP_CLAUSE_LOCATION (*pc),
                      "%<#pragma omp target exit data%> with map-type other "
-                     "than %<from%>, %<release%> or %<delete%> on %<map%>"
-                     " clause");
+                     "than %<from%>, %<tofrom%>, %<release%> or %<delete%> "
+                     "on %<map%> clause");
            *pc = OMP_CLAUSE_CHAIN (*pc);
            continue;
          }
index 37a18320bbc6267f46bc1225a4f7eb2902c5bdb1..af269944f5f9a864dc98cbc75084a7c416052602 100644 (file)
@@ -1,3 +1,14 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-07-01  Tobias Burnus  <tobias@codesourcery.com>
+
+       * dump-parse-tree.cc (show_omp_namelist): For the map-type,
+       also handle the always modifer and release/delete.
+       * openmp.cc (resolve_omp_clauses): Accept tofrom
+       map-type modifier for target enter/exit data,
+       but use 'to' / 'from' internally.
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index 1db45eb5afa92a00273fcaed94527c03f6149ce6..422582ce0d961080aca2e77f6a188be4c4df0c84 100644 (file)
@@ -1414,6 +1414,11 @@ show_omp_namelist (int list_type, gfc_omp_namelist *n)
          case OMP_MAP_TO: fputs ("to:", dumpfile); break;
          case OMP_MAP_FROM: fputs ("from:", dumpfile); break;
          case OMP_MAP_TOFROM: fputs ("tofrom:", dumpfile); break;
+         case OMP_MAP_ALWAYS_TO: fputs ("always,to:", dumpfile); break;
+         case OMP_MAP_ALWAYS_FROM: fputs ("always,from:", dumpfile); break;
+         case OMP_MAP_ALWAYS_TOFROM: fputs ("always,tofrom:", dumpfile); break;
+         case OMP_MAP_DELETE: fputs ("delete:", dumpfile); break;
+         case OMP_MAP_RELEASE: fputs ("release:", dumpfile); break;
          default: break;
          }
       else if (list_type == OMP_LIST_LINEAR)
index 613ebc121c37599335673563e5235ca0e5f7b0eb..22d5dc6b157fc7644e645b6c23e6711f6ad31063 100644 (file)
@@ -7932,10 +7932,16 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
                        case OMP_MAP_ALWAYS_TO:
                        case OMP_MAP_ALLOC:
                          break;
+                       case OMP_MAP_TOFROM:
+                         n->u.map_op = OMP_MAP_TO;
+                         break;
+                       case OMP_MAP_ALWAYS_TOFROM:
+                         n->u.map_op = OMP_MAP_ALWAYS_TO;
+                         break;
                        default:
                          gfc_error ("TARGET ENTER DATA with map-type other "
-                                    "than TO, or ALLOC on MAP clause at %L",
-                                    &n->where);
+                                    "than TO, TOFROM or ALLOC on MAP clause "
+                                    "at %L", &n->where);
                          break;
                        }
                      break;
@@ -7947,10 +7953,16 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
                        case OMP_MAP_RELEASE:
                        case OMP_MAP_DELETE:
                          break;
+                       case OMP_MAP_TOFROM:
+                         n->u.map_op = OMP_MAP_FROM;
+                         break;
+                       case OMP_MAP_ALWAYS_TOFROM:
+                         n->u.map_op = OMP_MAP_ALWAYS_FROM;
+                         break;
                        default:
                          gfc_error ("TARGET EXIT DATA with map-type other "
-                                    "than FROM, RELEASE, or DELETE on MAP "
-                                    "clause at %L", &n->where);
+                                    "than FROM, TOFROM, RELEASE, or DELETE on "
+                                    "MAP clause at %L", &n->where);
                          break;
                        }
                      break;
index d0332ca2ee29517103fa07b734343624325616dc..567c93347f21737188e160375e310b051885c9db 100644 (file)
@@ -1,3 +1,13 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-07-01  Tobias Burnus  <tobias@codesourcery.com>
+
+       * c-c++-common/gomp/target-data-2.c: New test.
+       * c-c++-common/gomp/target-data-3.c: New test.
+       * gfortran.dg/gomp/target-data-1.f90: New test.
+       * gfortran.dg/gomp/target-data-2.f90: New test.
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
diff --git a/gcc/testsuite/c-c++-common/gomp/target-data-2.c b/gcc/testsuite/c-c++-common/gomp/target-data-2.c
new file mode 100644 (file)
index 0000000..e324870
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-additional-options "-fdump-tree-original" } */
+
+/* In OpenMP 5.2 permits tofrom for enter/exit data
+   in the FE, it is already converted to 'to' and 'from', respectively. */
+int x, y, z;
+
+void
+copyin ()
+{
+  #pragma omp target enter data map(x) map(tofrom: y) map(always, tofrom: z)
+}
+
+void
+copyout ()
+{
+  #pragma omp target exit data map(x) map(tofrom: y) map(always, tofrom: z)
+}
+
+/* { dg-final { scan-tree-dump-times "#pragma omp target enter data map\\(always,to:z\\) map\\(to:y\\) map\\(to:x\\)" 1 "original" } } */
+/* { dg-final { scan-tree-dump-times "#pragma omp target exit data map\\(always,from:z\\) map\\(from:y\\) map\\(from:x\\)" 1 "original" } } */
diff --git a/gcc/testsuite/c-c++-common/gomp/target-data-3.c b/gcc/testsuite/c-c++-common/gomp/target-data-3.c
new file mode 100644 (file)
index 0000000..8c6d5cb
--- /dev/null
@@ -0,0 +1,17 @@
+/* In OpenMP 5.2 permits tofrom for enter/exit data
+   in the FE, it is already converted to 'to' and 'from', respectively. */
+int y, z;
+
+void
+copyin ()
+{
+  #pragma omp target enter data map(from: y)         /* { dg-error "'#pragma omp target enter data' with map-type other than 'to', 'tofrom' or 'alloc' on 'map' clause" } */
+  #pragma omp target enter data map(always, from: z) /* { dg-error "'#pragma omp target enter data' with map-type other than 'to', 'tofrom' or 'alloc' on 'map' clause" } */
+}
+
+void
+copyout ()
+{
+  #pragma omp target exit data map(to: y)         /* { dg-error "'#pragma omp target exit data' with map-type other than 'from', 'tofrom', 'release' or 'delete' on 'map' clause" } */
+  #pragma omp target exit data map(always, to: z) /* { dg-error "'#pragma omp target exit data' with map-type other than 'from', 'tofrom', 'release' or 'delete' on 'map' clause" } */
+}
diff --git a/gcc/testsuite/gfortran.dg/gomp/target-data-1.f90 b/gcc/testsuite/gfortran.dg/gomp/target-data-1.f90
new file mode 100644 (file)
index 0000000..0f086f5
--- /dev/null
@@ -0,0 +1,17 @@
+! { dg-additional-options "-fdump-tree-original" }
+!
+! In OpenMP 5.2 permits tofrom for enter/exit data
+! in the FE, it is already converted to 'to' and 'from', respectively.
+module m
+  integer :: x, y, z
+contains
+subroutine copyin
+  !$omp target enter data map(x) map(tofrom: y) map(always, tofrom: z)
+end
+subroutine copyout
+  !$omp target exit data map(x) map(tofrom: y) map(always, tofrom: z)
+end
+end
+
+! { dg-final { scan-tree-dump-times "#pragma omp target enter data map\\(to:x\\) map\\(to:y\\) map\\(always,to:z\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma omp target exit data map\\(from:x\\) map\\(from:y\\) map\\(always,from:z\\)" 1 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/gomp/target-data-2.f90 b/gcc/testsuite/gfortran.dg/gomp/target-data-2.f90
new file mode 100644 (file)
index 0000000..71ee1eb
--- /dev/null
@@ -0,0 +1,14 @@
+! In OpenMP 5.2 permits tofrom for enter/exit data
+! in the FE, it is already converted to 'to' and 'from', respectively.
+module m
+  integer :: y, z
+contains
+subroutine copyin
+  !$omp target enter data map(from: y)         ! { dg-error "TARGET ENTER DATA with map-type other than TO, TOFROM or ALLOC on MAP clause" }
+  !$omp target enter data map(always, from: z) ! { dg-error "TARGET ENTER DATA with map-type other than TO, TOFROM or ALLOC on MAP clause" }
+end
+subroutine copyout
+  !$omp target exit data map(to: y)         ! { dg-error "TARGET EXIT DATA with map-type other than FROM, TOFROM, RELEASE, or DELETE on MAP clause" }
+  !$omp target exit data map(always, to: z) ! { dg-error "TARGET EXIT DATA with map-type other than FROM, TOFROM, RELEASE, or DELETE on MAP clause" }
+end
+end
index cfb47039178208d0365e20c960188ef872e2f648..570d1bfee2843a0ccee912eb5bb4de4f0f5a1bcb 100644 (file)
@@ -1,3 +1,11 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-07-01  Tobias Burnus  <tobias@codesourcery.com>
+
+       * libgomp.texi (OpenMP 5.2): Mark target enter/exit data
+       with fromto as implemented.
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index f7ac02776059bce68afc9c4457443e30378c819c..0f63d3b71119e67684c041c3370ce3fe96f33988 100644 (file)
@@ -389,7 +389,7 @@ The OpenMP 4.5 specification is fully supported.
       @tab Y @tab
 @item @code{ompt_callback_work} @tab N @tab
 @item Default map-type for @code{map} clause in @code{target enter/exit data}
-      @tab N @tab
+      @tab Y @tab
 @item New @code{doacross} clause as alias for @code{depend} with
       @code{source}/@code{sink} modifier @tab N @tab
 @item Deprecation of @code{depend} with @code{source}/@code{sink} modifier