This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Allow !$omp directives anywhere in the specification part


Hi!

Per discussions on omp-lang, the only requirement on !$omp directive
ordering for declarative directives is that they appear somewhere in the
specification part, but they can appear before or after use-stmt, before or
after import-stmt, before or after implicit-stmt, or anywhere in between
other specification part declarations.

I have kept the OpenACC handling as is, please check if you shouldn't
treat them like the OpenMP ones though.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk
and 6.2.

2016-06-01  Jakub Jelinek  <jakub@redhat.com>

	* parse.c (case_decl): Move ST_OMP_* to ...
	(case_omp_decl): ... here, new macro.
	(verify_st_order): For case_omp_decl, complain about
	p->state >= ORDER_EXEC, but don't change p->state otherwise.

	* gfortran.dg/gomp/order-1.f90: New test.
	* gfortran.dg/gomp/order-2.f90: New test.

--- gcc/fortran/parse.c.jj	2016-05-09 10:20:26.000000000 +0200
+++ gcc/fortran/parse.c	2016-06-01 11:05:38.860786469 +0200
@@ -1390,9 +1390,13 @@ next_statement (void)
 
 #define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \
   case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \
-  case ST_TYPE: case ST_INTERFACE: case ST_OMP_THREADPRIVATE: \
-  case ST_PROCEDURE: case ST_OMP_DECLARE_SIMD: case ST_OMP_DECLARE_REDUCTION: \
-  case ST_OMP_DECLARE_TARGET: case ST_OACC_ROUTINE: case ST_OACC_DECLARE
+  case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE: case ST_OACC_ROUTINE: \
+  case ST_OACC_DECLARE
+
+/* OpenMP declaration statements.  */
+
+#define case_omp_decl case ST_OMP_THREADPRIVATE: case ST_OMP_DECLARE_SIMD: \
+  case ST_OMP_DECLARE_TARGET: case ST_OMP_DECLARE_REDUCTION
 
 /* Block end statements.  Errors associated with interchanging these
    are detected in gfc_match_end().  */
@@ -2488,6 +2492,14 @@ verify_st_order (st_state *p, gfc_statem
 	p->state = ORDER_SPEC;
       break;
 
+    case_omp_decl:
+      /* The OpenMP directives have to be somewhere in the specification
+	 part, but there are no further requirements on their ordering.
+	 Thus don't adjust p->state, just ignore them.  */
+      if (p->state >= ORDER_EXEC)
+	goto order;
+      break;
+
     case_executable:
     case_exec_markers:
       if (p->state < ORDER_EXEC)
@@ -3563,6 +3575,7 @@ loop:
     case ST_STRUCTURE_DECL:
     case ST_DERIVED_DECL:
     case_decl:
+    case_omp_decl:
 declSt:
       if (!verify_st_order (&ss, st, false))
 	{
--- gcc/testsuite/gfortran.dg/gomp/order-1.f90.jj	2016-06-01 11:39:36.215342050 +0200
+++ gcc/testsuite/gfortran.dg/gomp/order-1.f90	2016-06-01 11:55:51.662918805 +0200
@@ -0,0 +1,92 @@
+! { dg-do compile }
+
+module m
+  integer :: i
+end module m
+subroutine f1
+  type t
+    integer :: i
+  end type t
+  interface
+    integer function f3 (a, b)
+      !$omp declare simd (f3) uniform (a)
+      use m
+      import :: t
+      implicit none
+      type (t) :: a
+      integer :: b
+    end function f3
+  end interface
+  interface
+    integer function f4 (a, b)
+      use m
+      !$omp declare simd (f4) uniform (a)
+      import :: t
+      implicit none
+      type (t) :: a
+      integer :: b
+    end function f4
+  end interface
+  interface
+    integer function f5 (a, b)
+      use m
+      import :: t
+      !$omp declare simd (f5) uniform (a)
+      implicit none
+      type (t) :: a
+      integer :: b
+    end function f5
+  end interface
+  interface
+    integer function f6 (a, b)
+      use m
+      import :: t
+      implicit none
+      !$omp declare simd (f6) uniform (a)
+      type (t) :: a
+      integer :: b
+    end function f6
+  end interface
+  interface
+    integer function f7 (a, b)
+      use m
+      import :: t
+      implicit none
+      type (t) :: a
+      !$omp declare simd (f7) uniform (a)
+      integer :: b
+    end function f7
+  end interface
+  call f2
+contains
+  subroutine f2
+    !$omp threadprivate (t1)
+    use m
+    !$omp threadprivate (t2)
+    implicit none
+    !$omp threadprivate (t3)
+    integer, save :: t1, t2, t3, t4
+    !$omp threadprivate (t4)
+    t1 = 1; t2 = 2; t3 = 3; t4 = 4
+  end subroutine f2
+  subroutine f8
+    !$omp declare reduction (f8_1:real:omp_out = omp_out + omp_in)
+    use m
+    !$omp declare reduction (f8_2:real:omp_out = omp_out + omp_in)
+    implicit none
+    !$omp declare reduction (f8_3:real:omp_out = omp_out + omp_in)
+    integer :: j
+    !$omp declare reduction (f8_4:real:omp_out = omp_out + omp_in)
+  end subroutine f8
+  subroutine f9
+    !$omp declare target (f9_1)
+    use m
+    !$omp declare target (f9_2)
+    implicit none
+    !$omp declare target (f9_3)
+    !$omp declare target
+    integer, save :: f9_1, f9_2, f9_3, f9_4
+    !$omp declare target (f9_4)
+    f9_1 = 1; f9_2 = 2; f9_3 = 3; f9_4 = 4
+  end subroutine f9
+end subroutine f1
--- gcc/testsuite/gfortran.dg/gomp/order-2.f90.jj	2016-06-01 11:56:06.079731210 +0200
+++ gcc/testsuite/gfortran.dg/gomp/order-2.f90	2016-06-01 11:57:22.573735851 +0200
@@ -0,0 +1,37 @@
+! { dg-do compile }
+
+module m
+  integer :: i
+end module m
+subroutine f1
+  call f2
+contains
+  subroutine f2
+    use m
+    implicit none
+    integer, save :: t
+    t = 1
+    !$omp threadprivate (t1)	! { dg-error "Unexpected" }
+  end subroutine f2
+  subroutine f3
+    use m
+    implicit none
+    integer :: j
+    j = 1
+    !$omp declare reduction (foo:real:omp_out = omp_out + omp_in)	! { dg-error "Unexpected" }
+  end subroutine f3
+  subroutine f4
+    use m
+    implicit none
+    !$omp declare target
+    integer, save :: f4_1
+    f4_1 = 1
+    !$omp declare target (f4_1)	! { dg-error "Unexpected" }
+    !$omp declare target	! { dg-error "Unexpected" }
+  end subroutine f4
+  integer function f5 (a, b)
+    integer :: a, b
+    a = 1; b = 2
+    !$omp declare simd (f5) notinbranch	! { dg-error "Unexpected" }
+  end function f5
+end subroutine f1

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]