]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP/Fortran: Add support for firstprivate and allocate clauses on scope construct
authorTobias Burnus <tobias@codesourcery.com>
Tue, 5 Jul 2022 08:03:25 +0000 (10:03 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Tue, 5 Jul 2022 08:03:25 +0000 (10:03 +0200)
Fortran commit to C/C++/backend commit
r13-862-gf38b20d68fade5a922b9f68c4c3841e653d1b83c

gcc/fortran/ChangeLog:

* openmp.cc (OMP_SCOPE_CLAUSES): Add firstprivate and allocate.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.2): Mark scope w/ firstprivate/allocate as Y.
* testsuite/libgomp.fortran/scope-2.f90: New test.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/scope-5.f90: New test.
* gfortran.dg/gomp/scope-6.f90: New test.

(cherry picked from commit ff35a75473d28205e52ecbcf9e6b5107b8b5ab90)

gcc/fortran/ChangeLog.omp
gcc/fortran/openmp.cc
gcc/testsuite/ChangeLog.omp
gcc/testsuite/gfortran.dg/gomp/scope-5.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/scope-6.f90 [new file with mode: 0644]
libgomp/ChangeLog.omp
libgomp/libgomp.texi
libgomp/testsuite/libgomp.fortran/scope-2.f90 [new file with mode: 0644]

index 24d4f84cf433b19a1aad73773a0b1afcb3a1334a..730308d9b727a644d53d4731a6e889d1fc8e2e15 100644 (file)
@@ -1,3 +1,10 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-06-03  Tobias Burnus  <tobias@codesourcery.com>
+
+       * openmp.cc (OMP_SCOPE_CLAUSES): Add firstprivate and allocate.
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index ebc29c65b5bbcb488a09902d2d489efffc46b172..64529f97336555ad89fa1eab0b5e0050271807d9 100644 (file)
@@ -4230,7 +4230,8 @@ cleanup:
    | OMP_CLAUSE_PRIVATE | OMP_CLAUSE_LASTPRIVATE | OMP_CLAUSE_REDUCTION)
 
 #define OMP_SCOPE_CLAUSES \
-  (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_REDUCTION)
+  (omp_mask (OMP_CLAUSE_PRIVATE) |OMP_CLAUSE_FIRSTPRIVATE              \
+   | OMP_CLAUSE_REDUCTION | OMP_CLAUSE_ALLOCATE)
 #define OMP_SECTIONS_CLAUSES \
   (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_FIRSTPRIVATE             \
    | OMP_CLAUSE_LASTPRIVATE | OMP_CLAUSE_REDUCTION | OMP_CLAUSE_ALLOCATE)
index db614a4e89920ef5eee8d0f2ac95db9a23f353d0..7534b517e4c485392be913775d3c457d271a398b 100644 (file)
@@ -1,3 +1,11 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-06-03  Tobias Burnus  <tobias@codesourcery.com>
+
+       * gfortran.dg/gomp/scope-5.f90: New test.
+       * gfortran.dg/gomp/scope-6.f90: New test.
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
diff --git a/gcc/testsuite/gfortran.dg/gomp/scope-5.f90 b/gcc/testsuite/gfortran.dg/gomp/scope-5.f90
new file mode 100644 (file)
index 0000000..baddae5
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+
+subroutine foo ()
+  integer f
+  f = 0;
+  !$omp scope firstprivate(f)  ! { dg-error "firstprivate variable 'f' is private in outer context" }
+    f = f + 1
+  !$omp end scope
+end
diff --git a/gcc/testsuite/gfortran.dg/gomp/scope-6.f90 b/gcc/testsuite/gfortran.dg/gomp/scope-6.f90
new file mode 100644 (file)
index 0000000..9c595b1
--- /dev/null
@@ -0,0 +1,23 @@
+! { dg-additional-options "-fdump-tree-original" }
+
+module m
+  use iso_c_binding
+  !use omp_lib, only: omp_allocator_handle_kind
+  implicit none
+  integer, parameter :: omp_allocator_handle_kind = c_intptr_t
+  integer :: a = 0, b = 42, c = 0
+
+contains
+  subroutine foo (h)
+  integer(omp_allocator_handle_kind), value :: h 
+  !$omp scope private (a) firstprivate (b) reduction (+: c) allocate ( h : a , b , c)
+    if (b /= 42) &
+      error stop
+    a = 36
+    b = 15
+    c = c + 1
+  !$omp end scope
+  end
+end
+
+! { dg-final { scan-tree-dump "omp scope private\\(a\\) firstprivate\\(b\\) reduction\\(\\+:c\\) allocate\\(allocator\\(D\\.\[0-9\]+\\):a) allocate\\(allocator\\(D\\.\[0-9\]+\\):b) allocate\\(allocator\\(D\\.\[0-9\]+\\):c)" "original" } }
index 37780a713a4db5f43509b408a31e32e4cfbc786a..7737c78d88e2a52917ba9663d4c5c3913acc72e3 100644 (file)
@@ -1,3 +1,11 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-06-03  Tobias Burnus  <tobias@codesourcery.com>
+
+       * libgomp.texi (OpenMP 5.2): Mark scope w/ firstprivate/allocate as Y.
+       * testsuite/libgomp.fortran/scope-2.f90: New test.
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index 4c9225d11f6e643522ba976bb83e909c30dcc0e0..82c08bf1fef3697c05fcfec60f6eefe50e86f031 100644 (file)
@@ -386,7 +386,7 @@ The OpenMP 4.5 specification is fully supported.
 @item Deprecation of delimited form of @code{declare target} @tab N @tab
 @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab
 @item @code{allocate} and @code{firstprivate} clauses on @code{scope}
-      @tab N @tab
+      @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
diff --git a/libgomp/testsuite/libgomp.fortran/scope-2.f90 b/libgomp/testsuite/libgomp.fortran/scope-2.f90
new file mode 100644 (file)
index 0000000..f2e1593
--- /dev/null
@@ -0,0 +1,57 @@
+program main
+  implicit none
+  integer a(0:63)
+  integer r, r2, i, n
+  a = 0
+  r = 0
+  r2 = 0
+  n = 64
+  !$omp parallel
+    !$omp scope
+     !$omp scope firstprivate (n)
+      !$omp do
+      do i = 0, 63
+       a(i) = a(i) + 1
+      end do
+     !$omp end scope nowait
+    !$omp end scope nowait
+
+    !$omp scope reduction(+: r) firstprivate (n)
+      !$omp do
+      do i = 0, 63
+        r = r + i
+        if (a(i) /= 1) &
+          error stop
+      end do
+      !$omp end do nowait
+      !$omp barrier
+      if (n /= 64) then
+        error stop
+      else
+        n = 128
+      end if
+    !$omp end scope nowait
+
+    !$omp barrier
+    if (r /= 64 * 63 / 2) &
+      error stop
+    !$omp scope private (i)
+     !$omp scope reduction(+: r2)
+      !$omp do
+      do i = 0, 63
+          r2 = r2 + 2 * i
+          a(i) = a(i) + i
+      end do
+      !$omp end do nowait
+     !$omp end scope
+    !$omp end scope nowait
+    if (r2 /= 64 * 63) &
+      error stop
+    !$omp do
+    do i = 0, 63
+      if (a(i) /= i + 1) &
+        error stop
+    end do
+    !$omp end do nowait
+  !$omp end parallel
+end program