public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/omp/gcc-12] openmp: Add support for enter clause on declare target
@ 2022-07-05  8:10 Tobias Burnus
  0 siblings, 0 replies; only message in thread
From: Tobias Burnus @ 2022-07-05  8:10 UTC (permalink / raw)
  To: gcc-cvs

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

commit d23aea91c1c5b4aea2af90634cf653cf7f12d720
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Jul 5 09:27:36 2022 +0200

    openmp: Add support for enter clause on declare target
    
    OpenMP 5.1 and earlier had 2 different uses of to clause, one for target
    update construct with one semantics, and one for declare target directive
    with a different semantics.
    Under the hood we were using OMP_CLAUSE_TO_DECLARE to represent the latter.
    OpenMP 5.2 renamed the declare target clause to to enter, the old one is
    kept as a deprecated alias.
    
    As we are far from having full OpenMP 5.2 support, this patch adds support
    for the enter clause (and renames OMP_CLAUSE_TO_DECLARE to OMP_CLAUSE_ENTER
    with a flag to tell the spelling of the clause for better diagnostics),
    but doesn't deprecate the to clause on declare target just yet (that
    should be done as one of the last steps in 5.2 support).
    
    2022-05-27  Jakub Jelinek  <jakub@redhat.com>
    
    gcc/
            * tree-core.h (enum omp_clause_code): Rename OMP_CLAUSE_TO_DECLARE
            to OMP_CLAUSE_ENTER.
            * tree.h (OMP_CLAUSE_ENTER_TO): Define.
            * tree.cc (omp_clause_num_ops, omp_clause_code_name): Rename
            OMP_CLAUSE_TO_DECLARE to OMP_CLAUSE_ENTER.
            * tree-pretty-print.cc (dump_omp_clause): Handle OMP_CLAUSE_ENTER
            instead of OMP_CLAUSE_TO_DECLARE, if OMP_CLAUSE_ENTER_TO, print
            "to" instead of "enter".
            * tree-nested.cc (convert_nonlocal_omp_clauses,
            convert_local_omp_clauses): Handle OMP_CLAUSE_ENTER instead of
            OMP_CLAUSE_TO_DECLARE.
    gcc/c-family/
            * c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_ENTER.
    gcc/c/
            * c-parser.cc (c_parser_omp_clause_name): Parse enter clause.
            (c_parser_omp_all_clauses): For to clause on declare target, use
            OMP_CLAUSE_ENTER clause with OMP_CLAUSE_ENTER_TO instead of
            OMP_CLAUSE_TO_DECLARE clause.  Handle PRAGMA_OMP_CLAUSE_ENTER.
            (OMP_DECLARE_TARGET_CLAUSE_MASK): Add enter clause.
            (c_parser_omp_declare_target): Use OMP_CLAUSE_ENTER instead of
            OMP_CLAUSE_TO_DECLARE.
            * c-typeck.cc (c_finish_omp_clauses): Handle OMP_CLAUSE_ENTER instead
            of OMP_CLAUSE_TO_DECLARE, to OMP_CLAUSE_ENTER_TO use "to" as clause
            name in diagnostics instead of
            omp_clause_code_name[OMP_CLAUSE_CODE (c)].
    gcc/cp/
            * parser.cc (cp_parser_omp_clause_name): Parse enter clause.
            (cp_parser_omp_all_clauses): For to clause on declare target, use
            OMP_CLAUSE_ENTER clause with OMP_CLAUSE_ENTER_TO instead of
            OMP_CLAUSE_TO_DECLARE clause.  Handle PRAGMA_OMP_CLAUSE_ENTER.
            (OMP_DECLARE_TARGET_CLAUSE_MASK): Add enter clause.
            (cp_parser_omp_declare_target): Use OMP_CLAUSE_ENTER instead of
            OMP_CLAUSE_TO_DECLARE.
            * semantics.cc (finish_omp_clauses): Handle OMP_CLAUSE_ENTER instead
            of OMP_CLAUSE_TO_DECLARE, to OMP_CLAUSE_ENTER_TO use "to" as clause
            name in diagnostics instead of
            omp_clause_code_name[OMP_CLAUSE_CODE (c)].
    gcc/testsuite/
            * c-c++-common/gomp/clauses-3.c: Add tests with enter clause instead
            of to or modify some existing to clauses to enter.
            * c-c++-common/gomp/declare-target-1.c: Likewise.
            * c-c++-common/gomp/declare-target-2.c: Likewise.
            * c-c++-common/gomp/declare-target-3.c: Likewise.
            * g++.dg/gomp/attrs-9.C: Likewise.
            * g++.dg/gomp/declare-target-1.C: Likewise.
    libgomp/
            * testsuite/libgomp.c-c++-common/target-40.c: Modify some existing to
            clauses to enter.
            * testsuite/libgomp.c/target-41.c: Likewise.
    
    (cherry picked from commit 0ccba4ed8571c18c7015413441e971d4863c3644)

Diff:
---
 gcc/ChangeLog.omp                                  | 17 ++++++++++++++
 gcc/c-family/ChangeLog.omp                         |  7 ++++++
 gcc/c-family/c-pragma.h                            |  3 ++-
 gcc/c/ChangeLog.omp                                | 17 ++++++++++++++
 gcc/c/c-parser.cc                                  | 23 +++++++++++++++----
 gcc/c/c-typeck.cc                                  | 21 +++++++++--------
 gcc/cp/ChangeLog.omp                               | 17 ++++++++++++++
 gcc/cp/parser.cc                                   | 21 ++++++++++++++---
 gcc/cp/semantics.cc                                | 26 ++++++++++++----------
 gcc/testsuite/ChangeLog.omp                        | 13 +++++++++++
 gcc/testsuite/c-c++-common/gomp/clauses-3.c        |  4 +++-
 gcc/testsuite/c-c++-common/gomp/declare-target-1.c |  2 +-
 gcc/testsuite/c-c++-common/gomp/declare-target-2.c |  5 +++++
 gcc/testsuite/c-c++-common/gomp/declare-target-3.c |  3 +++
 gcc/testsuite/g++.dg/gomp/attrs-9.C                |  4 ++--
 gcc/testsuite/g++.dg/gomp/declare-target-1.C       |  5 +++++
 gcc/tree-core.h                                    |  6 ++---
 gcc/tree-nested.cc                                 |  4 ++--
 gcc/tree-pretty-print.cc                           |  7 ++++--
 gcc/tree.cc                                        |  4 ++--
 gcc/tree.h                                         |  4 ++++
 libgomp/ChangeLog.omp                              |  9 ++++++++
 libgomp/testsuite/libgomp.c-c++-common/target-40.c |  2 +-
 libgomp/testsuite/libgomp.c/target-41.c            |  2 +-
 24 files changed, 182 insertions(+), 44 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 9ae5b92172c..21bfd6c79a3 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,20 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backport from mainline:
+	2022-05-27  Jakub Jelinek  <jakub@redhat.com>
+
+	* tree-core.h (enum omp_clause_code): Rename OMP_CLAUSE_TO_DECLARE
+	to OMP_CLAUSE_ENTER.
+	* tree.h (OMP_CLAUSE_ENTER_TO): Define.
+	* tree.cc (omp_clause_num_ops, omp_clause_code_name): Rename
+	OMP_CLAUSE_TO_DECLARE to OMP_CLAUSE_ENTER.
+	* tree-pretty-print.cc (dump_omp_clause): Handle OMP_CLAUSE_ENTER
+	instead of OMP_CLAUSE_TO_DECLARE, if OMP_CLAUSE_ENTER_TO, print
+	"to" instead of "enter".
+	* tree-nested.cc (convert_nonlocal_omp_clauses,
+	convert_local_omp_clauses): Handle OMP_CLAUSE_ENTER instead of
+	OMP_CLAUSE_TO_DECLARE.
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backport from mainline:
diff --git a/gcc/c-family/ChangeLog.omp b/gcc/c-family/ChangeLog.omp
index f4d2dce3f45..9bdb0dbf407 100644
--- a/gcc/c-family/ChangeLog.omp
+++ b/gcc/c-family/ChangeLog.omp
@@ -1,3 +1,10 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backport from mainline:
+	2022-05-27  Jakub Jelinek  <jakub@redhat.com>
+
+	* c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_ENTER.
+
 2022-07-04  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backport from mainline:
diff --git a/gcc/c-family/c-pragma.h b/gcc/c-family/c-pragma.h
index 35893dc260e..f929e6a5258 100644
--- a/gcc/c-family/c-pragma.h
+++ b/gcc/c-family/c-pragma.h
@@ -91,7 +91,7 @@ enum pragma_kind {
 
 
 /* All clauses defined by OpenACC 2.0, and OpenMP 2.5, 3.0, 3.1, 4.0, 4.5, 5.0,
-   and 5.1.  Used internally by both C and C++ parsers.  */
+   5.1 and 5.2.  Used internally by both C and C++ parsers.  */
 enum pragma_omp_clause {
   PRAGMA_OMP_CLAUSE_NONE = 0,
 
@@ -109,6 +109,7 @@ enum pragma_omp_clause {
   PRAGMA_OMP_CLAUSE_DEVICE,
   PRAGMA_OMP_CLAUSE_DEVICE_TYPE,
   PRAGMA_OMP_CLAUSE_DIST_SCHEDULE,
+  PRAGMA_OMP_CLAUSE_ENTER,
   PRAGMA_OMP_CLAUSE_FILTER,
   PRAGMA_OMP_CLAUSE_FINAL,
   PRAGMA_OMP_CLAUSE_FIRSTPRIVATE,
diff --git a/gcc/c/ChangeLog.omp b/gcc/c/ChangeLog.omp
index 2cca133beb3..9deef6d31b5 100644
--- a/gcc/c/ChangeLog.omp
+++ b/gcc/c/ChangeLog.omp
@@ -1,3 +1,20 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backport from mainline:
+	2022-05-27  Jakub Jelinek  <jakub@redhat.com>
+
+	* c-parser.cc (c_parser_omp_clause_name): Parse enter clause.
+	(c_parser_omp_all_clauses): For to clause on declare target, use
+	OMP_CLAUSE_ENTER clause with OMP_CLAUSE_ENTER_TO instead of
+	OMP_CLAUSE_TO_DECLARE clause.  Handle PRAGMA_OMP_CLAUSE_ENTER.
+	(OMP_DECLARE_TARGET_CLAUSE_MASK): Add enter clause.
+	(c_parser_omp_declare_target): Use OMP_CLAUSE_ENTER instead of
+	OMP_CLAUSE_TO_DECLARE.
+	* c-typeck.cc (c_finish_omp_clauses): Handle OMP_CLAUSE_ENTER instead
+	of OMP_CLAUSE_TO_DECLARE, to OMP_CLAUSE_ENTER_TO use "to" as clause
+	name in diagnostics instead of
+	omp_clause_code_name[OMP_CLAUSE_CODE (c)].
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backport from mainline:
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index d9489c298f8..44f222800b7 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -12792,6 +12792,10 @@ c_parser_omp_clause_name (c_parser *parser)
 	  else if (!strcmp ("dist_schedule", p))
 	    result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
 	  break;
+	case 'e':
+	  if (!strcmp ("enter", p))
+	    result = PRAGMA_OMP_CLAUSE_ENTER;
+	  break;
 	case 'f':
 	  if (!strcmp ("filter", p))
 	    result = PRAGMA_OMP_CLAUSE_FILTER;
@@ -17292,9 +17296,13 @@ c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask,
 	  break;
 	case PRAGMA_OMP_CLAUSE_TO:
 	  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) != 0)
-	    clauses
-	      = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE,
-					      clauses);
+	    {
+	      tree nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ENTER,
+						      clauses);
+	      for (tree c = nl; c != clauses; c = OMP_CLAUSE_CHAIN (c))
+		OMP_CLAUSE_ENTER_TO (c) = 1;
+	      clauses = nl;
+	    }
 	  else
 	    clauses = c_parser_omp_clause_to (parser, clauses);
 	  c_name = "to";
@@ -17399,6 +17407,12 @@ c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask,
 					       clauses);
 	  c_name = "simd";
 	  break;
+	case PRAGMA_OMP_CLAUSE_ENTER:
+	  clauses
+	    = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ENTER,
+					    clauses);
+	  c_name = "enter";
+	  break;
 	default:
 	  c_parser_error (parser, "expected %<#pragma omp%> clause");
 	  goto saw_error;
@@ -22298,6 +22312,7 @@ c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
 
 #define OMP_DECLARE_TARGET_CLAUSE_MASK				\
 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO)		\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ENTER)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)		\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE_TYPE))
 
@@ -22312,7 +22327,7 @@ c_parser_omp_declare_target (c_parser *parser)
 					"#pragma omp declare target");
   else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
     {
-      clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE,
+      clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ENTER,
 					      clauses);
       clauses = c_finish_omp_clauses (clauses, C_ORT_OMP);
       c_parser_skip_to_pragma_eol (parser);
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 6c42716f105..4623b9d392f 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -15430,37 +15430,40 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 	    }
 	  break;
 
-	case OMP_CLAUSE_TO_DECLARE:
+	case OMP_CLAUSE_ENTER:
 	case OMP_CLAUSE_LINK:
 	  t = OMP_CLAUSE_DECL (c);
+	  const char *cname;
+	  cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
+	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
+	      && OMP_CLAUSE_ENTER_TO (c))
+	    cname = "to";
 	  if (TREE_CODE (t) == FUNCTION_DECL
-	      && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE)
+	      && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
 	    ;
 	  else if (!VAR_P (t))
 	    {
-	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE)
+	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
 		error_at (OMP_CLAUSE_LOCATION (c),
 			  "%qE is neither a variable nor a function name in "
-			  "clause %qs", t,
-			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+			  "clause %qs", t, cname);
 	      else
 		error_at (OMP_CLAUSE_LOCATION (c),
-			  "%qE is not a variable in clause %qs", t,
-			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+			  "%qE is not a variable in clause %qs", t, cname);
 	      remove = true;
 	    }
 	  else if (DECL_THREAD_LOCAL_P (t))
 	    {
 	      error_at (OMP_CLAUSE_LOCATION (c),
 			"%qD is threadprivate variable in %qs clause", t,
-			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+			cname);
 	      remove = true;
 	    }
 	  else if (!lang_hooks.types.omp_mappable_type (TREE_TYPE (t)))
 	    {
 	      error_at (OMP_CLAUSE_LOCATION (c),
 			"%qD does not have a mappable type in %qs clause", t,
-			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+			cname);
 	      remove = true;
 	    }
 	  if (remove)
diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index 49c1994c65c..a2122a223f5 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,20 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backport from mainline:
+	2022-05-27  Jakub Jelinek  <jakub@redhat.com>
+
+	* parser.cc (cp_parser_omp_clause_name): Parse enter clause.
+	(cp_parser_omp_all_clauses): For to clause on declare target, use
+	OMP_CLAUSE_ENTER clause with OMP_CLAUSE_ENTER_TO instead of
+	OMP_CLAUSE_TO_DECLARE clause.  Handle PRAGMA_OMP_CLAUSE_ENTER.
+	(OMP_DECLARE_TARGET_CLAUSE_MASK): Add enter clause.
+	(cp_parser_omp_declare_target): Use OMP_CLAUSE_ENTER instead of
+	OMP_CLAUSE_TO_DECLARE.
+	* semantics.cc (finish_omp_clauses): Handle OMP_CLAUSE_ENTER instead
+	of OMP_CLAUSE_TO_DECLARE, to OMP_CLAUSE_ENTER_TO use "to" as clause
+	name in diagnostics instead of
+	omp_clause_code_name[OMP_CLAUSE_CODE (c)].
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backport from mainline:
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 71cfe3f59a3..dc3bea50eaf 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -36373,6 +36373,10 @@ cp_parser_omp_clause_name (cp_parser *parser)
 	  else if (!strcmp ("dist_schedule", p))
 	    result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE;
 	  break;
+	case 'e':
+	  if (!strcmp ("enter", p))
+	    result = PRAGMA_OMP_CLAUSE_ENTER;
+	  break;
 	case 'f':
 	  if (!strcmp ("filter", p))
 	    result = PRAGMA_OMP_CLAUSE_FILTER;
@@ -40525,8 +40529,13 @@ cp_parser_omp_all_clauses (cp_parser *parser, omp_clause_mask mask,
 	  break;
 	case PRAGMA_OMP_CLAUSE_TO:
 	  if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) != 0)
-	    clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_TO_DECLARE,
-					      clauses);
+	    {
+	      tree nl = cp_parser_omp_var_list (parser, OMP_CLAUSE_ENTER,
+						clauses);
+	      for (tree c = nl; c != clauses; c = OMP_CLAUSE_CHAIN (c))
+		OMP_CLAUSE_ENTER_TO (c) = 1;
+	      clauses = nl;
+	    }
 	  else
 	    clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_TO, clauses,
 					      C_ORT_OMP, true);
@@ -40637,6 +40646,11 @@ cp_parser_omp_all_clauses (cp_parser *parser, omp_clause_mask mask,
 						clauses, token->location);
 	  c_name = "simd";
 	  break;
+	case PRAGMA_OMP_CLAUSE_ENTER:
+	  clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_ENTER,
+					    clauses);
+	  c_name = "enter";
+	  break;
 	default:
 	  cp_parser_error (parser, "expected %<#pragma omp%> clause");
 	  goto saw_error;
@@ -46197,6 +46211,7 @@ handle_omp_declare_target_clause (tree c, tree t, int device_type)
 
 #define OMP_DECLARE_TARGET_CLAUSE_MASK				\
 	( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO)		\
+	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ENTER)	\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)		\
 	| (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE_TYPE))
 
@@ -46216,7 +46231,7 @@ cp_parser_omp_declare_target (cp_parser *parser, cp_token *pragma_tok)
 				   "#pragma omp declare target", pragma_tok);
   else if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
     {
-      clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_TO_DECLARE,
+      clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE_ENTER,
 					clauses);
       clauses = finish_omp_clauses (clauses, C_ORT_OMP);
       cp_parser_require_pragma_eol (parser, pragma_tok);
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 51918d5091c..2b84e000487 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -8525,48 +8525,50 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 	    }
 	  break;
 
-	case OMP_CLAUSE_TO_DECLARE:
+	case OMP_CLAUSE_ENTER:
 	case OMP_CLAUSE_LINK:
 	  t = OMP_CLAUSE_DECL (c);
+	  const char *cname;
+	  cname = omp_clause_code_name[OMP_CLAUSE_CODE (c)];
+	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER
+	      && OMP_CLAUSE_ENTER_TO (c))
+	    cname = "to";
 	  if (TREE_CODE (t) == FUNCTION_DECL
-	      && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE)
+	      && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
 	    ;
 	  else if (!VAR_P (t))
 	    {
-	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE)
+	      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ENTER)
 		{
 		  if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
 		    error_at (OMP_CLAUSE_LOCATION (c),
-			      "template %qE in clause %qs", t,
-			      omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+			      "template %qE in clause %qs", t, cname);
 		  else if (really_overloaded_fn (t))
 		    error_at (OMP_CLAUSE_LOCATION (c),
 			      "overloaded function name %qE in clause %qs", t,
-			      omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+			      cname);
 		  else
 		    error_at (OMP_CLAUSE_LOCATION (c),
 			      "%qE is neither a variable nor a function name "
-			      "in clause %qs", t,
-			      omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+			      "in clause %qs", t, cname);
 		}
 	      else
 		error_at (OMP_CLAUSE_LOCATION (c),
-			  "%qE is not a variable in clause %qs", t,
-			  omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+			  "%qE is not a variable in clause %qs", t, cname);
 	      remove = true;
 	    }
 	  else if (DECL_THREAD_LOCAL_P (t))
 	    {
 	      error_at (OMP_CLAUSE_LOCATION (c),
 			"%qD is threadprivate variable in %qs clause", t,
-			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+			cname);
 	      remove = true;
 	    }
 	  else if (!cp_omp_mappable_type (TREE_TYPE (t)))
 	    {
 	      error_at (OMP_CLAUSE_LOCATION (c),
 			"%qD does not have a mappable type in %qs clause", t,
-			omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+			cname);
 	      cp_omp_emit_unmappable_type_notes (TREE_TYPE (t));
 	      remove = true;
 	    }
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 473bd6ba061..f3ce282c15d 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,16 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backport from mainline:
+	2022-05-27  Jakub Jelinek  <jakub@redhat.com>
+
+	* c-c++-common/gomp/clauses-3.c: Add tests with enter clause instead
+	of to or modify some existing to clauses to enter.
+	* c-c++-common/gomp/declare-target-1.c: Likewise.
+	* c-c++-common/gomp/declare-target-2.c: Likewise.
+	* c-c++-common/gomp/declare-target-3.c: Likewise.
+	* g++.dg/gomp/attrs-9.C: Likewise.
+	* g++.dg/gomp/declare-target-1.C: Likewise.
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backport from mainline:
diff --git a/gcc/testsuite/c-c++-common/gomp/clauses-3.c b/gcc/testsuite/c-c++-common/gomp/clauses-3.c
index 7e07a81c319..5618a9138ce 100644
--- a/gcc/testsuite/c-c++-common/gomp/clauses-3.c
+++ b/gcc/testsuite/c-c++-common/gomp/clauses-3.c
@@ -3,6 +3,8 @@ struct S { int *s; char u; struct T v; long x; };
 
 void bar (int *);
 #pragma omp declare target to (bar)
+void baz (int *);
+#pragma omp declare target enter (baz)
 
 int
 main ()
@@ -18,6 +20,6 @@ main ()
   #pragma omp target map (s.s[0]) map (s.v.b[:3])
   ;
   #pragma omp target map (s.s[0]) map (s.v.b[:3])
-  bar (s.s);
+  baz (s.s);
   return 0;
 }
diff --git a/gcc/testsuite/c-c++-common/gomp/declare-target-1.c b/gcc/testsuite/c-c++-common/gomp/declare-target-1.c
index a1f1ea717b7..79ad556a9c7 100644
--- a/gcc/testsuite/c-c++-common/gomp/declare-target-1.c
+++ b/gcc/testsuite/c-c++-common/gomp/declare-target-1.c
@@ -10,4 +10,4 @@ long c;
 #pragma omp end declare target
 
 #pragma omp declare target (bar, a)
-#pragma omp declare target to (b) link (d) to (foo)
+#pragma omp declare target to (b) link (d) enter (foo)
diff --git a/gcc/testsuite/c-c++-common/gomp/declare-target-2.c b/gcc/testsuite/c-c++-common/gomp/declare-target-2.c
index c7a325c6155..44fb14daf87 100644
--- a/gcc/testsuite/c-c++-common/gomp/declare-target-2.c
+++ b/gcc/testsuite/c-c++-common/gomp/declare-target-2.c
@@ -7,6 +7,7 @@ extern int a;
 #pragma omp end declare target
 int b;
 #pragma omp declare target to (b) link (b)	/* { dg-error "appears more than once on the same .declare target. directive" } */
+#pragma omp declare target enter (b) link (b)	/* { dg-error "appears more than once on the same .declare target. directive" } */
 int c;
 #pragma omp declare target (c)
 #pragma omp declare target link (c)		/* { dg-error "specified both in declare target" } */
@@ -32,9 +33,13 @@ int m;
 #pragma omp declare target to (k)
 #pragma omp declare target (k)
 #pragma omp declare target to (k, m) link (l)
+#pragma omp declare target enter (k, m) link (l)
 #pragma omp declare target link (l)
 int n, o, s, t;
 #pragma omp declare target to (n) to (n)	/* { dg-error "appears more than once on the same .declare target. directive" } */
+#pragma omp declare target enter (n) enter (n)	/* { dg-error "appears more than once on the same .declare target. directive" } */
+#pragma omp declare target enter (n) to (n)	/* { dg-error "appears more than once on the same .declare target. directive" } */
+#pragma omp declare target to (n) enter (n)	/* { dg-error "appears more than once on the same .declare target. directive" } */
 #pragma omp declare target link (o, o)		/* { dg-error "appears more than once on the same .declare target. directive" } */
 #pragma omp declare target (s, t, s)		/* { dg-error "appears more than once on the same .declare target. directive" } */
 int p, q, r;
diff --git a/gcc/testsuite/c-c++-common/gomp/declare-target-3.c b/gcc/testsuite/c-c++-common/gomp/declare-target-3.c
index bf72fda0a89..e76e7a3c5c8 100644
--- a/gcc/testsuite/c-c++-common/gomp/declare-target-3.c
+++ b/gcc/testsuite/c-c++-common/gomp/declare-target-3.c
@@ -15,10 +15,13 @@ extern int f[];
 #pragma omp declare target to (f) /* { dg-error "'f' does not have a mappable type in 'to' clause" } */
 extern int g[];
 #pragma omp declare target to (g) /* { dg-error "'g' does not have a mappable type in 'to' clause" } */
+extern int g2[];
+#pragma omp declare target enter (g2) /* { dg-error "'g2' does not have a mappable type in 'enter' clause" } */
 int g[3];
 extern int h[];
 int h[3];
 #pragma omp declare target to (h)
+#pragma omp declare target enter (h)
 
 int i[] = { 1, 2, 3 };
 int j[] = { 1, 2, 3 };
diff --git a/gcc/testsuite/g++.dg/gomp/attrs-9.C b/gcc/testsuite/g++.dg/gomp/attrs-9.C
index 08cd2b1dfd9..19a3b0a83c8 100644
--- a/gcc/testsuite/g++.dg/gomp/attrs-9.C
+++ b/gcc/testsuite/g++.dg/gomp/attrs-9.C
@@ -6,8 +6,8 @@ int a;
 [[omp::directive (declare target (a))]];
 int t;
 [[omp::sequence (omp::directive (threadprivate (t)))]];
-int b, c;
-[[omp::directive (declare target, to (b), link (c))]];
+int b, c, e;
+[[omp::directive (declare target, to (b), link (c), enter (e))]];
 [[omp::directive (declare target)]];
 [[omp::directive (declare target)]];
 int d;
diff --git a/gcc/testsuite/g++.dg/gomp/declare-target-1.C b/gcc/testsuite/g++.dg/gomp/declare-target-1.C
index 9cc32f421a7..7b270cdddb7 100644
--- a/gcc/testsuite/g++.dg/gomp/declare-target-1.C
+++ b/gcc/testsuite/g++.dg/gomp/declare-target-1.C
@@ -16,6 +16,7 @@ void f5 (T);
 #pragma omp declare target (f3)
 #pragma omp declare target to (f4)	// { dg-error "overloaded function name .f4. in clause .to." }
 #pragma omp declare target to (f5<int>)	// { dg-error "template .f5<int>. in clause .to." }
+#pragma omp declare target enter (f5<short>) // { dg-error "template .f5<short int>. in clause .enter." }
 template <int N>
 void f6 (int)
 {
@@ -35,3 +36,7 @@ int v;
 #pragma omp declare target (N::M::f7)
 #pragma omp declare target to (::N::f8)
 #pragma omp declare target to (::f9) to (::v)
+#pragma omp declare target to (::f9, ::v)
+#pragma omp declare target enter (::N::f8)
+#pragma omp declare target enter (::f9) enter (::v)
+#pragma omp declare target enter (::f9, ::v)
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index 3013db3df75..d65e474f1b3 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -304,9 +304,9 @@ enum omp_clause_code {
   /* OpenMP clause: uniform (argument-list).  */
   OMP_CLAUSE_UNIFORM,
 
-  /* OpenMP clause: to (extended-list).
-     Only when it appears in declare target.  */
-  OMP_CLAUSE_TO_DECLARE,
+  /* OpenMP clause: enter (extended-list).
+     to is a deprecated alias when it appears in declare target.  */
+  OMP_CLAUSE_ENTER,
 
   /* OpenMP clause: link (variable-list).  */
   OMP_CLAUSE_LINK,
diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc
index 078ceab3ca3..995280904b0 100644
--- a/gcc/tree-nested.cc
+++ b/gcc/tree-nested.cc
@@ -1335,7 +1335,7 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
 	case OMP_CLAUSE_FIRSTPRIVATE:
 	case OMP_CLAUSE_COPYPRIVATE:
 	case OMP_CLAUSE_SHARED:
-	case OMP_CLAUSE_TO_DECLARE:
+	case OMP_CLAUSE_ENTER:
 	case OMP_CLAUSE_LINK:
 	case OMP_CLAUSE_USE_DEVICE_PTR:
 	case OMP_CLAUSE_USE_DEVICE_ADDR:
@@ -2120,7 +2120,7 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
 	case OMP_CLAUSE_FIRSTPRIVATE:
 	case OMP_CLAUSE_COPYPRIVATE:
 	case OMP_CLAUSE_SHARED:
-	case OMP_CLAUSE_TO_DECLARE:
+	case OMP_CLAUSE_ENTER:
 	case OMP_CLAUSE_LINK:
 	case OMP_CLAUSE_USE_DEVICE_PTR:
 	case OMP_CLAUSE_USE_DEVICE_ADDR:
diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc
index 23672082ad6..f7b10cf6a5c 100644
--- a/gcc/tree-pretty-print.cc
+++ b/gcc/tree-pretty-print.cc
@@ -517,8 +517,11 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags)
     case OMP_CLAUSE__SCANTEMP_:
       name = "_scantemp_";
       goto print_remap;
-    case OMP_CLAUSE_TO_DECLARE:
-      name = "to";
+    case OMP_CLAUSE_ENTER:
+      if (OMP_CLAUSE_ENTER_TO (clause))
+	name = "to";
+      else
+	name = "enter";
       goto print_remap;
     case OMP_CLAUSE_LINK:
       name = "link";
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 4142131a88f..b28b86ba225 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -280,7 +280,7 @@ unsigned const char omp_clause_num_ops[] =
   1, /* OMP_CLAUSE_DEPEND  */
   1, /* OMP_CLAUSE_NONTEMPORAL  */
   1, /* OMP_CLAUSE_UNIFORM  */
-  1, /* OMP_CLAUSE_TO_DECLARE  */
+  1, /* OMP_CLAUSE_ENTER  */
   1, /* OMP_CLAUSE_LINK  */
   1, /* OMP_CLAUSE_DETACH  */
   1, /* OMP_CLAUSE_USE_DEVICE_PTR  */
@@ -372,7 +372,7 @@ const char * const omp_clause_code_name[] =
   "depend",
   "nontemporal",
   "uniform",
-  "to",
+  "enter",
   "link",
   "detach",
   "use_device_ptr",
diff --git a/gcc/tree.h b/gcc/tree.h
index 8670199dddc..1b9caf06295 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -1909,6 +1909,10 @@ class auto_suppress_location_wrappers
 #define OMP_CLAUSE_BIND_KIND(NODE) \
   (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_BIND)->omp_clause.subcode.bind_kind)
 
+/* True if ENTER clause is spelled as TO.  */
+#define OMP_CLAUSE_ENTER_TO(NODE) \
+  (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_ENTER)->base.public_flag)
+
 #define OMP_CLAUSE_TILE_LIST(NODE) \
   OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_TILE), 0)
 #define OMP_CLAUSE_TILE_ITERVAR(NODE) \
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 6225f015a48..a8b0ad0faf0 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,12 @@
+2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backport from mainline:
+	2022-05-27  Jakub Jelinek  <jakub@redhat.com>
+
+	* testsuite/libgomp.c-c++-common/target-40.c: Modify some existing to
+	clauses to enter.
+	* testsuite/libgomp.c/target-41.c: Likewise.
+
 2022-07-05  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backport from mainline:
diff --git a/libgomp/testsuite/libgomp.c-c++-common/target-40.c b/libgomp/testsuite/libgomp.c-c++-common/target-40.c
index 22bbdd97b7e..b4660693055 100644
--- a/libgomp/testsuite/libgomp.c-c++-common/target-40.c
+++ b/libgomp/testsuite/libgomp.c-c++-common/target-40.c
@@ -18,7 +18,7 @@ int a = 1;
 int *b = &a;
 int **c = &b;
 fnp2 f5 (void) { f3 (); return f4; }
-#pragma omp declare target to (c)
+#pragma omp declare target enter (c)
 
 int
 main ()
diff --git a/libgomp/testsuite/libgomp.c/target-41.c b/libgomp/testsuite/libgomp.c/target-41.c
index d8d756f80e9..9b49d9a75a6 100644
--- a/libgomp/testsuite/libgomp.c/target-41.c
+++ b/libgomp/testsuite/libgomp.c/target-41.c
@@ -11,7 +11,7 @@ foo (void)
   v++;
 }
 
-#pragma omp declare target to (v, foo)
+#pragma omp declare target enter (v, foo)
 
 int
 main ()


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-05  8:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-05  8:10 [gcc/devel/omp/gcc-12] openmp: Add support for enter clause on declare target Tobias Burnus

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).