]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
C, C++, Fortran, OpenMP: Add support for 'flush seq_cst' construct.
authorMarcel Vollweiler <marcel@codesourcery.com>
Tue, 7 Sep 2021 10:46:28 +0000 (03:46 -0700)
committerMarcel Vollweiler <marcel@codesourcery.com>
Tue, 7 Sep 2021 10:46:28 +0000 (03:46 -0700)
This patch adds support for the 'seq_cst' memory order clause on the 'flush'
directive which was introduced in OpenMP 5.1.

gcc/c-family/ChangeLog:

* c-omp.c (c_finish_omp_flush): Handle MEMMODEL_SEQ_CST.

gcc/c/ChangeLog:

* c-parser.c (c_parser_omp_flush): Parse 'seq_cst' clause on 'flush'
directive.

gcc/cp/ChangeLog:

* parser.c (cp_parser_omp_flush): Parse 'seq_cst' clause on 'flush'
directive.
* semantics.c (finish_omp_flush): Handle MEMMODEL_SEQ_CST.

gcc/fortran/ChangeLog:

* openmp.c (gfc_match_omp_flush): Parse 'seq_cst' clause on 'flush'
directive.
* trans-openmp.c (gfc_trans_omp_flush): Handle OMP_MEMORDER_SEQ_CST.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/flush-1.c: Add test case for 'seq_cst'.
* c-c++-common/gomp/flush-2.c: Add test case for 'seq_cst'.
* g++.dg/gomp/attrs-1.C: Adapt test to handle all flush clauses.
* g++.dg/gomp/attrs-2.C: Adapt test to handle all flush clauses.
* gfortran.dg/gomp/flush-1.f90: Add test case for 'seq_cst'.
* gfortran.dg/gomp/flush-2.f90: Add test case for 'seq_cst'.

12 files changed:
gcc/c-family/c-omp.c
gcc/c/c-parser.c
gcc/cp/parser.c
gcc/cp/semantics.c
gcc/fortran/openmp.c
gcc/fortran/trans-openmp.c
gcc/testsuite/c-c++-common/gomp/flush-1.c
gcc/testsuite/c-c++-common/gomp/flush-2.c
gcc/testsuite/g++.dg/gomp/attrs-1.C
gcc/testsuite/g++.dg/gomp/attrs-2.C
gcc/testsuite/gfortran.dg/gomp/flush-1.f90
gcc/testsuite/gfortran.dg/gomp/flush-2.f90

index 18de7e42b93324ebc870fc4906e961bde4065619..4b95fc16e1f635b1c3b2dae293d6c035e275d184 100644 (file)
@@ -606,7 +606,7 @@ c_finish_omp_flush (location_t loc, int mo)
 {
   tree x;
 
-  if (mo == MEMMODEL_LAST)
+  if (mo == MEMMODEL_LAST || mo == MEMMODEL_SEQ_CST)
     {
       x = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
       x = build_call_expr_loc (loc, x, 0);
index 3b1d10f1a36760a64a7d580b79dffc733c1c5eef..4d074ec14438484b8a494e9d3265e7a0a6ae63db 100644 (file)
@@ -18339,7 +18339,9 @@ c_parser_omp_flush (c_parser *parser)
       const char *p
        = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value);
 
-      if (!strcmp (p, "acq_rel"))
+      if (!strcmp (p, "seq_cst"))
+       mo = MEMMODEL_SEQ_CST;
+      else if (!strcmp (p, "acq_rel"))
        mo = MEMMODEL_ACQ_REL;
       else if (!strcmp (p, "release"))
        mo = MEMMODEL_RELEASE;
@@ -18347,7 +18349,8 @@ c_parser_omp_flush (c_parser *parser)
        mo = MEMMODEL_ACQUIRE;
       else
        error_at (c_parser_peek_token (parser)->location,
-                 "expected %<acq_rel%>, %<release%> or %<acquire%>");
+                 "expected %<seq_cst%>, %<acq_rel%>, %<release%> or "
+                 "%<acquire%>");
       c_parser_consume_token (parser);
     }
   if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
index ea71f9ca91a61d1e28420658d83272dd75ce6f33..f9c2c8ac3a7261d0b6331bdf8961b190a0b640bc 100644 (file)
@@ -40742,7 +40742,9 @@ cp_parser_omp_flush (cp_parser *parser, cp_token *pragma_tok)
     {
       tree id = cp_lexer_peek_token (parser->lexer)->u.value;
       const char *p = IDENTIFIER_POINTER (id);
-      if (!strcmp (p, "acq_rel"))
+      if (!strcmp (p, "seq_cst"))
+       mo = MEMMODEL_SEQ_CST;
+      else if (!strcmp (p, "acq_rel"))
        mo = MEMMODEL_ACQ_REL;
       else if (!strcmp (p, "release"))
        mo = MEMMODEL_RELEASE;
@@ -40750,7 +40752,8 @@ cp_parser_omp_flush (cp_parser *parser, cp_token *pragma_tok)
        mo = MEMMODEL_ACQUIRE;
       else
        error_at (cp_lexer_peek_token (parser->lexer)->location,
-                 "expected %<acq_rel%>, %<release%> or %<acquire%>");
+                 "expected %<seq_cst%>, %<acq_rel%>, %<release%> or "
+                 "%<acquire%>");
       cp_lexer_consume_token (parser->lexer);
     }
   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
index f4b042fb676bbd088b455e6d8774b05088170450..8b78e89ce3a145956fd5efe7ad972d633b3106db 100644 (file)
@@ -10039,7 +10039,7 @@ finish_omp_flush (int mo)
 {
   tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
   releasing_vec vec;
-  if (mo != MEMMODEL_LAST)
+  if (mo != MEMMODEL_LAST && mo != MEMMODEL_SEQ_CST)
     {
       fn = builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE);
       vec->quick_push (build_int_cst (integer_type_node, mo));
index 64ecd547d267ffb8949c0d2c5063791db9c22931..a64b7f5aa10e55db36362df2cca5621efe5c8e63 100644 (file)
@@ -3782,7 +3782,9 @@ gfc_match_omp_flush (void)
   enum gfc_omp_memorder mo = OMP_MEMORDER_UNSET;
   if (gfc_match_omp_eos () == MATCH_NO && gfc_peek_ascii_char () != '(')
     {
-      if (gfc_match ("acq_rel") == MATCH_YES)
+      if (gfc_match ("seq_cst") == MATCH_YES)
+       mo = OMP_MEMORDER_SEQ_CST;
+      else if (gfc_match ("acq_rel") == MATCH_YES)
        mo = OMP_MEMORDER_ACQ_REL;
       else if (gfc_match ("release") == MATCH_YES)
        mo = OMP_MEMORDER_RELEASE;
@@ -3790,7 +3792,7 @@ gfc_match_omp_flush (void)
        mo = OMP_MEMORDER_ACQUIRE;
       else
        {
-         gfc_error ("Expected AQC_REL, RELEASE, or ACQUIRE at %C");
+         gfc_error ("Expected SEQ_CST, AQC_REL, RELEASE, or ACQUIRE at %C");
          return MATCH_ERROR;
        }
       c = gfc_get_omp_clauses ();
index 6f9b0e390dea0eaec3f8c27bcee7f8dc8b26081e..e55e0c818686cd69bdcd4798026382a85483a178 100644 (file)
@@ -5413,7 +5413,8 @@ gfc_trans_omp_flush (gfc_code *code)
 {
   tree call;
   if (!code->ext.omp_clauses
-      || code->ext.omp_clauses->memorder == OMP_MEMORDER_UNSET)
+      || code->ext.omp_clauses->memorder == OMP_MEMORDER_UNSET
+      || code->ext.omp_clauses->memorder == OMP_MEMORDER_SEQ_CST)
     {
       call = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
       call = build_call_expr_loc (input_location, call, 0);
index 7c3e5294a051e78a8b127c246ea3b8874512f3fc..717b951160fa38ff306e778732f1df0258f92a80 100644 (file)
@@ -1,4 +1,5 @@
 /* { dg-additional-options "-fdump-tree-gimple" } */
+/* { dg-final { scan-tree-dump "foo \\(6\\);\[\n\r]*  __sync_synchronize \\(\\);\[\n\r]*  foo \\(6\\);" "gimple" } } */
 /* { dg-final { scan-tree-dump "foo \\(4\\);\[\n\r]*  __atomic_thread_fence \\(4\\);\[\n\r]*  foo \\(4\\);" "gimple" } } */
 /* { dg-final { scan-tree-dump "foo \\(3\\);\[\n\r]*  __atomic_thread_fence \\(3\\);\[\n\r]*  foo \\(3\\);" "gimple" } } */
 /* { dg-final { scan-tree-dump "foo \\(2\\);\[\n\r]*  __atomic_thread_fence \\(2\\);\[\n\r]*  foo \\(2\\);" "gimple" } } */
@@ -37,3 +38,11 @@ f4 (void)
   #pragma omp flush
   foo (5);
 }
+
+void
+f5 (void)
+{
+  foo (6);
+  #pragma omp flush seq_cst
+  foo (6);
+}
index 00baa8ac67f8f93126172d96b016b69879a7191d..30ef5982712f43e38faf7f676366c0d5c7567191 100644 (file)
@@ -8,10 +8,11 @@ foo (void)
   #pragma omp flush acquire
   #pragma omp flush release
   #pragma omp flush acq_rel
-  #pragma omp flush relaxed            /* { dg-error "expected 'acq_rel', 'release' or 'acquire'" } */
-  #pragma omp flush seq_cst            /* { dg-error "expected 'acq_rel', 'release' or 'acquire'" } */
-  #pragma omp flush foobar             /* { dg-error "expected 'acq_rel', 'release' or 'acquire'" } */
+  #pragma omp flush seq_cst
+  #pragma omp flush relaxed            /* { dg-error "expected 'seq_cst', 'acq_rel', 'release' or 'acquire'" } */
+  #pragma omp flush foobar             /* { dg-error "expected 'seq_cst', 'acq_rel', 'release' or 'acquire'" } */
   #pragma omp flush acquire (a, b)     /* { dg-error "'flush' list specified together with memory order clause" } */
   #pragma omp flush release (a, b)     /* { dg-error "'flush' list specified together with memory order clause" } */
   #pragma omp flush acq_rel (a, b)     /* { dg-error "'flush' list specified together with memory order clause" } */
+  #pragma omp flush seq_cst (a, b)     /* { dg-error "'flush' list specified together with memory order clause" } */
 }
index cd20845b634d7ca7ce48ba254d6c99e6a1413213..c871c51728fc3d1888f1519d44ec5cacbf7bb843 100644 (file)
@@ -528,6 +528,12 @@ bar (int d, int m, int i1, int i2, int i3, int p, int *idp, int s,
   ;
   [[omp::directive (flush acq_rel)]]
   ;
+  [[omp::directive (flush acquire)]]
+  ;
+  [[omp::directive (flush release)]]
+  ;
+  [[omp::directive (flush seq_cst)]]
+  ;
   [[omp::directive (flush (p, f))]]
   ;
   [[omp::directive (simd
index 5c54905576d1fe19b09ab1a27bce4179c4b216c1..5ec19b32fb0e3b63ab8af416f29d918047feafdb 100644 (file)
@@ -528,6 +528,12 @@ bar (int d, int m, int i1, int i2, int i3, int p, int *idp, int s,
   ;
   [[omp::directive (flush, acq_rel)]]
   ;
+  [[omp::directive (flush, acquire)]]
+  ;
+  [[omp::directive (flush, release)]]
+  ;
+  [[omp::directive (flush, seq_cst)]]
+  ;
   [[omp::directive (flush (p, f))]]
   ;
   [[omp::directive (simd,
index d0b7f9eb82d3d90dd5261f7205bba2c742a8ebce..904bb1d03aab49d10eccad75e1e2776e8e05e5da 100644 (file)
@@ -1,4 +1,5 @@
 ! { dg-additional-options "-fdump-tree-gimple" }
+! { dg-final { scan-tree-dump "foo \\(6\\);\[\n\r]*  __sync_synchronize \\(\\);\[\n\r]*  foo \\(6\\);" "gimple" } }
 ! { dg-final { scan-tree-dump "foo \\(4\\);\[\n\r]*  __atomic_thread_fence \\(4\\);\[\n\r]*  foo \\(4\\);" "gimple" } }
 ! { dg-final { scan-tree-dump "foo \\(3\\);\[\n\r]*  __atomic_thread_fence \\(3\\);\[\n\r]*  foo \\(3\\);" "gimple" } }
 ! { dg-final { scan-tree-dump "foo \\(2\\);\[\n\r]*  __atomic_thread_fence \\(2\\);\[\n\r]*  foo \\(2\\);" "gimple" } }
@@ -39,3 +40,10 @@ subroutine f4
   !$omp flush
   call foo (5)
 end
+
+subroutine f5
+  use m
+  call foo (6)
+  !$omp flush seq_cst
+  call foo (6)
+end
index 685737116490701b87143485a2a5718a5f4e3051..ba234448a60d711d2a739afa1caa373f04b69203 100644 (file)
@@ -9,10 +9,11 @@ subroutine foo (void)
   !$omp flush acquire
   !$omp flush release
   !$omp flush acq_rel
-  !$omp flush relaxed          ! { dg-error "Expected AQC_REL, RELEASE, or ACQUIRE" }
-  !$omp flush seq_cst          ! { dg-error "Expected AQC_REL, RELEASE, or ACQUIRE" }
-  !$omp flush foobar           ! { dg-error "Expected AQC_REL, RELEASE, or ACQUIRE" }
+  !$omp flush seq_cst
+  !$omp flush relaxed          ! { dg-error "Expected SEQ_CST, AQC_REL, RELEASE, or ACQUIRE" }
+  !$omp flush foobar           ! { dg-error "Expected SEQ_CST, AQC_REL, RELEASE, or ACQUIRE" }
   !$omp flush acquire (a, b)   ! { dg-error "List specified together with memory order clause in FLUSH directive" }
   !$omp flush release (a, b)   ! { dg-error "List specified together with memory order clause in FLUSH directive" }
   !$omp flush acq_rel (a, b)   ! { dg-error "List specified together with memory order clause in FLUSH directive" }
-end
+  !$omp flush seq_cst (a, b)   ! { dg-error "List specified together with memory order clause in FLUSH directive" }
+  end