[gcc r14-4907] Disentangle handling of OpenACC 'host', 'self' pragma tokens

Thomas Schwinge tschwinge@gcc.gnu.org
Wed Oct 25 09:07:15 GMT 2023


https://gcc.gnu.org/g:c92509d9fd98e02d17ab1610f696c88f606dcdf4

commit r14-4907-gc92509d9fd98e02d17ab1610f696c88f606dcdf4
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Fri Oct 20 14:47:58 2023 +0200

    Disentangle handling of OpenACC 'host', 'self' pragma tokens
    
    'gcc/c-family/c-pragma.h:pragma_omp_clause' already defines
    'PRAGMA_OACC_CLAUSE_SELF', but it has no longer been used for the 'update'
    directive's 'self' clause as of 2018
    commit 829c6349e96c5bfa8603aaef8858b38e237a2f33 (Subversion r261813)
    "Update OpenACC data clause semantics to the 2.5 behavior".  That one instead
    mapped the 'self' pragma token to the 'host' one (same semantics).  That means
    that we're later not able to tell whether originally we had seen 'self' or
    'host', which was OK as long as only the 'update' directive had a 'self'
    clause.  However, as of recent commit 3a3596389c2e539cb8fd5dc5784a4e2afe193a2a
    "OpenACC 2.7: Implement self clause for compute constructs", also OpenACC
    compute constructs may have a 'self' clause -- with different semantics.  That
    means, we need to know which OpenACC directive we're parsing clauses for, which
    can be done in a simpler way than in that commit, similar to how the OpenMP
    'to' clause is handled.
    
    While at that, clarify that (already in OpenACC 2.0a)
    "The 'host' clause is a synonym for the 'self' clause." -- not the other way
    round.
    
            gcc/c/
            * c-parser.cc (c_parser_omp_clause_name): Return
            'PRAGMA_OACC_CLAUSE_SELF' for "self".
            (c_parser_oacc_data_clause, OACC_UPDATE_CLAUSE_MASK): Adjust.
            (c_parser_oacc_all_clauses): Remove 'bool compute_p' formal
            parameter, and instead locally determine whether we're called for
            an OpenACC compute construct or OpenACC 'update' directive.
            (c_parser_oacc_compute): Adjust.
            gcc/cp/
            * parser.cc (cp_parser_omp_clause_name): Return
            'PRAGMA_OACC_CLAUSE_SELF' for "self".
            (cp_parser_oacc_data_clause, OACC_UPDATE_CLAUSE_MASK): Adjust.
            (cp_parser_oacc_all_clauses): Remove 'bool compute_p' formal
            parameter, and instead locally determine whether we're called for
            an OpenACC compute construct or OpenACC 'update' directive.
            (cp_parser_oacc_compute): Adjust.
            gcc/fortran/
            * openmp.cc (omp_mask2): Split 'OMP_CLAUSE_HOST_SELF' into
            'OMP_CLAUSE_SELF', 'OMP_CLAUSE_HOST'.
            (gfc_match_omp_clauses, OACC_UPDATE_CLAUSES): Adjust.

Diff:
---
 gcc/c/c-parser.cc     | 38 +++++++++++++++++---------------------
 gcc/cp/parser.cc      | 39 +++++++++++++++++----------------------
 gcc/fortran/openmp.cc | 27 ++++++++++++++-------------
 3 files changed, 48 insertions(+), 56 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index a82f5afeff7..5213a57a1ec 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -14061,8 +14061,8 @@ c_parser_omp_clause_name (c_parser *parser)
 	    result = PRAGMA_OMP_CLAUSE_SCHEDULE;
 	  else if (!strcmp ("sections", p))
 	    result = PRAGMA_OMP_CLAUSE_SECTIONS;
-	  else if (!strcmp ("self", p)) /* "self" is a synonym for "host".  */
-	    result = PRAGMA_OACC_CLAUSE_HOST;
+	  else if (!strcmp ("self", p))
+	    result = PRAGMA_OACC_CLAUSE_SELF;
 	  else if (!strcmp ("seq", p))
 	    result = PRAGMA_OACC_CLAUSE_SEQ;
 	  else if (!strcmp ("shared", p))
@@ -14583,9 +14583,6 @@ c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
     case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT:
       kind = GOMP_MAP_DEVICE_RESIDENT;
       break;
-    case PRAGMA_OACC_CLAUSE_HOST:
-      kind = GOMP_MAP_FORCE_FROM;
-      break;
     case PRAGMA_OACC_CLAUSE_LINK:
       kind = GOMP_MAP_LINK;
       break;
@@ -14595,6 +14592,11 @@ c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind,
     case PRAGMA_OACC_CLAUSE_PRESENT:
       kind = GOMP_MAP_FORCE_PRESENT;
       break;
+    case PRAGMA_OACC_CLAUSE_SELF:
+      /* "The 'host' clause is a synonym for the 'self' clause."  */
+    case PRAGMA_OACC_CLAUSE_HOST:
+      kind = GOMP_MAP_FORCE_FROM;
+      break;
     default:
       gcc_unreachable ();
     }
@@ -18083,8 +18085,7 @@ c_parser_omp_clause_detach (c_parser *parser, tree list)
 
 static tree
 c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
-			   const char *where, bool finish_p = true,
-			   bool compute_p = false)
+			   const char *where, bool finish_p = true)
 {
   tree clauses = NULL;
   bool first = true;
@@ -18100,18 +18101,7 @@ c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
 	c_parser_consume_token (parser);
 
       here = c_parser_peek_token (parser)->location;
-
-      /* For OpenACC compute directives */
-      if (compute_p
-	  && c_parser_next_token_is (parser, CPP_NAME)
-	  && !strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value),
-		      "self"))
-	{
-	  c_kind = PRAGMA_OACC_CLAUSE_SELF;
-	  c_parser_consume_token (parser);
-	}
-      else
-	c_kind = c_parser_omp_clause_name (parser);
+      c_kind = c_parser_omp_clause_name (parser);
 
       switch (c_kind)
 	{
@@ -18244,7 +18234,12 @@ c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask,
 	  c_name = "reduction";
 	  break;
 	case PRAGMA_OACC_CLAUSE_SELF:
-	  clauses = c_parser_oacc_compute_clause_self (parser, clauses);
+	  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST)) == 0)
+	    /* OpenACC compute construct */
+	    clauses = c_parser_oacc_compute_clause_self (parser, clauses);
+	  else
+	    /* OpenACC 'update' directive */
+	    clauses = c_parser_oacc_data_clause (parser, c_kind, clauses);
 	  c_name = "self";
 	  break;
 	case PRAGMA_OACC_CLAUSE_SEQ:
@@ -19166,7 +19161,7 @@ c_parser_oacc_compute (location_t loc, c_parser *parser,
 	}
     }
 
-  tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name, true, true);
+  tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name);
 
   tree block = c_begin_omp_parallel ();
   add_stmt (c_parser_omp_structured_block (parser, if_p));
@@ -19366,6 +19361,7 @@ c_finish_oacc_routine (struct oacc_routine_data *data, tree fndecl,
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST)		\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF_PRESENT)		\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF)		\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
 
 static void
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index c5a9928ad27..5a6c416d932 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -37566,8 +37566,8 @@ cp_parser_omp_clause_name (cp_parser *parser)
 	    result = PRAGMA_OMP_CLAUSE_SCHEDULE;
 	  else if (!strcmp ("sections", p))
 	    result = PRAGMA_OMP_CLAUSE_SECTIONS;
-	  else if (!strcmp ("self", p)) /* "self" is a synonym for "host".  */
-	    result = PRAGMA_OACC_CLAUSE_HOST;
+	  else if (!strcmp ("self", p))
+	    result = PRAGMA_OACC_CLAUSE_SELF;
 	  else if (!strcmp ("seq", p))
 	    result = PRAGMA_OACC_CLAUSE_SEQ;
 	  else if (!strcmp ("shared", p))
@@ -38004,9 +38004,6 @@ cp_parser_oacc_data_clause (cp_parser *parser, pragma_omp_clause c_kind,
     case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT:
       kind = GOMP_MAP_DEVICE_RESIDENT;
       break;
-    case PRAGMA_OACC_CLAUSE_HOST:
-      kind = GOMP_MAP_FORCE_FROM;
-      break;
     case PRAGMA_OACC_CLAUSE_LINK:
       kind = GOMP_MAP_LINK;
       break;
@@ -38016,6 +38013,11 @@ cp_parser_oacc_data_clause (cp_parser *parser, pragma_omp_clause c_kind,
     case PRAGMA_OACC_CLAUSE_PRESENT:
       kind = GOMP_MAP_FORCE_PRESENT;
       break;
+    case PRAGMA_OACC_CLAUSE_SELF:
+      /* "The 'host' clause is a synonym for the 'self' clause."  */
+    case PRAGMA_OACC_CLAUSE_HOST:
+      kind = GOMP_MAP_FORCE_FROM;
+      break;
     default:
       gcc_unreachable ();
     }
@@ -41236,7 +41238,7 @@ cp_parser_oacc_compute_clause_self (cp_parser *parser, tree list)
 static tree
 cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask,
 			    const char *where, cp_token *pragma_tok,
-			    bool finish_p = true, bool compute_p = false)
+			    bool finish_p = true)
 {
   tree clauses = NULL;
   bool first = true;
@@ -41256,19 +41258,7 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask,
 	cp_lexer_consume_token (parser->lexer);
 
       here = cp_lexer_peek_token (parser->lexer)->location;
-
-      /* For OpenACC compute directives */
-      if (compute_p
-	  && cp_lexer_next_token_is (parser->lexer, CPP_NAME)
-	  && !strcmp (IDENTIFIER_POINTER
-		      (cp_lexer_peek_token (parser->lexer)->u.value),
-		      "self"))
-	{
-	  c_kind = PRAGMA_OACC_CLAUSE_SELF;
-	  cp_lexer_consume_token (parser->lexer);
-	}
-      else
-	c_kind = cp_parser_omp_clause_name (parser);
+      c_kind = cp_parser_omp_clause_name (parser);
 
       switch (c_kind)
 	{
@@ -41403,7 +41393,12 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask,
 	  c_name = "reduction";
 	  break;
 	case PRAGMA_OACC_CLAUSE_SELF:
-	  clauses = cp_parser_oacc_compute_clause_self (parser, clauses);
+	  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST)) == 0)
+	    /* OpenACC compute construct */
+	    clauses = cp_parser_oacc_compute_clause_self (parser, clauses);
+	  else
+	    /* OpenACC 'update' directive */
+	    clauses = cp_parser_oacc_data_clause (parser, c_kind, clauses);
 	  c_name = "self";
 	  break;
 	case PRAGMA_OACC_CLAUSE_SEQ:
@@ -47006,8 +47001,7 @@ cp_parser_oacc_compute (cp_parser *parser, cp_token *pragma_tok,
 	}
     }
 
-  tree clauses = cp_parser_oacc_all_clauses (parser, mask, p_name, pragma_tok,
-					     true, true);
+  tree clauses = cp_parser_oacc_all_clauses (parser, mask, p_name, pragma_tok);
 
   tree block = begin_omp_parallel ();
   unsigned int save = cp_parser_begin_omp_structured_block (parser);
@@ -47026,6 +47020,7 @@ cp_parser_oacc_compute (cp_parser *parser, cp_token *pragma_tok,
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST)		\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF)			\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF_PRESENT)		\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF)		\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT))
 
 static tree
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 083c15e5599..2e2e23d567b 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -1080,7 +1080,8 @@ enum omp_mask2
   OMP_CLAUSE_INDEPENDENT,
   OMP_CLAUSE_USE_DEVICE,
   OMP_CLAUSE_DEVICE_RESIDENT,
-  OMP_CLAUSE_HOST_SELF,
+  OMP_CLAUSE_SELF,
+  OMP_CLAUSE_HOST,
   OMP_CLAUSE_WAIT,
   OMP_CLAUSE_DELETE,
   OMP_CLAUSE_AUTO,
@@ -1094,7 +1095,6 @@ enum omp_mask2
   OMP_CLAUSE_DOACROSS, /* OpenMP 5.2 */
   OMP_CLAUSE_ASSUMPTIONS, /* OpenMP 5.1. */
   OMP_CLAUSE_USES_ALLOCATORS, /* OpenMP 5.0  */
-  OMP_CLAUSE_SELF, /* OpenACC 2.7  */
   /* This must come last.  */
   OMP_MASK2_LAST
 };
@@ -1877,8 +1877,7 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
      that should work.  */
   bool allow_derived = (openacc
 			&& ((mask & OMP_CLAUSE_ATTACH)
-			    || (mask & OMP_CLAUSE_DETACH)
-			    || (mask & OMP_CLAUSE_HOST_SELF)));
+			    || (mask & OMP_CLAUSE_DETACH)));
 
   gcc_checking_assert (OMP_MASK1_LAST <= 64 && OMP_MASK2_LAST <= 64);
   *cp = NULL;
@@ -2550,7 +2549,7 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 	      && gfc_match ("device ( ") == MATCH_YES
 	      && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
 					   OMP_MAP_FORCE_TO, true,
-					   allow_derived))
+					   /* allow_derived = */ true))
 	    continue;
 	  if ((mask & OMP_CLAUSE_DEVICEPTR)
 	      && gfc_match ("deviceptr ( ") == MATCH_YES
@@ -2725,11 +2724,11 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 	      c->assume->holds = el;
 	      continue;
 	    }
-	  if ((mask & OMP_CLAUSE_HOST_SELF)
+	  if ((mask & OMP_CLAUSE_HOST)
 	      && gfc_match ("host ( ") == MATCH_YES
 	      && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
 					   OMP_MAP_FORCE_FROM, true,
-					   allow_derived))
+					   /* allow_derived = */ true))
 	    continue;
 	  break;
 	case 'i':
@@ -3521,10 +3520,10 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 		gfc_current_locus = old_loc;
 	    }
 	  if ((mask & OMP_CLAUSE_SELF)
+	      && !(mask & OMP_CLAUSE_HOST) /* OpenACC compute construct */
 	      && (m = gfc_match_dupl_check (!c->self_expr, "self"))
 	          != MATCH_NO)
 	    {
-	      gcc_assert (!(mask & OMP_CLAUSE_HOST_SELF));
 	      if (m == MATCH_ERROR)
 		goto error;
 	      m = gfc_match (" ( %e )", &c->self_expr);
@@ -3541,11 +3540,12 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 		}
 	      continue;
 	    }
-	  if ((mask & OMP_CLAUSE_HOST_SELF)
+	  if ((mask & OMP_CLAUSE_SELF)
+	      && (mask & OMP_CLAUSE_HOST) /* OpenACC 'update' directive */
 	      && gfc_match ("self ( ") == MATCH_YES
 	      && gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
 					   OMP_MAP_FORCE_FROM, true,
-					   allow_derived))
+					   /* allow_derived = */ true))
 	    continue;
 	  if ((mask & OMP_CLAUSE_SEQ)
 	      && (m = gfc_match_dupl_check (!c->seq, "seq")) != MATCH_NO)
@@ -3854,9 +3854,10 @@ error:
    | OMP_CLAUSE_CREATE | OMP_CLAUSE_DEVICEPTR | OMP_CLAUSE_DEVICE_RESIDENT    \
    | OMP_CLAUSE_PRESENT			      \
    | OMP_CLAUSE_LINK)
-#define OACC_UPDATE_CLAUSES \
-  (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_ASYNC | OMP_CLAUSE_HOST_SELF	      \
-   | OMP_CLAUSE_DEVICE | OMP_CLAUSE_WAIT | OMP_CLAUSE_IF_PRESENT)
+#define OACC_UPDATE_CLAUSES						\
+  (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_ASYNC | OMP_CLAUSE_HOST	      \
+   | OMP_CLAUSE_DEVICE | OMP_CLAUSE_WAIT | OMP_CLAUSE_IF_PRESENT	      \
+   | OMP_CLAUSE_SELF)
 #define OACC_ENTER_DATA_CLAUSES \
   (omp_mask (OMP_CLAUSE_IF) | OMP_CLAUSE_ASYNC | OMP_CLAUSE_WAIT	      \
    | OMP_CLAUSE_COPYIN | OMP_CLAUSE_CREATE | OMP_CLAUSE_ATTACH)


More information about the Gcc-cvs mailing list