public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/omp/gcc-11] openmp: Add nothing directive support
@ 2021-08-18 10:24 Tobias Burnus
  0 siblings, 0 replies; only message in thread
From: Tobias Burnus @ 2021-08-18 10:24 UTC (permalink / raw)
  To: gcc-cvs

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

commit e935744890269c22714fed59edd1d84406233140
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Aug 18 11:20:10 2021 +0200

    openmp: Add nothing directive support
    
    As has been clarified, it is intentional that nothing directive is accepted
    in substatements of selection and looping statements and after labels and
    is handled as if the directive just isn't there, so that
    void
    foo (int x)
    {
      if (x)
        #pragma omp metadirective when (...:nothing) when (...:parallel)
        bar ();
    }
    behaves consistently; declarative and stand-alone directives aren't allowed
    at that point, but constructs are parsed with the following statement as
    the construct body and nothing or missing default on metadirective therefore
    should handle the following statement as part of the if substatement instead
    of having nothing as the substatement and bar done unconditionally after the
    if.
    
    2021-08-18  Jakub Jelinek  <jakub@redhat.com>
    
    gcc/c-family/
            * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_NOTHING.
            * c-pragma.c (omp_pragmas): Add nothing directive.
            * c-omp.c (omp_directives): Uncomment nothing directive entry.
    gcc/c/
            * c-parser.c (c_parser_omp_nothing): New function.
            (c_parser_pragma): Handle PRAGMA_OMP_NOTHING.
    gcc/cp/
            * parser.c (cp_parser_omp_nothing): New function.
            (cp_parser_pragma): Handle PRAGMA_OMP_NOTHING.
    gcc/testsuite/
            * c-c++-common/gomp/nothing-1.c: New test.
            * g++.dg/gomp/attrs-1.C (bar): Add nothing directive test.
            * g++.dg/gomp/attrs-2.C (bar): Likewise.
            * g++.dg/gomp/attrs-9.C: Likewise.
    libgomp/
            * testsuite/libgomp.c-c++-common/nothing-1.c: New test.
    
    (cherry picked from commit 5079b7781a2c506dcdfb241347d74c7891268225)

Diff:
---
 gcc/c-family/ChangeLog.omp                         |  9 +++++
 gcc/c-family/c-omp.c                               |  4 +-
 gcc/c-family/c-pragma.c                            |  1 +
 gcc/c-family/c-pragma.h                            |  1 +
 gcc/c/ChangeLog.omp                                |  7 ++++
 gcc/c/c-parser.c                                   | 15 +++++++
 gcc/cp/ChangeLog.omp                               |  8 ++++
 gcc/cp/parser.c                                    | 14 +++++++
 gcc/testsuite/ChangeLog.omp                        | 10 +++++
 gcc/testsuite/c-c++-common/gomp/nothing-1.c        | 37 +++++++++++++++++
 gcc/testsuite/g++.dg/gomp/attrs-1.C                |  1 +
 gcc/testsuite/g++.dg/gomp/attrs-2.C                |  1 +
 gcc/testsuite/g++.dg/gomp/attrs-9.C                |  1 +
 libgomp/ChangeLog.omp                              |  7 ++++
 libgomp/testsuite/libgomp.c-c++-common/nothing-1.c | 47 ++++++++++++++++++++++
 15 files changed, 161 insertions(+), 2 deletions(-)

diff --git a/gcc/c-family/ChangeLog.omp b/gcc/c-family/ChangeLog.omp
index 2258b025529..a3366bb06d2 100644
--- a/gcc/c-family/ChangeLog.omp
+++ b/gcc/c-family/ChangeLog.omp
@@ -1,3 +1,12 @@
+2021-08-18  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backported from master:
+	2021-08-18  Jakub Jelinek  <jakub@redhat.com>
+
+	* c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_NOTHING.
+	* c-pragma.c (omp_pragmas): Add nothing directive.
+	* c-omp.c (omp_directives): Uncomment nothing directive entry.
+
 2021-08-17  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backported from master:
diff --git a/gcc/c-family/c-omp.c b/gcc/c-family/c-omp.c
index 5dce7fb988c..a553302a6b0 100644
--- a/gcc/c-family/c-omp.c
+++ b/gcc/c-family/c-omp.c
@@ -3791,8 +3791,8 @@ static const struct c_omp_directive omp_directives[] = {
     C_OMP_DIR_CONSTRUCT, true },
   /* { "metadirective", nullptr, nullptr, PRAGMA_OMP_METADIRECTIVE,
     C_OMP_DIR_???, ??? },  */
-  /* { "nothing", nullptr, nullptr, PRAGMA_OMP_NOTHING,
-    C_OMP_DIR_UTILITY, false },  */
+  { "nothing", nullptr, nullptr, PRAGMA_OMP_NOTHING,
+    C_OMP_DIR_UTILITY, false },
   /* ordered with depend clause is C_OMP_DIR_STANDALONE.  */
   { "ordered", nullptr, nullptr, PRAGMA_OMP_ORDERED,
     C_OMP_DIR_CONSTRUCT, true },
diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
index 9c555855dc4..ef428dae010 100644
--- a/gcc/c-family/c-pragma.c
+++ b/gcc/c-family/c-pragma.c
@@ -1318,6 +1318,7 @@ static const struct omp_pragma_def omp_pragmas[] = {
   { "depobj", PRAGMA_OMP_DEPOBJ },
   { "end", PRAGMA_OMP_END_DECLARE_TARGET },
   { "flush", PRAGMA_OMP_FLUSH },
+  { "nothing", PRAGMA_OMP_NOTHING },
   { "requires", PRAGMA_OMP_REQUIRES },
   { "scope", PRAGMA_OMP_SCOPE },
   { "section", PRAGMA_OMP_SECTION },
diff --git a/gcc/c-family/c-pragma.h b/gcc/c-family/c-pragma.h
index 2b9e5eac675..dc9e8a6616d 100644
--- a/gcc/c-family/c-pragma.h
+++ b/gcc/c-family/c-pragma.h
@@ -57,6 +57,7 @@ enum pragma_kind {
   PRAGMA_OMP_FLUSH,
   PRAGMA_OMP_FOR,
   PRAGMA_OMP_LOOP,
+  PRAGMA_OMP_NOTHING,
   PRAGMA_OMP_MASKED,
   PRAGMA_OMP_MASTER,
   PRAGMA_OMP_ORDERED,
diff --git a/gcc/c/ChangeLog.omp b/gcc/c/ChangeLog.omp
index 3b1b0869849..80d1d59cd2a 100644
--- a/gcc/c/ChangeLog.omp
+++ b/gcc/c/ChangeLog.omp
@@ -1,3 +1,10 @@
+2021-08-18  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backported from master:
+	2021-08-18  Jakub Jelinek  <jakub@redhat.com>
+	* c-parser.c (c_parser_omp_nothing): New function.
+	(c_parser_pragma): Handle PRAGMA_OMP_NOTHING.
+
 2021-08-18  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backported from master:
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index a07f5b8cdda..73d54f1f3ea 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1577,6 +1577,7 @@ static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
 static void c_parser_omp_taskwait (c_parser *);
 static void c_parser_omp_taskyield (c_parser *);
 static void c_parser_omp_cancel (c_parser *);
+static void c_parser_omp_nothing (c_parser *);
 
 enum pragma_context { pragma_external, pragma_struct, pragma_param,
 		      pragma_stmt, pragma_compound };
@@ -12444,6 +12445,10 @@ c_parser_pragma (c_parser *parser, enum pragma_context context, bool *if_p)
       c_parser_omp_requires (parser);
       return false;
 
+    case PRAGMA_OMP_NOTHING:
+      c_parser_omp_nothing (parser);
+      return false;
+
     case PRAGMA_OMP_ORDERED:
       return c_parser_omp_ordered (parser, context, if_p);
 
@@ -21929,6 +21934,16 @@ c_parser_omp_taskloop (location_t loc, c_parser *parser,
   return ret;
 }
 
+/* OpenMP 5.1
+   #pragma omp nothing new-line  */
+
+static void
+c_parser_omp_nothing (c_parser *parser)
+{
+  c_parser_consume_pragma (parser);
+  c_parser_skip_to_pragma_eol (parser);
+}
+
 /* Main entry point to parsing most OpenMP pragmas.  */
 
 static void
diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index 07fee66a31e..05614304769 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,11 @@
+2021-08-18  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backported from master:
+	2021-08-18  Jakub Jelinek  <jakub@redhat.com>
+
+	* parser.c (cp_parser_omp_nothing): New function.
+	(cp_parser_pragma): Handle PRAGMA_OMP_NOTHING.
+
 2021-08-18  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backported from master:
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 1381eb00f09..5b9d42f6ccf 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -45353,6 +45353,16 @@ cp_parser_omp_requires (cp_parser *parser, cp_token *pragma_tok)
 }
 
 
+/* OpenMP 5.1:
+   #pragma omp nothing new-line  */
+
+static void
+cp_parser_omp_nothing (cp_parser *parser, cp_token *pragma_tok)
+{
+  cp_parser_skip_to_pragma_eol (parser, pragma_tok);
+}
+
+
 /* OpenMP 4.5:
    #pragma omp taskloop taskloop-clause[optseq] new-line
      for-loop
@@ -46462,6 +46472,10 @@ cp_parser_pragma (cp_parser *parser, enum pragma_context context, bool *if_p)
 	}
       return cp_parser_omp_requires (parser, pragma_tok);
 
+    case PRAGMA_OMP_NOTHING:
+      cp_parser_omp_nothing (parser, pragma_tok);
+      return false;
+
     case PRAGMA_OMP_ORDERED:
       if (context != pragma_stmt && context != pragma_compound)
 	goto bad_stmt;
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 57574d56fdc..27c518d2c83 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,13 @@
+2021-08-18  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backported from master:
+	2021-08-18  Jakub Jelinek  <jakub@redhat.com>
+
+	* c-c++-common/gomp/nothing-1.c: New test.
+	* g++.dg/gomp/attrs-1.C (bar): Add nothing directive test.
+	* g++.dg/gomp/attrs-2.C (bar): Likewise.
+	* g++.dg/gomp/attrs-9.C: Likewise.
+
 2021-08-18  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backported from master:
diff --git a/gcc/testsuite/c-c++-common/gomp/nothing-1.c b/gcc/testsuite/c-c++-common/gomp/nothing-1.c
new file mode 100644
index 00000000000..d50c92a67c3
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/nothing-1.c
@@ -0,0 +1,37 @@
+#pragma omp nothing
+
+struct S
+{
+  #pragma omp nothing
+  int s;
+};
+
+int
+foo (int i)
+{
+  #pragma omp nothing
+  if (0)
+    #pragma omp nothing
+    i++;
+  if (1)
+    ;
+  else
+    #pragma omp nothing
+    i++;
+  switch (0)
+    #pragma omp nothing
+    {
+    default:
+      break;
+    }
+  while (0)
+    #pragma omp nothing
+    i++;
+  for (; 0;)
+    #pragma omp nothing
+    i++;
+  lab:
+  #pragma omp nothing
+  i++;
+  return i;
+}
diff --git a/gcc/testsuite/g++.dg/gomp/attrs-1.C b/gcc/testsuite/g++.dg/gomp/attrs-1.C
index 686acf5042f..435d54fb762 100644
--- a/gcc/testsuite/g++.dg/gomp/attrs-1.C
+++ b/gcc/testsuite/g++.dg/gomp/attrs-1.C
@@ -111,6 +111,7 @@ void
 bar (int d, int m, int i1, int i2, int i3, int p, int *idp, int s,
      int nte, int tl, int nth, int g, int nta, int fi, int pp, int *q, int *dd, int ntm)
 {
+  [[omp::directive (nothing)]];
   [[omp::directive (for simd
     private (p) firstprivate (f) lastprivate (l) linear (ll:1) reduction(+:r) schedule(static, 4) collapse(1) nowait
     safelen(8) simdlen(4) aligned(q: 32) nontemporal(ntm) if(i1) order(concurrent) allocate (f))]]
diff --git a/gcc/testsuite/g++.dg/gomp/attrs-2.C b/gcc/testsuite/g++.dg/gomp/attrs-2.C
index 2190457c877..bea657f02b9 100644
--- a/gcc/testsuite/g++.dg/gomp/attrs-2.C
+++ b/gcc/testsuite/g++.dg/gomp/attrs-2.C
@@ -111,6 +111,7 @@ void
 bar (int d, int m, int i1, int i2, int i3, int p, int *idp, int s,
      int nte, int tl, int nth, int g, int nta, int fi, int pp, int *q, int *dd, int ntm)
 {
+  [[omp::directive (nothing)]];
   [[omp::directive (for simd,
     private (p),firstprivate (f),lastprivate (l),linear (ll:1),reduction(+:r),schedule(static, 4),collapse(1),nowait,
     safelen(8),simdlen(4),aligned(q: 32),nontemporal(ntm),if(i1),order(concurrent),allocate (f))]]
diff --git a/gcc/testsuite/g++.dg/gomp/attrs-9.C b/gcc/testsuite/g++.dg/gomp/attrs-9.C
index 0af556c7284..08cd2b1dfd9 100644
--- a/gcc/testsuite/g++.dg/gomp/attrs-9.C
+++ b/gcc/testsuite/g++.dg/gomp/attrs-9.C
@@ -13,3 +13,4 @@ int b, c;
 int d;
 [[omp::directive (end declare target)]];
 [[omp::directive (end declare target)]];
+[[omp::directive (nothing)]];
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 31540ddc1bc..75a0b1e159c 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,10 @@
+2021-08-18  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backported from master:
+	2021-08-18  Jakub Jelinek  <jakub@redhat.com>
+
+	* testsuite/libgomp.c-c++-common/nothing-1.c: New test.
+
 2021-08-17  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backported from master:
diff --git a/libgomp/testsuite/libgomp.c-c++-common/nothing-1.c b/libgomp/testsuite/libgomp.c-c++-common/nothing-1.c
new file mode 100644
index 00000000000..69716b18d98
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/nothing-1.c
@@ -0,0 +1,47 @@
+#include <stdlib.h>
+
+#pragma omp nothing
+
+struct S
+{
+  #pragma omp nothing
+  int s;
+};
+
+int
+foo (int i)
+{
+  #pragma omp nothing
+  if (0)
+    #pragma omp nothing
+    i++;
+  if (1)
+    ;
+  else
+    #pragma omp nothing
+    i++;
+  switch (0)
+    #pragma omp nothing
+    {
+    default:
+      break;
+    }
+  while (0)
+    #pragma omp nothing
+    i++;
+  for (; 0;)
+    #pragma omp nothing
+    i++;
+  lab:
+  #pragma omp nothing
+  i++;
+  return i;
+}
+
+int
+main ()
+{
+  if (foo (5) != 6 || foo (-2) != -1)
+    abort ();
+  return 0;
+}


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

only message in thread, other threads:[~2021-08-18 10:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 10:24 [gcc/devel/omp/gcc-11] openmp: Add nothing directive support 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).