]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Add nothing directive support
authorJakub Jelinek <jakub@redhat.com>
Wed, 18 Aug 2021 09:20:10 +0000 (11:20 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Wed, 18 Aug 2021 09:20:10 +0000 (11:20 +0200)
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)

15 files changed:
gcc/c-family/ChangeLog.omp
gcc/c-family/c-omp.c
gcc/c-family/c-pragma.c
gcc/c-family/c-pragma.h
gcc/c/ChangeLog.omp
gcc/c/c-parser.c
gcc/cp/ChangeLog.omp
gcc/cp/parser.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/c-c++-common/gomp/nothing-1.c [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/attrs-1.C
gcc/testsuite/g++.dg/gomp/attrs-2.C
gcc/testsuite/g++.dg/gomp/attrs-9.C
libgomp/ChangeLog.omp
libgomp/testsuite/libgomp.c-c++-common/nothing-1.c [new file with mode: 0644]

index 2258b025529f6ec7bab22c992fb6f2cc2ca48231..a3366bb06d2c436e7969d92c42b8fe14d056d84b 100644 (file)
@@ -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:
index 5dce7fb988c10fc7efa4c8629939a16c2a4b1a21..a553302a6b04b6df2b0c3503be6f90c759f2724e 100644 (file)
@@ -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 },
index 9c555855dc4b5341a274b401d805fa02c7f5f6f1..ef428dae0104733619c9bd446abeab52c0dcdb58 100644 (file)
@@ -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 },
index 2b9e5eac675a5af98f76f3dd996c5775a2e5ef94..dc9e8a6616df91d25645ea32d621a75c4e2bcdb4 100644 (file)
@@ -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,
index 3b1b08698498f2fca6f4ae14264ca8049b46c254..80d1d59cd2a85f8589eff813460989ec4e7ea821 100644 (file)
@@ -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:
index a07f5b8cdda1df664f5b955aa1dede290b69b83e..73d54f1f3ea6b1b30f3d6f05e2c6704e3b83b690 100644 (file)
@@ -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
index 07fee66a31e11a41b99ee2bbb620bebd91ed4df4..056143047696faa3b81e1cff6cead39b50c1fd28 100644 (file)
@@ -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:
index 1381eb00f09b1006fc3aee23b14ba644b7dc15ee..5b9d42f6ccf06360f83202f23b1acad8cb5406ef 100644 (file)
@@ -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;
index 57574d56fdce1676edc3028e452fc43c99fa8d13..27c518d2c83f24a44ed29990d2160f8a4c7fc769 100644 (file)
@@ -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 (file)
index 0000000..d50c92a
--- /dev/null
@@ -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;
+}
index 686acf5042fe82d18db4ed077f148cfba2af6098..435d54fb762e1370eab273e2334d6d827cbe91bd 100644 (file)
@@ -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))]]
index 2190457c877966e1af2bdaa09c9a6fb7e0bb25ae..bea657f02b9a80433867c81b2fb2ad42da710397 100644 (file)
@@ -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))]]
index 0af556c728423429deb6cb5877af90dd5b09362f..08cd2b1dfd94e4efede5b674c86258e0fce38487 100644 (file)
@@ -13,3 +13,4 @@ int b, c;
 int d;
 [[omp::directive (end declare target)]];
 [[omp::directive (end declare target)]];
+[[omp::directive (nothing)]];
index 31540ddc1bc365d81a1ee926827808ceee1efacf..75a0b1e159c3e5974dd734cc9426cd4f44212ea7 100644 (file)
@@ -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 (file)
index 0000000..69716b1
--- /dev/null
@@ -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;
+}