public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: gcc-patches@gcc.gnu.org, Tobias Burnus <tobias@codesourcery.com>
Subject: [PATCH] openmp: Introduce gimple_omp_ordered_standalone_p
Date: Mon, 5 Sep 2022 14:28:53 +0200	[thread overview]
Message-ID: <YxXrhR0b1sGePltD@tucnak> (raw)
In-Reply-To: <YxMLPflR4I4wvkU+@tucnak>

Hi!

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.

Will commit if it passes full bootstrap/regtest on x86_64-linux and
i686-linux overnight.

2022-09-05  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.

--- gcc/gimple.h.jj	2022-06-27 11:18:02.682058403 +0200
+++ gcc/gimple.h	2022-09-05 13:47:21.009761168 +0200
@@ -194,6 +194,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,
@@ -2312,7 +2313,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_TEAMS);
+			      && gimple_code (s) <= GIMPLE_OMP_ORDERED);
   return s->subcode;
 }
 
@@ -2402,6 +2403,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.  */
 
--- gcc/gimplify.cc.jj	2022-09-03 09:41:34.823006434 +0200
+++ gcc/gimplify.cc	2022-09-05 13:37:00.158143869 +0200
@@ -12427,7 +12427,7 @@ gimplify_omp_taskloop_expr (tree type, t
 }
 
 /* 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 *)
@@ -12435,7 +12435,7 @@ find_standalone_omp_ordered (tree *tp, i
   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:
@@ -15839,6 +15839,9 @@ gimplify_expr (tree *expr_p, gimple_seq
 		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),
--- gcc/omp-low.cc.jj	2022-09-03 09:41:34.827006378 +0200
+++ gcc/omp-low.cc	2022-09-05 13:24:30.796236971 +0200
@@ -3718,7 +3718,7 @@ check_omp_nesting_restrictions (gimple *
 			  "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))
 		  {
@@ -9989,8 +9989,7 @@ lower_omp_ordered (gimple_stmt_iterator
   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
--- gcc/omp-expand.cc.jj	2022-09-03 09:41:34.829006350 +0200
+++ gcc/omp-expand.cc	2022-09-05 13:25:39.328317824 +0200
@@ -10487,8 +10487,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.  */
@@ -10616,9 +10615,7 @@ build_omp_regions_1 (basic_block bb, str
 		}
 	    }
 	  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;
@@ -10842,9 +10839,7 @@ omp_make_gimple_edges (basic_block bb, s
     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;
 
--- gcc/cp/pt.cc.jj	2022-09-03 09:41:34.866005829 +0200
+++ gcc/cp/pt.cc	2022-09-05 14:16:25.584362892 +0200
@@ -19526,9 +19526,14 @@ tsubst_expr (tree t, tree args, tsubst_f
     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;
--- gcc/testsuite/c-c++-common/gomp/sink-3.c.jj	2022-09-03 09:41:34.928004956 +0200
+++ gcc/testsuite/c-c++-common/gomp/sink-3.c	2022-09-05 14:07:04.580887813 +0200
@@ -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)
     }
 }
--- gcc/testsuite/c-c++-common/gomp/doacross-6.c.jj	2022-09-03 09:41:34.914005153 +0200
+++ gcc/testsuite/c-c++-common/gomp/doacross-6.c	2022-09-05 13:34:20.545312759 +0200
@@ -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


	Jakub


  reply	other threads:[~2022-09-05 12:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-03  8:07 [committed] openmp: Partial OpenMP 5.2 doacross and omp_cur_iteration support Jakub Jelinek
2022-09-05 12:28 ` Jakub Jelinek [this message]
2022-09-05 13:01 ` Tobias Burnus
2022-09-05 16:00   ` Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YxXrhR0b1sGePltD@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=tobias@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).