]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP: Support 'if (simd:/cancel:' in Fortran
authorTobias Burnus <tobias@codesourcery.com>
Fri, 21 Aug 2020 07:42:52 +0000 (09:42 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Fri, 21 Aug 2020 07:42:52 +0000 (09:42 +0200)
gcc/fortran/ChangeLog:

* gfortran.h (enum gfc_omp_if_kind): Add OMP_IF_CANCEL and OMP_IF_SIMD.
* openmp.c (OMP_SIMD_CLAUSES): Add OMP_CLAUSE_IF.
(gfc_match_omp_clauses, resolve_omp_clauses): Handle 'if (simd/cancel:'.
* dump-parse-tree.c (show_omp_clauses): Likewise.
* trans-openmp.c (gfc_trans_omp_clauses, gfc_trans_omp_cancel,
(gfc_split_omp_clauses): Likewise.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/cancel-2.f90: New test.
* gfortran.dg/gomp/cancel-3.f90: New test.
* gfortran.dg/gomp/if-1.f90: New test.

(cherry picked from commit e55ba804d3b8de86a430a8a5553dfc1ad06daa74)

gcc/fortran/ChangeLog.omp
gcc/fortran/dump-parse-tree.c
gcc/fortran/gfortran.h
gcc/fortran/openmp.c
gcc/fortran/trans-openmp.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/gfortran.dg/gomp/cancel-2.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/cancel-3.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/if-1.f90 [new file with mode: 0644]

index 54ecabf1ea50e3d80c2938003bce6ee264aa1e55..ae347c925c92344f7800b79fafbdcceba34fd753 100644 (file)
@@ -1,3 +1,15 @@
+2020-08-21  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline
+       2020-07-22  Tobias Burnus  <tobias@codesourcery.com>
+
+       * gfortran.h (enum gfc_omp_if_kind): Add OMP_IF_CANCEL and OMP_IF_SIMD.
+       * openmp.c (OMP_SIMD_CLAUSES): Add OMP_CLAUSE_IF.
+       (gfc_match_omp_clauses, resolve_omp_clauses): Handle 'if (simd/cancel:'.
+       * dump-parse-tree.c (show_omp_clauses): Likewise.
+       * trans-openmp.c (gfc_trans_omp_clauses, gfc_trans_omp_cancel,
+       (gfc_split_omp_clauses): Likewise.
+
 2020-08-19  Sandra Loosemore  <sandra@codesourcery.com>
 
        Annotate inner loops in "acc kernels loop" directives (Fortran).
index e79494d59bf896bdeb5db9b22cf1afe2804018ea..364584d2060c1f58cbe337ab2283fd9df44a1b1b 100644 (file)
@@ -1693,7 +1693,9 @@ show_omp_clauses (gfc_omp_clauses *omp_clauses)
     if (omp_clauses->if_exprs[i])
       {
        static const char *ifs[] = {
+         "CANCEL",
          "PARALLEL",
+         "SIMD",
          "TASK",
          "TASKLOOP",
          "TARGET",
index 2620e9a25504173409b337309847c5fbe97e6951..ec49e1ae920d5f80336fb65946f81166bee18c9a 100644 (file)
@@ -1323,7 +1323,9 @@ enum gfc_omp_cancel_kind
 
 enum gfc_omp_if_kind
 {
+  OMP_IF_CANCEL,
   OMP_IF_PARALLEL,
+  OMP_IF_SIMD,
   OMP_IF_TASK,
   OMP_IF_TASKLOOP,
   OMP_IF_TARGET,
index b9e4bdaedf07785b01192b856dfbbd9a373999c6..bd126e4c669430540ed49279cdc91df7afda1058 100644 (file)
@@ -1305,7 +1305,9 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
                {
                  /* This should match the enum gfc_omp_if_kind order.  */
                  static const char *ifs[OMP_IF_LAST] = {
+                   " cancel : %e )",
                    " parallel : %e )",
+                   " simd : %e )",
                    " task : %e )",
                    " taskloop : %e )",
                    " target : %e )",
@@ -2580,7 +2582,8 @@ cleanup:
 #define OMP_SIMD_CLAUSES \
   (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_LASTPRIVATE              \
    | OMP_CLAUSE_REDUCTION | OMP_CLAUSE_COLLAPSE | OMP_CLAUSE_SAFELEN   \
-   | OMP_CLAUSE_LINEAR | OMP_CLAUSE_ALIGNED | OMP_CLAUSE_SIMDLEN)
+   | OMP_CLAUSE_LINEAR | OMP_CLAUSE_ALIGNED | OMP_CLAUSE_SIMDLEN       \
+   | OMP_CLAUSE_IF)
 #define OMP_TASK_CLAUSES \
   (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_FIRSTPRIVATE             \
    | OMP_CLAUSE_SHARED | OMP_CLAUSE_IF | OMP_CLAUSE_DEFAULT            \
@@ -4145,33 +4148,53 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
        else
          switch (code->op)
            {
+           case EXEC_OMP_CANCEL:
+             ok = ifc == OMP_IF_CANCEL;
+             break;
+
            case EXEC_OMP_PARALLEL:
            case EXEC_OMP_PARALLEL_DO:
            case EXEC_OMP_PARALLEL_SECTIONS:
            case EXEC_OMP_PARALLEL_WORKSHARE:
-           case EXEC_OMP_PARALLEL_DO_SIMD:
            case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
-           case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
            case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
-           case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
              ok = ifc == OMP_IF_PARALLEL;
              break;
 
+           case EXEC_OMP_PARALLEL_DO_SIMD:
+           case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
+           case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
+             ok = ifc == OMP_IF_PARALLEL || ifc == OMP_IF_SIMD;
+             break;
+
+           case EXEC_OMP_SIMD:
+           case EXEC_OMP_DO_SIMD:
+           case EXEC_OMP_DISTRIBUTE_SIMD:
+           case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
+             ok = ifc == OMP_IF_SIMD;
+             break;
+
            case EXEC_OMP_TASK:
              ok = ifc == OMP_IF_TASK;
              break;
 
            case EXEC_OMP_TASKLOOP:
-           case EXEC_OMP_TASKLOOP_SIMD:
              ok = ifc == OMP_IF_TASKLOOP;
              break;
 
+           case EXEC_OMP_TASKLOOP_SIMD:
+             ok = ifc == OMP_IF_TASKLOOP || ifc == OMP_IF_SIMD;
+             break;
+
            case EXEC_OMP_TARGET:
            case EXEC_OMP_TARGET_TEAMS:
            case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
+             ok = ifc == OMP_IF_TARGET;
+             break;
+
            case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
            case EXEC_OMP_TARGET_SIMD:
-             ok = ifc == OMP_IF_TARGET;
+             ok = ifc == OMP_IF_TARGET || ifc == OMP_IF_SIMD;
              break;
 
            case EXEC_OMP_TARGET_DATA:
@@ -4191,13 +4214,18 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
              break;
 
            case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
-           case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
            case EXEC_OMP_TARGET_PARALLEL:
            case EXEC_OMP_TARGET_PARALLEL_DO:
-           case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
              ok = ifc == OMP_IF_TARGET || ifc == OMP_IF_PARALLEL;
              break;
 
+           case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
+           case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
+             ok = (ifc == OMP_IF_TARGET
+                   || ifc == OMP_IF_PARALLEL
+                   || ifc == OMP_IF_SIMD);
+             break;
+
            default:
              ok = false;
              break;
@@ -4205,7 +4233,9 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
        if (!ok)
          {
            static const char *ifs[] = {
+             "CANCEL",
              "PARALLEL",
+             "SIMD",
              "TASK",
              "TASKLOOP",
              "TARGET",
index 1c8ca812e47e3287c01ce7bb2eb81d65f34d5024..11ac5aa698d86ede97ae8ec0af04bd285ab2d731 100644 (file)
@@ -3199,9 +3199,15 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses,
        c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_IF);
        switch (ifc)
          {
+         case OMP_IF_CANCEL:
+           OMP_CLAUSE_IF_MODIFIER (c) = VOID_CST;
+           break;
          case OMP_IF_PARALLEL:
            OMP_CLAUSE_IF_MODIFIER (c) = OMP_PARALLEL;
            break;
+         case OMP_IF_SIMD:
+           OMP_CLAUSE_IF_MODIFIER (c) = OMP_SIMD;
+           break;
          case OMP_IF_TASK:
            OMP_CLAUSE_IF_MODIFIER (c) = OMP_TASK;
            break;
@@ -4204,13 +4210,18 @@ gfc_trans_omp_cancel (gfc_code *code)
     default: gcc_unreachable ();
     }
   gfc_start_block (&block);
-  if (code->ext.omp_clauses->if_expr)
+  if (code->ext.omp_clauses->if_expr
+      || code->ext.omp_clauses->if_exprs[OMP_IF_CANCEL])
     {
       gfc_se se;
       tree if_var;
 
+      gcc_assert ((code->ext.omp_clauses->if_expr == NULL)
+                 ^ (code->ext.omp_clauses->if_exprs[OMP_IF_CANCEL] == NULL));
       gfc_init_se (&se, NULL);
-      gfc_conv_expr (&se, code->ext.omp_clauses->if_expr);
+      gfc_conv_expr (&se, code->ext.omp_clauses->if_expr != NULL
+                         ? code->ext.omp_clauses->if_expr
+                         : code->ext.omp_clauses->if_exprs[OMP_IF_CANCEL]);
       gfc_add_block_to_block (&block, &se.pre);
       if_var = gfc_evaluate_now (se.expr, &block);
       gfc_add_block_to_block (&block, &se.post);
@@ -5009,6 +5020,8 @@ gfc_split_omp_clauses (gfc_code *code,
          /* Duplicate collapse.  */
          clausesa[GFC_OMP_SPLIT_SIMD].collapse
            = code->ext.omp_clauses->collapse;
+         clausesa[GFC_OMP_SPLIT_SIMD].if_exprs[OMP_IF_SIMD]
+           = code->ext.omp_clauses->if_exprs[OMP_IF_SIMD];
          /* And this is copied to all.  */
          clausesa[GFC_OMP_SPLIT_SIMD].if_expr
            = code->ext.omp_clauses->if_expr;
index a992892b8082d2ecd64984056b59650ea77b6e17..ecccbc8f9c1bf6e194a6e732ba18c5ab8775830a 100644 (file)
@@ -1,3 +1,12 @@
+2020-08-21  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline
+       2020-07-22  Tobias Burnus  <tobias@codesourcery.com>
+
+       * gfortran.dg/gomp/cancel-2.f90: New test.
+       * gfortran.dg/gomp/cancel-3.f90: New test.
+       * gfortran.dg/gomp/if-1.f90: New test.
+
 2020-08-19   Sandra Loosemore  <sandra@codesourcery.com>
 
        Annotate inner loops in "acc kernels loop" directives (Fortran).
diff --git a/gcc/testsuite/gfortran.dg/gomp/cancel-2.f90 b/gcc/testsuite/gfortran.dg/gomp/cancel-2.f90
new file mode 100644 (file)
index 0000000..481b1aa
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-do compile }
+
+subroutine foo ()
+  !$omp parallel
+    !$omp cancel parallel if (.true.)
+    !$omp cancel parallel if (cancel: .true.)
+
+    !$omp cancel parallel if (.true.) if (.true.)                   ! { dg-error "Failed to match clause" }
+    !$omp cancel parallel if (cancel: .true.) if (cancel: .true.)   ! { dg-error "Failed to match clause" }
+    !$omp cancel parallel if (cancel: .true.) if (.true.)           ! { dg-error "IF clause without modifier at .1. used together with IF clauses with modifiers" }
+    !$omp cancel parallel if (cancel: .true.) if (parallel: .true.) ! { dg-error "IF clause modifier PARALLEL at .1. not appropriate for the current OpenMP construct" }
+    !$omp cancel parallel if (.true.) if (cancel: .true.)           ! { dg-error "Failed to match clause at" }
+    !$omp cancel parallel if (parallel: .true.) if (cancel: .true.) ! { dg-error "IF clause modifier PARALLEL at .1. not appropriate for the current OpenMP construct" }
+  !$omp end parallel
+end subroutine
diff --git a/gcc/testsuite/gfortran.dg/gomp/cancel-3.f90 b/gcc/testsuite/gfortran.dg/gomp/cancel-3.f90
new file mode 100644 (file)
index 0000000..78b54d8
--- /dev/null
@@ -0,0 +1,35 @@
+! { dg-do compile }
+! { dg-additional-options "-fdump-tree-original" }
+
+subroutine foo ()
+  !$omp parallel
+    !$omp cancel parallel if (.true.)
+    !$omp cancel parallel if (cancel: .true.)
+    !$omp cancel parallel if (.false.)
+    !$omp cancel parallel if (cancel: .false.)
+  !$omp end parallel
+
+  !$omp sections
+    !$omp cancel sections if (cancel: .true.)
+    stop
+  !$omp end sections
+
+  !$omp do
+  do i = 1, 10
+    !$omp cancel do if (.false.)
+  end do
+
+  !$omp task
+    !$omp cancel taskgroup if (cancel: .false.)
+  !$omp end task
+  !$omp task
+    !$omp cancel taskgroup
+  !$omp end task
+end subroutine
+
+! { dg-final { scan-tree-dump-times "__builtin_GOMP_cancel \\(1, 1\\);" 2 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_GOMP_cancel \\(1, 0\\);" 2 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_GOMP_cancel \\(4, 1\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_GOMP_cancel \\(2, 0\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_GOMP_cancel \\(8, 0\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_GOMP_cancel \\(8, 1\\);" 1 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/gomp/if-1.f90 b/gcc/testsuite/gfortran.dg/gomp/if-1.f90
new file mode 100644 (file)
index 0000000..ddf903f
--- /dev/null
@@ -0,0 +1,122 @@
+! { dg-do compile }
+
+subroutine foo (a, b, p, q)
+  logical, value :: a
+  logical :: b
+  integer :: p(:)
+  integer, pointer :: q(:)
+  integer :: i
+  !$omp parallel if (a)
+  !$omp end parallel
+  !$omp parallel if (parallel:a)
+  !$omp end parallel
+  !$omp parallel do simd if (a)
+  do i = 1, 16
+  end do
+  !$omp end parallel do simd
+  !$omp parallel do simd if (parallel : a)
+  do i = 1, 16
+  end do
+  !$omp end parallel do simd
+  !$omp parallel do simd if (simd : a)
+  do i = 1, 16
+  end do
+  !$omp end parallel do simd
+  !$omp parallel do simd if (simd : a) if (parallel:b)
+  do i = 1, 16
+  end do
+  !$omp end parallel do simd
+  !$omp task if (a)
+  !$omp end task
+  !$omp task if (task: a)
+  !$omp end task
+  !$omp taskloop if (a)
+  do i = 1, 16
+  end do
+  !$omp end taskloop
+  !$omp taskloop if (taskloop : a)
+  do i = 1, 16
+  end do
+  !$omp end taskloop
+  !$omp taskloop simd if (a)
+  do i = 1, 16
+  end do
+  !$omp end taskloop simd
+  !$omp taskloop simd if (taskloop : a)
+  do i = 1, 16
+  end do
+  !$omp end taskloop simd
+  !$omp taskloop simd if (simd : a)
+  do i = 1, 16
+  end do
+  !$omp end taskloop simd
+  !$omp taskloop simd if (taskloop:b) if (simd : a)
+  do i = 1, 16
+  end do
+  !$omp end taskloop simd
+  !$omp target if (a)
+  !$omp end target
+  !$omp target if (target: a)
+  !$omp end target
+  !$omp target simd if (a)
+  do i = 1, 16
+  end do
+  !$omp end target simd
+  !$omp target simd if (simd : a) if (target: b)
+  do i = 1, 16
+  end do
+  !$omp end target simd
+  !$omp target teams distribute parallel do simd if (a)
+  do i = 1, 16
+  end do
+  !$omp end target teams distribute parallel do simd
+  !$omp target teams distribute parallel do simd if (parallel : a) if (target: b)
+  do i = 1, 16
+  end do
+  !$omp end target teams distribute parallel do simd
+  !$omp target teams distribute parallel do simd if (simd : a) if (target: b)
+  do i = 1, 16
+  end do
+  !$omp end target teams distribute parallel do simd
+
+  !$omp target data if (a) map (p(1:2))
+  !$omp end target data
+  !$omp target data if (target data: a) map (p(1:2))
+  !$omp end target data
+  !$omp target enter data if (a) map (to: p(1:2))
+  !$omp target enter data if (target enter data: a) map (to: p(1:2))
+  !$omp target exit data if (a) map (from: p(1:2))
+  !$omp target exit data if (target exit data: a) map (from: p(1:2))
+  !$omp target update if (a) to (q(1:3))
+  !$omp target update if (target update:a) to (q(1:3))
+  !$omp parallel
+    !$omp cancel parallel if (a)
+  !$omp end parallel
+  !$omp parallel
+    !$omp cancel parallel if (cancel:a)
+  !$omp end parallel
+  !$omp do
+  do i = 1, 16
+      !$omp cancel do if (a)
+  end do
+  !$omp do
+  do i = 1, 16
+      !$omp cancel do if (cancel: a)
+  end do
+  !$omp sections
+    !$omp section
+       !$omp cancel sections if (a)
+  !$omp end sections
+  !$omp sections
+    !$omp section
+       !$omp cancel sections if (cancel: a)
+  !$omp end sections
+  !$omp taskgroup
+    !$omp task
+      !$omp cancel taskgroup if (a)
+    !$omp end task
+    !$omp task
+      !$omp cancel taskgroup if (cancel: a)
+    !$omp end task
+  !$omp end taskgroup
+end