Skip to content

Commit 659d1fe

Browse files
authored
[clang][OpenMP] OpenMP 6.0 updates to restrictions with order/concurrent (#125621)
From OpenMP 6.0 features list - OpenMP directives in concurrent loop regions - atomics constructs on concurrent loop regions - Lift nesting restriction on concurrent loop Testing - Updated test/OpenMP/for_order_messages.cpp - check-all
1 parent 6f750cf commit 659d1fe

File tree

4 files changed

+92
-12
lines changed

4 files changed

+92
-12
lines changed

clang/include/clang/Basic/OpenMPKinds.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,14 @@ bool isOpenMPInformationalDirective(OpenMPDirectiveKind DKind);
399399
/// \return true - if the above condition is met for this directive
400400
/// otherwise - false.
401401
bool isOpenMPCapturingDirective(OpenMPDirectiveKind DKind);
402+
403+
/// Checks if the specified directive is an order concurrent nestable
404+
/// directive that can be nested within region corresponding to construct
405+
/// on which order clause was specified with concurrent as ordering argument.
406+
/// \param DKind Specified directive.
407+
/// \return true - if the above condition is met for this directive
408+
/// otherwise - false.
409+
bool isOpenMPOrderConcurrentNestableDirective(OpenMPDirectiveKind DKind);
402410
}
403411

404412
template <>

clang/lib/Basic/OpenMPKinds.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,12 @@ bool clang::isOpenMPCapturingDirective(OpenMPDirectiveKind DKind) {
765765
return false;
766766
}
767767

768+
bool clang::isOpenMPOrderConcurrentNestableDirective(
769+
OpenMPDirectiveKind DKind) {
770+
return DKind == OMPD_atomic || DKind == OMPD_loop || DKind == OMPD_simd ||
771+
DKind == OMPD_parallel || isOpenMPLoopTransformationDirective(DKind);
772+
}
773+
768774
void clang::getOpenMPCaptureRegions(
769775
SmallVectorImpl<OpenMPDirectiveKind> &CaptureRegions,
770776
OpenMPDirectiveKind DKind) {

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4788,13 +4788,26 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
47884788
getLeafOrCompositeConstructs(ParentRegion, LeafOrComposite);
47894789
OpenMPDirectiveKind EnclosingConstruct = ParentLOC.back();
47904790

4791-
if (SemaRef.LangOpts.OpenMP >= 51 && Stack->isParentOrderConcurrent() &&
4792-
CurrentRegion != OMPD_simd && CurrentRegion != OMPD_loop &&
4793-
CurrentRegion != OMPD_parallel &&
4794-
!isOpenMPCombinedParallelADirective(CurrentRegion)) {
4795-
SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_order)
4796-
<< getOpenMPDirectiveName(CurrentRegion);
4797-
return true;
4791+
if (Stack->isParentOrderConcurrent()) {
4792+
bool InvalidOrderNesting = false;
4793+
if ((SemaRef.LangOpts.OpenMP == 51 || SemaRef.LangOpts.OpenMP == 52) &&
4794+
CurrentRegion != OMPD_simd && CurrentRegion != OMPD_loop &&
4795+
CurrentRegion != OMPD_parallel &&
4796+
!isOpenMPCombinedParallelADirective(CurrentRegion)) {
4797+
InvalidOrderNesting = true;
4798+
} else if (SemaRef.LangOpts.OpenMP >= 60 &&
4799+
!isOpenMPOrderConcurrentNestableDirective(CurrentRegion)) {
4800+
// OpenMP 6.0 [12.3 order Clause, Restrictions]
4801+
// Only regions that correspond to order-concurrent-nestable constructs
4802+
// or order-concurrent-nestable routines may be strictly nested regions
4803+
// of regions that correspond to constructs on which the order clause is
4804+
// specified with concurrent as the ordering argument.
4805+
InvalidOrderNesting = true;
4806+
}
4807+
if (InvalidOrderNesting) {
4808+
SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_order)
4809+
<< getOpenMPDirectiveName(CurrentRegion);
4810+
}
47984811
}
47994812
if (isOpenMPSimdDirective(ParentRegion) &&
48004813
((SemaRef.LangOpts.OpenMP <= 45 && CurrentRegion != OMPD_ordered) ||
@@ -7114,7 +7127,8 @@ ExprResult SemaOpenMP::ActOnOpenMPCall(ExprResult Call, Scope *Scope,
71147127
if (!CalleeFnDecl)
71157128
return Call;
71167129

7117-
if (getLangOpts().OpenMP >= 51 && CalleeFnDecl->getIdentifier() &&
7130+
if (getLangOpts().OpenMP >= 51 && getLangOpts().OpenMP < 60 &&
7131+
CalleeFnDecl->getIdentifier() &&
71187132
CalleeFnDecl->getName().starts_with_insensitive("omp_")) {
71197133
// checking for any calls inside an Order region
71207134
if (Scope && Scope->isOpenMPOrderClauseScope())

clang/test/OpenMP/for_order_messages.cpp

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=50 -triple x86_64-unknown-unknown -verify=expected,omp50 %s -Wuninitialized
2-
// RUN: %clang_cc1 -fsyntax-only -fopenmp -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
2+
// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=51 -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
3+
// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=52 -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
4+
// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=60 -triple x86_64-unknown-unknown -verify=expected,omp60 %s -Wuninitialized
35

46
// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=50 -triple x86_64-unknown-unknown -verify=expected,omp50 %s -Wuninitialized
5-
// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
7+
// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=51 -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
8+
// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
9+
// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=60 -triple x86_64-unknown-unknown -verify=expected,omp60 %s -Wuninitialized
610

711
extern int omp_get_num_threads (void);
812

@@ -35,13 +39,61 @@ int main(int argc, char **argv) {
3539

3640
#pragma omp parallel for order(reproducible: concurrent) // omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
3741
for (int i = 0; i < 10; ++i) {
38-
#pragma omp target //omp51-error {{construct 'target' not allowed in a region associated with a directive with 'order' clause}}
42+
#pragma omp target //omp51-error {{construct 'target' not allowed in a region associated with a directive with 'order' clause}} omp60-error {{construct 'target' not allowed in a region associated with a directive with 'order' clause}}
3943
A++;
4044
}
4145

4246
#pragma omp parallel for order(unconstrained: concurrent) // omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
4347
for (int i = 0; i < 10; ++i) {
44-
#pragma omp target //omp51-error {{construct 'target' not allowed in a region associated with a directive with 'order' clause}}
48+
#pragma omp target //omp51-error {{construct 'target' not allowed in a region associated with a directive with 'order' clause}} omp60-error {{construct 'target' not allowed in a region associated with a directive with 'order' clause}}
4549
A++;
4650
}
51+
52+
#pragma omp loop bind(parallel) order(concurrent)
53+
for (int i = 0; i < 10; ++i) {
54+
#pragma omp parallel for //omp60-error {{construct 'parallel for' not allowed in a region associated with a directive with 'order' clause}}
55+
for (int j = 0; j < 10; ++j) {
56+
A += j;
57+
}
58+
}
59+
60+
#pragma omp distribute order(concurrent)
61+
for (int i = 0; i < 10; ++i) {
62+
#pragma omp parallel for simd //omp60-error {{construct 'parallel for simd' not allowed in a region associated with a directive with 'order' clause}}
63+
for (int j = 0; j < 10; ++j) {
64+
A += j;
65+
}
66+
}
67+
68+
#pragma omp for order(concurrent)
69+
for (int i = 0; i < 10; ++i) {
70+
#pragma omp parallel master //omp60-error {{construct 'parallel master' not allowed in a region associated with a directive with 'order' clause}}
71+
for (int j = 0; j < 10; ++j) {
72+
A += j;
73+
}
74+
}
75+
76+
#pragma omp for order(concurrent)
77+
for (int i = 0; i < 10; ++i) {
78+
#pragma omp parallel master taskloop //omp60-error {{construct 'parallel master taskloop' not allowed in a region associated with a directive with 'order' clause}}
79+
for (int j = 0; j < 10; ++j) {
80+
A += j;
81+
}
82+
}
83+
84+
#pragma omp for order(concurrent)
85+
for (int i = 0; i < 10; ++i) {
86+
#pragma omp parallel master taskloop simd //omp60-error {{construct 'parallel master taskloop simd' not allowed in a region associated with a directive with 'order' clause}}
87+
for (int j = 0; j < 10; ++j) {
88+
A += j;
89+
}
90+
}
91+
92+
#pragma omp for order(concurrent)
93+
for (int i = 0; i < 10; ++i) {
94+
#pragma omp parallel sections //omp60-error {{construct 'parallel sections' not allowed in a region associated with a directive with 'order' clause}}
95+
{
96+
A++;
97+
}
98+
}
4799
}

0 commit comments

Comments
 (0)