Skip to content

Commit 612f8ec

Browse files
ShashwathiNavadaShashwathi Nchandraghale
authored
seq_cst is allowed in Flush since OpenMP 5.1. (#114072)
This PR adds support seq_cst (sequential consistency) clause for the flush directive in OpenMP. The seq_cst clause enforces a stricter memory ordering, ensuring that all threads observe the memory effects of the flush in the same order, improving consistency in memory operations across threads. --------- Co-authored-by: Shashwathi N <[email protected]> Co-authored-by: CHANDRA GHALE <[email protected]>
1 parent 48ec59c commit 612f8ec

File tree

11 files changed

+42
-29
lines changed

11 files changed

+42
-29
lines changed

clang/docs/OpenMPSupport.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ implementation.
290290
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
291291
| memory management | changes to omp_alloctrait_key enum | :none:`unclaimed` | |
292292
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
293-
| memory model | seq_cst clause on flush construct | :none:`unclaimed` | |
293+
| memory model | seq_cst clause on flush construct | :good:`done` | https://github.com/llvm/llvm-project/pull/114072 |
294294
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
295295
| misc | 'omp_all_memory' keyword and use in 'depend' clause | :good:`done` | D125828, D126321 |
296296
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+

clang/include/clang/AST/OpenMPClause.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,8 +2670,8 @@ class OMPCompareClause final : public OMPClause {
26702670
}
26712671
};
26722672

2673-
/// This represents 'seq_cst' clause in the '#pragma omp atomic'
2674-
/// directive.
2673+
/// This represents 'seq_cst' clause in the '#pragma omp atomic|flush'
2674+
/// directives.
26752675
///
26762676
/// \code
26772677
/// #pragma omp atomic seq_cst

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11396,7 +11396,7 @@ def err_omp_atomic_weak_no_equality : Error<"expected '==' operator for 'weak' c
1139611396
def err_omp_atomic_several_clauses : Error<
1139711397
"directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause">;
1139811398
def err_omp_several_mem_order_clauses : Error<
11399-
"directive '#pragma omp %0' cannot contain more than one %select{'seq_cst', 'relaxed', |}1'acq_rel', 'acquire' or 'release' clause">;
11399+
"directive '#pragma omp %0' cannot contain more than one 'seq_cst',%select{ 'relaxed',|}1 'acq_rel', 'acquire' or 'release' clause">;
1140011400
def err_omp_atomic_incompatible_mem_order_clause : Error<
1140111401
"directive '#pragma omp atomic%select{ %0|}1' cannot be used with '%2' clause">;
1140211402
def note_omp_previous_mem_order_clause : Note<

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11102,7 +11102,8 @@ StmtResult SemaOpenMP::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses,
1110211102
for (const OMPClause *C : Clauses) {
1110311103
if (C->getClauseKind() == OMPC_acq_rel ||
1110411104
C->getClauseKind() == OMPC_acquire ||
11105-
C->getClauseKind() == OMPC_release) {
11105+
C->getClauseKind() == OMPC_release ||
11106+
C->getClauseKind() == OMPC_seq_cst /*OpenMP 5.1*/) {
1110611107
if (MemOrderKind != OMPC_unknown) {
1110711108
Diag(C->getBeginLoc(), diag::err_omp_several_mem_order_clauses)
1110811109
<< getOpenMPDirectiveName(OMPD_flush) << 1

clang/test/OpenMP/flush_ast_print.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
2-
// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
3-
// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s
1+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -ast-print %s | FileCheck %s
2+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s
3+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s
44

5-
// RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | FileCheck %s
6-
// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
7-
// RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s
5+
// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -ast-print %s | FileCheck %s
6+
// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s
7+
// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s
88
// expected-no-diagnostics
99

1010
#ifndef HEADER
@@ -19,6 +19,7 @@ T tmain(T argc) {
1919
#pragma omp flush acq_rel
2020
#pragma omp flush acquire
2121
#pragma omp flush release
22+
#pragma omp flush seq_cst
2223
#pragma omp flush(a)
2324
return a + argc;
2425
}
@@ -27,18 +28,21 @@ T tmain(T argc) {
2728
// CHECK-NEXT: #pragma omp flush acq_rel{{$}}
2829
// CHECK-NEXT: #pragma omp flush acquire{{$}}
2930
// CHECK-NEXT: #pragma omp flush release{{$}}
31+
// CHECK-NEXT: #pragma omp flush seq_cst{{$}}
3032
// CHECK-NEXT: #pragma omp flush (a)
3133
// CHECK: static int a;
3234
// CHECK-NEXT: #pragma omp flush
3335
// CHECK-NEXT: #pragma omp flush acq_rel{{$}}
3436
// CHECK-NEXT: #pragma omp flush acquire{{$}}
3537
// CHECK-NEXT: #pragma omp flush release{{$}}
38+
// CHECK-NEXT: #pragma omp flush seq_cst{{$}}
3639
// CHECK-NEXT: #pragma omp flush (a)
3740
// CHECK: static char a;
3841
// CHECK-NEXT: #pragma omp flush
3942
// CHECK-NEXT: #pragma omp flush acq_rel{{$}}
4043
// CHECK-NEXT: #pragma omp flush acquire{{$}}
4144
// CHECK-NEXT: #pragma omp flush release{{$}}
45+
// CHECK-NEXT: #pragma omp flush seq_cst{{$}}
4246
// CHECK-NEXT: #pragma omp flush (a)
4347

4448
int main(int argc, char **argv) {
@@ -48,11 +52,13 @@ int main(int argc, char **argv) {
4852
#pragma omp flush acq_rel
4953
#pragma omp flush acquire
5054
#pragma omp flush release
55+
#pragma omp flush seq_cst
5156
#pragma omp flush(a)
5257
// CHECK-NEXT: #pragma omp flush
5358
// CHECK-NEXT: #pragma omp flush acq_rel
5459
// CHECK-NEXT: #pragma omp flush acquire{{$}}
5560
// CHECK-NEXT: #pragma omp flush release
61+
// CHECK-NEXT: #pragma omp flush seq_cst
5662
// CHECK-NEXT: #pragma omp flush (a)
5763
return tmain(argc) + tmain(argv[0][0]) + a;
5864
}

clang/test/OpenMP/flush_codegen.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
2-
// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3-
// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4-
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
5-
// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
6-
// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
1+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
2+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -fopenmp-enable-irbuilder -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
5+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -fopenmp-enable-irbuilder -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
6+
// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -fopenmp-enable-irbuilder -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
77

8-
// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
9-
// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
10-
// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
8+
// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
9+
// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
10+
// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
1111
// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
1212
// expected-no-diagnostics
1313
#ifndef HEADER
@@ -17,6 +17,7 @@ template <class T>
1717
T tmain(T argc) {
1818
static T a;
1919
#pragma omp flush
20+
#pragma omp flush seq_cst
2021
#pragma omp flush acq_rel
2122
#pragma omp flush acquire
2223
#pragma omp flush release
@@ -28,6 +29,7 @@ T tmain(T argc) {
2829
int main() {
2930
static int a;
3031
#pragma omp flush
32+
#pragma omp flush seq_cst
3133
#pragma omp flush acq_rel
3234
#pragma omp flush acquire
3335
#pragma omp flush release
@@ -37,6 +39,7 @@ int main() {
3739
// CHECK: call {{.*}}void @__kmpc_flush(ptr {{(@|%).+}})
3840
// CHECK: call {{.*}}void @__kmpc_flush(ptr {{(@|%).+}})
3941
// CHECK: call {{.*}}void @__kmpc_flush(ptr {{(@|%).+}})
42+
// CHECK: call {{.*}}void @__kmpc_flush(ptr {{(@|%).+}})
4043
return tmain(a);
4144
// CHECK: call {{.*}} [[TMAIN:@.+]](
4245
// CHECK: ret
@@ -48,6 +51,7 @@ int main() {
4851
// CHECK: call {{.*}}void @__kmpc_flush(ptr {{(@|%).+}})
4952
// CHECK: call {{.*}}void @__kmpc_flush(ptr {{(@|%).+}})
5053
// CHECK: call {{.*}}void @__kmpc_flush(ptr {{(@|%).+}})
54+
// CHECK: call {{.*}}void @__kmpc_flush(ptr {{(@|%).+}})
5155
// CHECK: ret
5256

5357
// CHECK-NOT: line: 0,

clang/test/OpenMP/flush_messages.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,12 @@ label1 : {
134134
#pragma omp flush(argc) flush(argc) // expected-warning {{extra tokens at the end of '#pragma omp flush' are ignored}}
135135
#pragma omp parallel flush(argc) // expected-warning {{extra tokens at the end of '#pragma omp parallel' are ignored}}
136136
;
137-
#pragma omp flush seq_cst // expected-error {{unexpected OpenMP clause 'seq_cst' in directive '#pragma omp flush'}}
138137
#pragma omp flush acq_rel // omp45-error {{unexpected OpenMP clause 'acq_rel' in directive '#pragma omp flush'}}
139138
#pragma omp flush acquire // omp45-error {{unexpected OpenMP clause 'acquire' in directive '#pragma omp flush'}}
140139
#pragma omp flush release // omp45-error {{unexpected OpenMP clause 'release' in directive '#pragma omp flush'}}
141140
#pragma omp flush relaxed // expected-error {{unexpected OpenMP clause 'relaxed' in directive '#pragma omp flush'}}
142-
#pragma omp flush seq_cst // expected-error {{unexpected OpenMP clause 'seq_cst' in directive '#pragma omp flush'}}
143-
#pragma omp flush acq_rel acquire // omp45-error {{unexpected OpenMP clause 'acq_rel' in directive '#pragma omp flush'}} omp45-error {{unexpected OpenMP clause 'acquire' in directive '#pragma omp flush'}} omp51-error {{directive '#pragma omp flush' cannot contain more than one 'acq_rel', 'acquire' or 'release' clause}} omp51-note {{'acq_rel' clause used here}}
144-
#pragma omp flush release acquire // omp45-error {{unexpected OpenMP clause 'release' in directive '#pragma omp flush'}} omp45-error {{unexpected OpenMP clause 'acquire' in directive '#pragma omp flush'}} omp51-error {{directive '#pragma omp flush' cannot contain more than one 'acq_rel', 'acquire' or 'release' clause}} omp51-note {{'release' clause used here}}
141+
#pragma omp flush acq_rel acquire // omp45-error {{unexpected OpenMP clause 'acq_rel' in directive '#pragma omp flush'}} omp45-error {{unexpected OpenMP clause 'acquire' in directive '#pragma omp flush'}} omp51-error {{directive '#pragma omp flush' cannot contain more than one 'seq_cst', 'acq_rel', 'acquire' or 'release' clause}} omp51-note {{'acq_rel' clause used here}}
142+
#pragma omp flush release acquire // omp45-error {{unexpected OpenMP clause 'release' in directive '#pragma omp flush'}} omp45-error {{unexpected OpenMP clause 'acquire' in directive '#pragma omp flush'}} omp51-error {{directive '#pragma omp flush' cannot contain more than one 'seq_cst', 'acq_rel', 'acquire' or 'release' clause}} omp51-note {{'release' clause used here}}
145143
#pragma omp flush acq_rel (argc) // omp45-error {{unexpected OpenMP clause 'acq_rel' in directive '#pragma omp flush'}} expected-warning {{extra tokens at the end of '#pragma omp flush' are ignored}}
146144
#pragma omp flush(argc) acq_rel // omp45-error {{unexpected OpenMP clause 'acq_rel' in directive '#pragma omp flush'}} omp51-error {{'flush' directive with memory order clause 'acq_rel' cannot have the list}} omp51-note {{memory order clause 'acq_rel' is specified here}}
147145
return tmain(argc);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s -fopenmp-version=51 2>&1 | FileCheck %s
2+
3+
! CHECK: not yet implemented: Unhandled clause SEQ_CST in FLUSH construct
4+
program flush_seq_cst
5+
!$omp flush seq_cst
6+
end program

flang/test/Semantics/OpenMP/clause-validity01.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
! REQUIRES: openmp_runtime
22

3-
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags %openmp_module_flag -fopenmp-version=50
3+
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags %openmp_module_flag -fopenmp-version=51
44
use omp_lib
55
! Check OpenMP clause validity for the following directives:
66
!
@@ -507,7 +507,6 @@
507507
!$omp flush acquire
508508
!ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive
509509
!$omp flush release (c)
510-
!ERROR: SEQ_CST clause is not allowed on the FLUSH directive
511510
!$omp flush seq_cst
512511
!ERROR: RELAXED clause is not allowed on the FLUSH directive
513512
!$omp flush relaxed

flang/test/Semantics/OpenMP/flush02.f90

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
! REQUIRES: openmp_runtime
22

3-
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags -fopenmp-version=50
3+
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags -fopenmp-version=51
44

55
! Check OpenMP 5.0 - 2.17.8 flush Construct
66
! Restriction -
@@ -27,7 +27,6 @@
2727
!Only memory-order-clauses.
2828
if (omp_get_thread_num() == 1) THEN
2929
! Not allowed clauses.
30-
!ERROR: SEQ_CST clause is not allowed on the FLUSH directive
3130
!$omp flush seq_cst
3231
!ERROR: RELAXED clause is not allowed on the FLUSH directive
3332
!$omp flush relaxed
@@ -41,7 +40,6 @@
4140
!$omp flush acquire acquire
4241

4342
! Mix of allowed and not allowed.
44-
!ERROR: SEQ_CST clause is not allowed on the FLUSH directive
4543
!$omp flush seq_cst acquire
4644
END IF
4745

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ def OMP_Flush : Directive<"flush"> {
769769
// OMPKinds.def.
770770
VersionedClause<OMPC_Flush>,
771771
VersionedClause<OMPC_Release, 50>,
772+
VersionedClause<OMPC_SeqCst, 51>,
772773
];
773774
let association = AS_None;
774775
let category = CA_Executable;

0 commit comments

Comments
 (0)