[gcc r14-6718] OpenMP: Unify representation of name-list properties.

Sandra Loosemore sandra@gcc.gnu.org
Tue Dec 19 20:07:43 GMT 2023


https://gcc.gnu.org/g:9b8fdcbf2105c65de231ea3db10aaf38e3f68530

commit r14-6718-g9b8fdcbf2105c65de231ea3db10aaf38e3f68530
Author: Sandra Loosemore <sandra@codesourcery.com>
Date:   Sun Nov 19 05:31:41 2023 +0000

    OpenMP: Unify representation of name-list properties.
    
    Previously, name-list properties specified as identifiers were stored
    in the TREE_PURPOSE/OMP_TP_NAME slot, while those specified as strings
    were stored in the TREE_VALUE/OMP_TP_VALUE slot.  This patch puts both
    representations in OMP_TP_VALUE with a magic cookie in OMP_TP_NAME.
    
    gcc/ChangeLog
            * omp-general.h (OMP_TP_NAMELIST_NODE): New.
            * omp-general.cc (omp_context_name_list_prop): Move earlier
            in the file, and adjust for new representation.
            (omp_check_context_selector): Adjust this too.
            (omp_context_selector_props_compare): Likewise.
    
    gcc/c/ChangeLog
            * c-parser.cc (c_parser_omp_context_selector): Adjust for new
            namelist property representation.
    
    gcc/cp/ChangeLog
            * parser.cc (cp_parser_omp_context_selector): Adjust for new
            namelist property representation.
            * pt.cc (tsubst_attribute): Likewise.
    
    gcc/fortran/ChangeLog
            * trans-openmp.cc (gfc_trans_omp_declare_varaint): Adjust for
            new namelist property representation.

Diff:
---
 gcc/c/c-parser.cc           |  5 +--
 gcc/cp/parser.cc            |  5 +--
 gcc/cp/pt.cc                |  4 ++-
 gcc/fortran/trans-openmp.cc |  5 +--
 gcc/omp-general.cc          | 84 ++++++++++++++++++++++++++-------------------
 gcc/omp-general.h           |  1 +
 6 files changed, 61 insertions(+), 43 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index a61381e887f..b5bed5ee276 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -24571,11 +24571,12 @@ c_parser_omp_context_selector (c_parser *parser, tree set, tree parms)
 	    case CTX_PROPERTY_NAME_LIST:
 	      do
 		{
-		  tree prop = NULL_TREE, value = NULL_TREE;
+		  tree prop = OMP_TP_NAMELIST_NODE;
+		  tree value = NULL_TREE;
 		  if (c_parser_next_token_is (parser, CPP_KEYWORD)
 		      || c_parser_next_token_is (parser, CPP_NAME))
 		    {
-		      prop = c_parser_peek_token (parser)->value;
+		      value = c_parser_peek_token (parser)->value;
 		      c_parser_consume_token (parser);
 		    }
 		  else if (c_parser_next_token_is (parser, CPP_STRING))
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 5a916374ccf..3250b0bda6d 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -47630,11 +47630,12 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
 	    case CTX_PROPERTY_NAME_LIST:
 	      do
 		{
-		  tree prop = NULL_TREE, value = NULL_TREE;
+		  tree prop = OMP_TP_NAMELIST_NODE;
+		  tree value = NULL_TREE;
 		  if (cp_lexer_next_token_is (parser->lexer, CPP_KEYWORD)
 		      || cp_lexer_next_token_is (parser->lexer, CPP_NAME))
 		    {
-		      prop = cp_lexer_peek_token (parser->lexer)->u.value;
+		      value = cp_lexer_peek_token (parser->lexer)->u.value;
 		      cp_lexer_consume_token (parser->lexer);
 		    }
 		  else if (cp_lexer_next_token_is (parser->lexer, CPP_STRING))
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index a752dcf76b8..ef280e417d4 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -11939,7 +11939,9 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
 		    }
 		  properties = copy_list (OMP_TS_PROPERTIES (ts));
 		  for (tree p = properties; p; p = TREE_CHAIN (p))
-		    if (OMP_TP_VALUE (p))
+		    if (OMP_TP_NAME (p) == OMP_TP_NAMELIST_NODE)
+		      continue;
+		    else if (OMP_TP_VALUE (p))
 		      {
 			bool allow_string
 			  = (OMP_TS_ID (ts) != condition || set[0] != 'u');
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index 55f85d582b5..93f75162a2a 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -8428,9 +8428,10 @@ gfc_trans_omp_declare_variant (gfc_namespace *ns)
 		      break;
 		    case CTX_PROPERTY_NAME_LIST:
 		      {
-			tree prop = NULL_TREE, value = NULL_TREE;
+			tree prop = OMP_TP_NAMELIST_NODE;
+			tree value = NULL_TREE;
 			if (otp->is_name)
-			  prop = get_identifier (otp->name);
+			  value = get_identifier (otp->name);
 			else
 			  value = gfc_conv_constant_to_tree (otp->expr);
 
diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index c95873b5524..285bc788836 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1116,6 +1116,30 @@ omp_maybe_offloaded (void)
   return false;
 }
 
+/* Return a name from PROP, a property in selectors accepting
+   name lists.  */
+
+static const char *
+omp_context_name_list_prop (tree prop)
+{
+  gcc_assert (OMP_TP_NAME (prop) == OMP_TP_NAMELIST_NODE);
+  tree val = OMP_TP_VALUE (prop);
+  switch (TREE_CODE (val))
+    {
+    case IDENTIFIER_NODE:
+      return IDENTIFIER_POINTER (val);
+    case STRING_CST:
+      {
+	const char *ret = TREE_STRING_POINTER (val);
+	if ((size_t) TREE_STRING_LENGTH (val)
+	    == strlen (ret) + (lang_GNU_Fortran () ? 0 : 1))
+	  return ret;
+	return NULL;
+      }
+    default:
+      return NULL;
+    }
+}
 
 /* Diagnose errors in an OpenMP context selector, return CTX if
    it is correct or error_mark_node otherwise.  */
@@ -1200,23 +1224,29 @@ omp_check_context_selector (location_t loc, tree ctx)
 				    "atomic_default_mem_order");
 			  return error_mark_node;
 			}
+		      else if (OMP_TP_NAME (p) == OMP_TP_NAMELIST_NODE
+			       && (TREE_CODE (OMP_TP_VALUE (p)) == STRING_CST))
+			warning_at (loc, 0,
+				    "unknown property %qE of %qs selector",
+				    OMP_TP_VALUE (p),
+				    props[i].selector);
+		      else if (OMP_TP_NAME (p) == OMP_TP_NAMELIST_NODE)
+			warning_at (loc, 0,
+				    "unknown property %qs of %qs selector",
+				    omp_context_name_list_prop (p),
+				    props[i].selector);
 		      else if (OMP_TP_NAME (p))
 			warning_at (loc, OPT_Wopenmp,
 				    "unknown property %qs of %qs selector",
 				    IDENTIFIER_POINTER (OMP_TP_NAME (p)),
 				    props[i].selector);
-		      else
-			warning_at (loc, OPT_Wopenmp,
-				    "unknown property %qE of %qs selector",
-				    OMP_TP_VALUE (p), props[i].selector);
 		      break;
 		    }
-		  else if (OMP_TP_NAME (p) == NULL_TREE)
+		  else if (OMP_TP_NAME (p) == OMP_TP_NAMELIST_NODE)
+		    /* Property-list traits.  */
 		    {
-		      const char *str = TREE_STRING_POINTER (OMP_TP_VALUE (p));
-		      if (!strcmp (str, props[i].props[j])
-			  && ((size_t) TREE_STRING_LENGTH (OMP_TP_VALUE (p))
-			      == strlen (str) + (lang_GNU_Fortran () ? 0 : 1)))
+		      const char *str = omp_context_name_list_prop (p);
+		      if (str && !strcmp (str, props[i].props[j]))
 			break;
 		    }
 		  else if (!strcmp (IDENTIFIER_POINTER (OMP_TP_NAME (p)),
@@ -1279,24 +1309,6 @@ make_trait_property (tree name, tree value, tree chain)
   return tree_cons (name, value, chain);
 }
 
-/* Return a name from PROP, a property in selectors accepting
-   name lists.  */
-
-static const char *
-omp_context_name_list_prop (tree prop)
-{
-  if (OMP_TP_NAME (prop))
-    return IDENTIFIER_POINTER (OMP_TP_NAME (prop));
-  else
-    {
-      const char *ret = TREE_STRING_POINTER (OMP_TP_VALUE (prop));
-      if ((size_t) TREE_STRING_LENGTH (OMP_TP_VALUE (prop))
-	  == strlen (ret) + (lang_GNU_Fortran () ? 0 : 1))
-	return ret;
-      return NULL;
-    }
-}
-
 /* Return 1 if context selector matches the current OpenMP context, 0
    if it does not and -1 if it is unknown and need to be determined later.
    Some properties can be checked right away during parsing (this routine),
@@ -1795,18 +1807,18 @@ omp_context_selector_props_compare (const char *set, const char *sel,
 		  if (simple_cst_equal (OMP_TP_VALUE (p1), OMP_TP_VALUE (p2)))
 		    break;
 		}
+	      else if (OMP_TP_NAME (p1) == OMP_TP_NAMELIST_NODE)
+		{
+		  /* Handle string constant vs identifier comparison for
+		     name-list properties.  */
+		  const char *n1 = omp_context_name_list_prop (p1);
+		  const char *n2 = omp_context_name_list_prop (p2);
+		  if (n1 && n2 && !strcmp (n1, n2))
+		    break;
+		}
 	      else
 		break;
 	    }
-	  else
-	    {
-	      /* Handle string constant vs identifier comparison for
-		 name-list properties.  */
-	      const char *n1 = omp_context_name_list_prop (p1);
-	      const char *n2 = omp_context_name_list_prop (p2);
-	      if (n1 && n2 && !strcmp (n1, n2))
-		break;
-	    }
 	if (p2 == NULL_TREE)
 	  {
 	    int r = pass ? -1 : 1;
diff --git a/gcc/omp-general.h b/gcc/omp-general.h
index 4bd187bd860..40ede66568b 100644
--- a/gcc/omp-general.h
+++ b/gcc/omp-general.h
@@ -112,6 +112,7 @@ struct omp_for_data
    OMP_TS_SCORE_NODE.  */
 
 #define OMP_TS_SCORE_NODE integer_minus_one_node
+#define OMP_TP_NAMELIST_NODE integer_one_node
 
 #define OMP_TSS_ID(NODE) \
   TREE_PURPOSE (NODE)


More information about the Gcc-cvs mailing list