[clang] [clang][OpenMP] OpenMP 6.0 updates to restrictions with order/concurrent (PR #125621)
David Pagan via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 4 16:23:55 PST 2025
https://github.com/ddpagan updated https://github.com/llvm/llvm-project/pull/125621
>From deffda7ca37661781f1bae565ac8ae4a8fbba674 Mon Sep 17 00:00:00 2001
From: Dave Pagan <dave.pagan at amd.com>
Date: Fri, 31 Jan 2025 16:12:08 -0600
Subject: [PATCH 1/3] [clang][OpenMP] OpenMP 6.0 updates to restrictions with
order/concurrent
>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
---
clang/include/clang/Basic/OpenMPKinds.h | 8 +++++++
clang/lib/Basic/OpenMPKinds.cpp | 6 +++++
clang/lib/Sema/SemaOpenMP.cpp | 30 +++++++++++++++++-------
clang/test/OpenMP/for_order_messages.cpp | 12 ++++++----
4 files changed, 44 insertions(+), 12 deletions(-)
diff --git a/clang/include/clang/Basic/OpenMPKinds.h b/clang/include/clang/Basic/OpenMPKinds.h
index 3e5da2a6abc017..e80bce34a97e03 100644
--- a/clang/include/clang/Basic/OpenMPKinds.h
+++ b/clang/include/clang/Basic/OpenMPKinds.h
@@ -399,6 +399,14 @@ bool isOpenMPInformationalDirective(OpenMPDirectiveKind DKind);
/// \return true - if the above condition is met for this directive
/// otherwise - false.
bool isOpenMPCapturingDirective(OpenMPDirectiveKind DKind);
+
+/// Checks if the specified directive is an order concurrent nestable
+/// directive that can be nested within region corresponding to construct
+/// on which order clause was specified with concurrent as ordering argument.
+/// \param DKind Specified directive.
+/// \return true - if the above condition is met for this directive
+/// otherwise - false.
+bool isOpenMPOrderConcurrentNestableDirective(OpenMPDirectiveKind DKind);
}
template <>
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 62a13f01481b28..8398eabceb82fe 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -765,6 +765,12 @@ bool clang::isOpenMPCapturingDirective(OpenMPDirectiveKind DKind) {
return false;
}
+bool clang::isOpenMPOrderConcurrentNestableDirective(OpenMPDirectiveKind DKind) {
+ return DKind == OMPD_atomic || DKind == OMPD_loop ||
+ DKind == OMPD_simd || DKind == OMPD_parallel ||
+ isOpenMPLoopTransformationDirective(DKind);
+}
+
void clang::getOpenMPCaptureRegions(
SmallVectorImpl<OpenMPDirectiveKind> &CaptureRegions,
OpenMPDirectiveKind DKind) {
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index b83b2b12f4a230..3bba93c9560041 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -4788,13 +4788,26 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
getLeafOrCompositeConstructs(ParentRegion, LeafOrComposite);
OpenMPDirectiveKind EnclosingConstruct = ParentLOC.back();
- if (SemaRef.LangOpts.OpenMP >= 51 && Stack->isParentOrderConcurrent() &&
- CurrentRegion != OMPD_simd && CurrentRegion != OMPD_loop &&
- CurrentRegion != OMPD_parallel &&
- !isOpenMPCombinedParallelADirective(CurrentRegion)) {
- SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_order)
- << getOpenMPDirectiveName(CurrentRegion);
- return true;
+ if (Stack->isParentOrderConcurrent()) {
+ bool InvalidOrderNesting = false;
+ if ((SemaRef.LangOpts.OpenMP == 51 || SemaRef.LangOpts.OpenMP == 52) &&
+ CurrentRegion != OMPD_simd &&
+ CurrentRegion != OMPD_loop && CurrentRegion != OMPD_parallel &&
+ !isOpenMPCombinedParallelADirective(CurrentRegion)) {
+ InvalidOrderNesting = true;
+ } else if (SemaRef.LangOpts.OpenMP >= 60 &&
+ !isOpenMPOrderConcurrentNestableDirective(CurrentRegion)) {
+ // OpenMP 6.0 [12.3 order Clause, Restrictions]
+ // Only regions that correspond to order-concurrent-nestable constructs
+ // or order-concurrent-nestable routines may be strictly nested regions
+ // of regions that correspond to constructs on which the order clause is
+ // specified with concurrent as the ordering argument.
+ InvalidOrderNesting = true;
+ }
+ if (InvalidOrderNesting) {
+ SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_order)
+ << getOpenMPDirectiveName(CurrentRegion);
+ }
}
if (isOpenMPSimdDirective(ParentRegion) &&
((SemaRef.LangOpts.OpenMP <= 45 && CurrentRegion != OMPD_ordered) ||
@@ -7114,7 +7127,8 @@ ExprResult SemaOpenMP::ActOnOpenMPCall(ExprResult Call, Scope *Scope,
if (!CalleeFnDecl)
return Call;
- if (getLangOpts().OpenMP >= 51 && CalleeFnDecl->getIdentifier() &&
+ if (getLangOpts().OpenMP >= 51 && getLangOpts().OpenMP < 60 &&
+ CalleeFnDecl->getIdentifier() &&
CalleeFnDecl->getName().starts_with_insensitive("omp_")) {
// checking for any calls inside an Order region
if (Scope && Scope->isOpenMPOrderClauseScope())
diff --git a/clang/test/OpenMP/for_order_messages.cpp b/clang/test/OpenMP/for_order_messages.cpp
index d38f48d2004f08..78caebf55e99cf 100644
--- a/clang/test/OpenMP/for_order_messages.cpp
+++ b/clang/test/OpenMP/for_order_messages.cpp
@@ -1,8 +1,12 @@
// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=50 -triple x86_64-unknown-unknown -verify=expected,omp50 %s -Wuninitialized
-// RUN: %clang_cc1 -fsyntax-only -fopenmp -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
+// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=51 -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
+// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=52 -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
+// RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=60 -triple x86_64-unknown-unknown -verify=expected,omp60 %s -Wuninitialized
// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=50 -triple x86_64-unknown-unknown -verify=expected,omp50 %s -Wuninitialized
-// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
+// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=51 -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
+// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=52 -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
+// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=60 -triple x86_64-unknown-unknown -verify=expected,omp60 %s -Wuninitialized
extern int omp_get_num_threads (void);
@@ -35,13 +39,13 @@ int main(int argc, char **argv) {
#pragma omp parallel for order(reproducible: concurrent) // omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
for (int i = 0; i < 10; ++i) {
-#pragma omp target //omp51-error {{construct 'target' not allowed in a region associated with a directive with 'order' clause}}
+#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}}
A++;
}
#pragma omp parallel for order(unconstrained: concurrent) // omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
for (int i = 0; i < 10; ++i) {
-#pragma omp target //omp51-error {{construct 'target' not allowed in a region associated with a directive with 'order' clause}}
+#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}}
A++;
}
}
>From d0b9502ca47e47ebba5026474a9e8445078288eb Mon Sep 17 00:00:00 2001
From: Dave Pagan <dave.pagan at amd.com>
Date: Mon, 3 Feb 2025 21:33:41 -0600
Subject: [PATCH 2/3] Fix formatting issues.
---
clang/lib/Basic/OpenMPKinds.cpp | 8 ++++----
clang/lib/Sema/SemaOpenMP.cpp | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 8398eabceb82fe..956d92a7e95f04 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -765,10 +765,10 @@ bool clang::isOpenMPCapturingDirective(OpenMPDirectiveKind DKind) {
return false;
}
-bool clang::isOpenMPOrderConcurrentNestableDirective(OpenMPDirectiveKind DKind) {
- return DKind == OMPD_atomic || DKind == OMPD_loop ||
- DKind == OMPD_simd || DKind == OMPD_parallel ||
- isOpenMPLoopTransformationDirective(DKind);
+bool clang::isOpenMPOrderConcurrentNestableDirective(
+ OpenMPDirectiveKind DKind) {
+ return DKind == OMPD_atomic || DKind == OMPD_loop || DKind == OMPD_simd ||
+ DKind == OMPD_parallel || isOpenMPLoopTransformationDirective(DKind);
}
void clang::getOpenMPCaptureRegions(
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 3bba93c9560041..8d8405c6963cb3 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -4789,14 +4789,14 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
OpenMPDirectiveKind EnclosingConstruct = ParentLOC.back();
if (Stack->isParentOrderConcurrent()) {
- bool InvalidOrderNesting = false;
+ bool InvalidOrderNesting = false;
if ((SemaRef.LangOpts.OpenMP == 51 || SemaRef.LangOpts.OpenMP == 52) &&
- CurrentRegion != OMPD_simd &&
- CurrentRegion != OMPD_loop && CurrentRegion != OMPD_parallel &&
+ CurrentRegion != OMPD_simd && CurrentRegion != OMPD_loop &&
+ CurrentRegion != OMPD_parallel &&
!isOpenMPCombinedParallelADirective(CurrentRegion)) {
InvalidOrderNesting = true;
} else if (SemaRef.LangOpts.OpenMP >= 60 &&
- !isOpenMPOrderConcurrentNestableDirective(CurrentRegion)) {
+ !isOpenMPOrderConcurrentNestableDirective(CurrentRegion)) {
// OpenMP 6.0 [12.3 order Clause, Restrictions]
// Only regions that correspond to order-concurrent-nestable constructs
// or order-concurrent-nestable routines may be strictly nested regions
>From ddda2b2cbdcfb4a47cd4f5ae1ca3d006a8beb486 Mon Sep 17 00:00:00 2001
From: Dave Pagan <dave.pagan at amd.com>
Date: Tue, 4 Feb 2025 18:17:43 -0600
Subject: [PATCH 3/3] Added tests for directives no longer allowed to be nested
in order(concurrent) regions in OpenMP 6.0
---
clang/test/OpenMP/for_order_messages.cpp | 48 ++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/clang/test/OpenMP/for_order_messages.cpp b/clang/test/OpenMP/for_order_messages.cpp
index 78caebf55e99cf..530c0518492014 100644
--- a/clang/test/OpenMP/for_order_messages.cpp
+++ b/clang/test/OpenMP/for_order_messages.cpp
@@ -48,4 +48,52 @@ int main(int argc, char **argv) {
#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}}
A++;
}
+
+#pragma omp loop bind(parallel) order(concurrent)
+ for (int i = 0; i < 10; ++i) {
+#pragma omp parallel for //omp60-error {{construct 'parallel for' not allowed in a region associated with a directive with 'order' clause}}
+ for (int j = 0; j < 10; ++j) {
+ A += j;
+ }
+ }
+
+#pragma omp distribute order(concurrent)
+ for (int i = 0; i < 10; ++i) {
+#pragma omp parallel for simd //omp60-error {{construct 'parallel for simd' not allowed in a region associated with a directive with 'order' clause}}
+ for (int j = 0; j < 10; ++j) {
+ A += j;
+ }
+ }
+
+#pragma omp for order(concurrent)
+ for (int i = 0; i < 10; ++i) {
+#pragma omp parallel master //omp60-error {{construct 'parallel master' not allowed in a region associated with a directive with 'order' clause}}
+ for (int j = 0; j < 10; ++j) {
+ A += j;
+ }
+ }
+
+#pragma omp for order(concurrent)
+ for (int i = 0; i < 10; ++i) {
+#pragma omp parallel master taskloop //omp60-error {{construct 'parallel master taskloop' not allowed in a region associated with a directive with 'order' clause}}
+ for (int j = 0; j < 10; ++j) {
+ A += j;
+ }
+ }
+
+#pragma omp for order(concurrent)
+ for (int i = 0; i < 10; ++i) {
+#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}}
+ for (int j = 0; j < 10; ++j) {
+ A += j;
+ }
+ }
+
+#pragma omp for order(concurrent)
+ for (int i = 0; i < 10; ++i) {
+ #pragma omp parallel sections //omp60-error {{construct 'parallel sections' not allowed in a region associated with a directive with 'order' clause}}
+ {
+ A++;
+ }
+ }
}
More information about the cfe-commits
mailing list