diff mbox series

[og7] Enable fortran derived types in acc enter/exit data

Message ID 1a54d19d-65de-d61c-568b-bf15fcd8c707@codesourcery.com
State New
Headers show
Series [og7] Enable fortran derived types in acc enter/exit data | expand

Commit Message

Cesar Philippidis Oct. 11, 2017, 2:03 p.m. UTC
This patch enables fortran derived type members to be used in acc
enter/exit data constructs. Now, both acc enter/exit data and acc update
support individual derived type members. Eventually, I'd like all of the
acc data clauses to support individual derived type members. But that
may not happen in the near term.

Cesar
diff mbox series

Patch

2017-10-11  Cesar Philippidis  <cesar@codesourcery.com>

	gcc/fortran/
	* openmp.c (match_acc): Add new argument derived_types. Propagate
	it to gfc_match_omp_clauses.
	(gfc_match_oacc_enter_data): Update call to match_acc.
	(gfc_match_oacc_exit_data): Likewise.

	gcc/testsuite/
	* gfortran.dg/goacc/derived-types.f90: Adjust test case.

	libgomp/
	* testsuite/libgomp.oacc-fortran/derived-type-2.f90: New test.


diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index a59b7d27e9c..5562f4e02f7 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -2141,10 +2141,12 @@  gfc_match_omp_clauses (gfc_omp_clauses **cp, omp_mask mask,
 
 
 static match
-match_acc (gfc_exec_op op, const omp_mask mask, const omp_mask dtype_mask)
+match_acc (gfc_exec_op op, const omp_mask mask, const omp_mask dtype_mask,
+	   bool derived_types=false)
 {
   gfc_omp_clauses *c;
-  if (gfc_match_omp_clauses (&c, mask, dtype_mask, false, false, true)
+  if (gfc_match_omp_clauses (&c, mask, dtype_mask, false, false, true,
+			     derived_types)
       != MATCH_YES)
     return MATCH_ERROR;
   new_st.op = op;
@@ -2329,7 +2331,7 @@  match
 gfc_match_oacc_enter_data (void)
 {
   return match_acc (EXEC_OACC_ENTER_DATA, OACC_ENTER_DATA_CLAUSES,
-		    OMP_MASK2_LAST);
+		    OMP_MASK2_LAST, true);
 }
 
 
@@ -2337,7 +2339,7 @@  match
 gfc_match_oacc_exit_data (void)
 {
   return match_acc (EXEC_OACC_EXIT_DATA, OACC_EXIT_DATA_CLAUSES,
-		    OMP_MASK2_LAST);
+		    OMP_MASK2_LAST, true);
 }
 
 
diff --git a/gcc/testsuite/gfortran.dg/goacc/derived-types.f90 b/gcc/testsuite/gfortran.dg/goacc/derived-types.f90
index 44a38149560..11d055a79f2 100644
--- a/gcc/testsuite/gfortran.dg/goacc/derived-types.f90
+++ b/gcc/testsuite/gfortran.dg/goacc/derived-types.f90
@@ -28,11 +28,14 @@  program derived_acc
   !$acc update self(var%a)
   
   !$acc enter data copyin(var)
-  !$acc enter data copyin(var%a) ! { dg-error "Syntax error in OpenMP" }
+  !$acc enter data copyin(var%a)
 
   !$acc exit data copyout(var)
-  !$acc exit data copyout(var%a) ! { dg-error "Syntax error in OpenMP" }
+  !$acc exit data copyout(var%a)
 
+  !$acc data copy(var%a) ! { dg-error "Syntax error in OpenMP" }
+  !$acc end data ! { dg-error "Unexpected ..ACC END DATA" }
+  
   !$acc data copy(var)
   !$acc end data
 
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/derived-type-2.f90 b/libgomp/testsuite/libgomp.oacc-fortran/derived-type-2.f90
new file mode 100644
index 00000000000..3ed21953261
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/derived-type-2.f90
@@ -0,0 +1,67 @@ 
+! Test derived types in data clauses.
+
+! { dg-do run }
+
+module newtype
+  type dtype
+     integer :: a, b, c
+     integer, allocatable :: ary(:)
+  end type dtype
+end module newtype
+
+program main
+  use newtype
+  implicit none
+  integer, parameter :: n = 100
+  integer i
+  type (dtype), dimension(n) :: d1
+  type (dtype) :: d2
+  external process
+
+  allocate (d2%ary(n))
+
+  !$acc enter data create (d2%ary)
+
+  do i = 1, n
+     d2%ary(i) = 1
+  end do
+
+  !$acc update device (d2%ary)
+
+  call process (n, d2%ary)
+
+  !$acc exit data copyout (d2%ary)
+
+  do i = 1, n
+     if (d2%ary(i) /= i + 1) call abort
+  end do
+
+  !$acc data copy(d1(1:n))
+  !$acc parallel loop
+  do i = 1, n
+     d1(i)%a = i
+     d1(i)%b = i-1
+     d1(i)%c = i+1
+  end do
+  !$acc end data
+
+  do i = 1, n
+     if (d1(i)%a /= i) call abort
+     if (d1(i)%b /= i-1) call abort
+     if (d1(i)%c /= i+1) call abort
+  end do
+
+  deallocate (d2%ary)
+end program main
+
+subroutine process (a, b)
+  use newtype
+  implicit none
+  integer :: a, i
+  integer :: b(a)
+
+  !$acc parallel loop present (b(1:a))
+  do i = 1, a
+     b(i) = b(i) + i
+  end do
+end subroutine process