]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Introduce gimple_omp_ordered_standalone_p
authorJakub Jelinek <jakub@redhat.com>
Wed, 7 Sep 2022 08:36:22 +0000 (10:36 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Wed, 7 Sep 2022 08:36:22 +0000 (10:36 +0200)
On Sat, Sep 03, 2022 at 10:07:27AM +0200, Jakub Jelinek via Gcc-patches wrote:
> Incrementally, I'd like to change the way we differentiate between
> stand-alone and block-associated ordered constructs, because the current
> way of looking for presence of doacross clause doesn't work well if those
> clauses are removed because they had been invalid (wrong syntax or
> unknown variables in it etc.)

The following, so far only lightly tested, patch implements that.

2022-09-06  Jakub Jelinek  <jakub@redhat.com>

gcc/
* gimple.h (enum gf_mask): Add GF_OMP_ORDERED_STANDALONE enumerator.
(gimple_omp_subcode):  Use GIMPLE_OMP_ORDERED instead of
GIMPLE_OMP_TEAMS as upper bound.
(gimple_omp_ordered_standalone_p, gimple_omp_ordered_standalone): New
inline functions.
* gimplify.cc (find_standalone_omp_ordered): Look for OMP_ORDERED with
NULL OMP_ORDERED_BODY rather than with OMP_DOACROSS clause.
(gimplify_expr): Call gimple_omp_ordered_standalone for OMP_ORDERED
with NULL OMP_ORDERED_BODY.
* omp-low.cc (check_omp_nesting_restrictions): Use
gimple_omp_ordered_standalone_p test instead of
omp_find_clause (..., OMP_CLAUSE_DOACROSS).
(lower_omp_ordered): Likewise.
* omp-expand.cc (expand_omp, build_omp_regions_1,
omp_make_gimple_edges): Likewise.
gcc/cp/
* pt.cc (tsubst_expr) <case OMP_ORDERED>: If OMP_BODY was NULL, keep
it NULL after instantiation too.
gcc/testsuite/
* c-c++-common/gomp/sink-3.c: Don't expect a superfluous error during
error recovery.
* c-c++-common/gomp/doacross-6.c (foo): Add further tests.

(cherry picked from commit 3f585bdaa7f6fb02753ba7b4918f065357a6b7fd)

gcc/ChangeLog.omp
gcc/cp/ChangeLog.omp
gcc/cp/pt.cc
gcc/gimple.h
gcc/gimplify.cc
gcc/omp-expand.cc
gcc/omp-low.cc
gcc/testsuite/ChangeLog.omp
gcc/testsuite/c-c++-common/gomp/doacross-6.c
gcc/testsuite/c-c++-common/gomp/sink-3.c

index 47babd06e6371d374f5de2e4aa7f44c6b19d8f5f..a2dbe630bab0b616350625f884ec07d93f11c732 100644 (file)
@@ -1,3 +1,24 @@
+2022-09-07  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-09-06  Jakub Jelinek  <jakub@redhat.com>
+
+       * gimple.h (enum gf_mask): Add GF_OMP_ORDERED_STANDALONE enumerator.
+       (gimple_omp_subcode):  Use GIMPLE_OMP_ORDERED instead of
+       GIMPLE_OMP_TEAMS as upper bound.
+       (gimple_omp_ordered_standalone_p, gimple_omp_ordered_standalone): New
+       inline functions.
+       * gimplify.cc (find_standalone_omp_ordered): Look for OMP_ORDERED with
+       NULL OMP_ORDERED_BODY rather than with OMP_DOACROSS clause.
+       (gimplify_expr): Call gimple_omp_ordered_standalone for OMP_ORDERED
+       with NULL OMP_ORDERED_BODY.
+       * omp-low.cc (check_omp_nesting_restrictions): Use
+       gimple_omp_ordered_standalone_p test instead of
+       omp_find_clause (..., OMP_CLAUSE_DOACROSS).
+       (lower_omp_ordered): Likewise.
+       * omp-expand.cc (expand_omp, build_omp_regions_1,
+       omp_make_gimple_edges): Likewise.
+
 2022-09-05  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index 97a956f02456be90a82cf2508d950a3e9ae70849..35504f4c92b269daf0acec2b7a7af0191f24ef74 100644 (file)
@@ -1,3 +1,11 @@
+2022-09-07  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-09-06  Jakub Jelinek  <jakub@redhat.com>
+
+       * pt.cc (tsubst_expr) <case OMP_ORDERED>: If OMP_BODY was NULL, keep
+       it NULL after instantiation too.
+
 2022-09-06  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index 42fc7e9746130354fa72d04a14435849da36c5d2..3935f6199b1aecaef5fed167e726357430a8dbd8 100644 (file)
@@ -19385,9 +19385,14 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
     case OMP_ORDERED:
       tmp = tsubst_omp_clauses (OMP_ORDERED_CLAUSES (t), C_ORT_OMP, args,
                                complain, in_decl);
-      stmt = push_stmt_list ();
-      RECUR (OMP_BODY (t));
-      stmt = pop_stmt_list (stmt);
+      if (OMP_BODY (t))
+       {
+         stmt = push_stmt_list ();
+         RECUR (OMP_BODY (t));
+         stmt = pop_stmt_list (stmt);
+       }
+      else
+       stmt = NULL_TREE;
 
       t = copy_node (t);
       OMP_BODY (t) = stmt;
index 87ab13ee0e6d7f3caef57445c5ba28a5173b7141..7af58c4ae9039ee582a0a8aebac0b5d033450467 100644 (file)
@@ -200,6 +200,7 @@ enum gf_mask {
     GF_OMP_RETURN_NOWAIT       = 1 << 0,
 
     GF_OMP_SECTION_LAST                = 1 << 0,
+    GF_OMP_ORDERED_STANDALONE   = 1 << 0,
     GF_OMP_ATOMIC_MEMORY_ORDER  = (1 << 6) - 1,
     GF_OMP_ATOMIC_NEED_VALUE   = 1 << 6,
     GF_OMP_ATOMIC_WEAK         = 1 << 7,
@@ -2406,7 +2407,7 @@ static inline unsigned
 gimple_omp_subcode (const gimple *s)
 {
   gcc_gimple_checking_assert (gimple_code (s) >= GIMPLE_OMP_ATOMIC_LOAD
-                             && gimple_code (s) <= GIMPLE_OMP_ALLOCATE);
+                             && gimple_code (s) <= GIMPLE_OMP_ORDERED);
   return s->subcode;
 }
 
@@ -2496,6 +2497,27 @@ gimple_omp_section_set_last (gimple *g)
 }
 
 
+/* Return true if OMP ordered construct is stand-alone
+   (G has the GF_OMP_ORDERED_STANDALONE flag set).  */
+
+static inline bool
+gimple_omp_ordered_standalone_p (const gimple *g)
+{
+  GIMPLE_CHECK (g, GIMPLE_OMP_ORDERED);
+  return (gimple_omp_subcode (g) & GF_OMP_ORDERED_STANDALONE) != 0;
+}
+
+
+/* Set the GF_OMP_ORDERED_STANDALONE flag on G.  */
+
+static inline void
+gimple_omp_ordered_standalone (gimple *g)
+{
+  GIMPLE_CHECK (g, GIMPLE_OMP_ORDERED);
+  g->subcode |= GF_OMP_ORDERED_STANDALONE;
+}
+
+
 /* Return true if OMP parallel statement G has the
    GF_OMP_PARALLEL_COMBINED flag set.  */
 
index 493a42eff4f8aa03bab5177eb75ccac281e6fa7f..9382cef4c4767dc111b903cf3b1b52fc402edbc0 100644 (file)
@@ -13150,7 +13150,7 @@ localize_reductions (tree clauses, tree body)
 
 
 /* Helper function of gimplify_omp_for, find OMP_ORDERED with
-   OMP_CLAUSE_DOACROSS clause inside of OMP_FOR's body.  */
+   null OMP_ORDERED_BODY inside of OMP_FOR's body.  */
 
 static tree
 find_standalone_omp_ordered (tree *tp, int *walk_subtrees, void *)
@@ -13158,7 +13158,7 @@ find_standalone_omp_ordered (tree *tp, int *walk_subtrees, void *)
   switch (TREE_CODE (*tp))
     {
     case OMP_ORDERED:
-      if (omp_find_clause (OMP_ORDERED_CLAUSES (*tp), OMP_CLAUSE_DOACROSS))
+      if (OMP_ORDERED_BODY (*tp) == NULL_TREE)
        return *tp;
       break;
     case OMP_SIMD:
@@ -16847,6 +16847,9 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
                break;
              case OMP_ORDERED:
                g = gimplify_omp_ordered (*expr_p, body);
+               if (OMP_BODY (*expr_p) == NULL_TREE
+                   && gimple_code (g) == GIMPLE_OMP_ORDERED)
+                 gimple_omp_ordered_standalone (g);
                break;
              case OMP_MASKED:
                gimplify_scan_omp_clauses (&OMP_MASKED_CLAUSES (*expr_p),
index 48a0c8b634f7949d0393fd5bc58f283f1b424b63..a178ef7126f0826b3775a4c699bbd57d653f8c59 100644 (file)
@@ -10619,8 +10619,7 @@ expand_omp (struct omp_region *region)
          {
            gomp_ordered *ord_stmt
              = as_a <gomp_ordered *> (last_stmt (region->entry));
-           if (omp_find_clause (gimple_omp_ordered_clauses (ord_stmt),
-                                OMP_CLAUSE_DOACROSS))
+           if (gimple_omp_ordered_standalone_p (ord_stmt))
              {
                /* We'll expand these when expanding corresponding
                   worksharing region with ordered(n) clause.  */
@@ -10753,9 +10752,7 @@ build_omp_regions_1 (basic_block bb, struct omp_region *parent,
                }
            }
          else if (code == GIMPLE_OMP_ORDERED
-                  && omp_find_clause (gimple_omp_ordered_clauses
-                                        (as_a <gomp_ordered *> (stmt)),
-                                      OMP_CLAUSE_DOACROSS))
+                  && gimple_omp_ordered_standalone_p (stmt))
            /* #pragma omp ordered depend is also just a stand-alone
               directive.  */
            region = NULL;
@@ -10979,9 +10976,7 @@ omp_make_gimple_edges (basic_block bb, struct omp_region **region,
     case GIMPLE_OMP_ORDERED:
       cur_region = new_omp_region (bb, code, cur_region);
       fallthru = true;
-      if (omp_find_clause (gimple_omp_ordered_clauses
-                            (as_a <gomp_ordered *> (last)),
-                          OMP_CLAUSE_DOACROSS))
+      if (gimple_omp_ordered_standalone_p (last))
        cur_region = cur_region->outer;
       break;
 
index ce114af7518c0cd046cf79076eb8b0499f03761f..da7e262a27cbfd45a3e8025123055b7bf2089b13 100644 (file)
@@ -4197,7 +4197,7 @@ check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx)
                          "a loop region with an %<ordered%> clause");
                return false;
              }
-           if (omp_find_clause (c, OMP_CLAUSE_DOACROSS) == NULL_TREE)
+           if (!gimple_omp_ordered_standalone_p (stmt))
              {
                if (OMP_CLAUSE_ORDERED_DOACROSS (o))
                  {
@@ -10687,8 +10687,7 @@ lower_omp_ordered (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   bool threads = omp_find_clause (gimple_omp_ordered_clauses (ord_stmt),
                                  OMP_CLAUSE_THREADS);
 
-  if (omp_find_clause (gimple_omp_ordered_clauses (ord_stmt),
-                      OMP_CLAUSE_DOACROSS))
+  if (gimple_omp_ordered_standalone_p (ord_stmt))
     {
       /* FIXME: This is needs to be moved to the expansion to verify various
         conditions only testable on cfg with dominators computed, and also
index 0d64c7a6d408f6bf6d876d068c99059e98d011e2..ed42b20b099f02bf9bb26b36d52284f5a11cc30c 100644 (file)
@@ -1,3 +1,12 @@
+2022-09-07  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-09-06  Jakub Jelinek  <jakub@redhat.com>
+
+       * c-c++-common/gomp/sink-3.c: Don't expect a superfluous error during
+       error recovery.
+       * c-c++-common/gomp/doacross-6.c (foo): Add further tests.
+
 2022-09-06  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index b948d07cd22b9ec39cd11152a4b3d1f2dec539ce..65ee8979a4f39803683df58f5970d9f0cb1c4781 100644 (file)
@@ -22,6 +22,18 @@ foo (int n)
     {
       #pragma omp ordered doacross(sink)               /* { dg-error "expected ':' before '\\\)' token" } */
     }
+  #pragma omp for ordered
+  for (i = 0; i < 8; i += n)
+    {
+      #pragma omp ordered doacross(source)             /* { dg-error "expected ':' before '\\\)' token" } */
+      #pragma omp ordered doacross(sink:i-1)
+    }
+  #pragma omp for ordered
+  for (i = 0; i < 8; i += n)
+    {
+      #pragma omp ordered doacross(source:)
+      #pragma omp ordered doacross(sink)               /* { dg-error "expected ':' before '\\\)' token" } */
+    }
 }
 
 void
index 3f7ba5e307db3731b44cf5e7ecc19ef4d37bb359..7cb16ed0f76005024f8ba070bf51ff97568c32b9 100644 (file)
@@ -14,7 +14,7 @@ foo ()
   for (i=0; i < 100; ++i)
     {
 #pragma omp ordered depend(sink:poo-1,paa+1) /* { dg-error "poo.*declared.*paa.*declared" } */
-    bar(&i);                                /* { dg-error "must not have the same binding region" "" { target *-*-* } .-1 } */
+    bar(&i);
 #pragma omp ordered depend(source)
     }
 }