[clang] [clang][OpenMP] Implement `isOpenMPExecutableDirective` (PR #97089)
Krzysztof Parzyszek via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 28 11:22:43 PDT 2024
https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/97089
>From 789ec614d285e3fe632aae6280f6c4cf01746cdf Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Fri, 28 Jun 2024 12:27:10 -0500
Subject: [PATCH 1/2] [clang][OpenMP] Implement `isOpenMPExecutableDirective`
What is considered "executable" in clang differs slightly from the
OpenMP's "executable" category. In addition to the executable
category, subsidiary directives, and OMPD_error are considered
executable.
Implement a function that performs that check.
---
clang/include/clang/Basic/OpenMPKinds.h | 8 ++++++++
clang/lib/Basic/OpenMPKinds.cpp | 7 +++++++
clang/lib/Parse/ParseOpenMP.cpp | 6 ++----
clang/lib/Sema/SemaOpenMP.cpp | 2 ++
4 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/clang/include/clang/Basic/OpenMPKinds.h b/clang/include/clang/Basic/OpenMPKinds.h
index d127498774c7f..6d9d6ebc58e2c 100644
--- a/clang/include/clang/Basic/OpenMPKinds.h
+++ b/clang/include/clang/Basic/OpenMPKinds.h
@@ -368,6 +368,14 @@ bool needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind);
/// is restricted only to memory order clauses of "OMPC_acquire",
/// "OMPC_relaxed" and "OMPC_seq_cst".
bool checkFailClauseParameter(OpenMPClauseKind FailClauseParameter);
+
+/// Checks if the specified directive is considered as "executable". This
+/// combines the OpenMP categories of "executable" and "subsidiary", plus
+/// any other directives that are should be treated as executable.
+/// \param DKind Specified directive.
+/// \return true - if the above condition is met for this directive
+/// otherwise - false.
+bool isOpenMPExecutableDirective(OpenMPDirectiveKind DKind);
}
#endif
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index b3e9affbb3e58..7c8990880fae3 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -702,6 +702,13 @@ bool clang::needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind) {
DKind == OMPD_target_parallel_loop;
}
+bool clang::isOpenMPExecutableDirective(OpenMPDirectiveKind DKind) {
+ if (DKind == OMPD_error)
+ return true;
+ Category Cat = getDirectiveCategory(DKind);
+ return Cat == Category::Executable || Cat == Category::Subsidiary;
+}
+
void clang::getOpenMPCaptureRegions(
SmallVectorImpl<OpenMPDirectiveKind> &CaptureRegions,
OpenMPDirectiveKind DKind) {
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 00f9ebb65d876..326cd22ff9005 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2397,10 +2397,8 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
StmtResult Parser::ParseOpenMPExecutableDirective(
ParsedStmtContext StmtCtx, OpenMPDirectiveKind DKind, SourceLocation Loc,
bool ReadDirectiveWithinMetadirective) {
- assert((DKind == OMPD_error ||
- getDirectiveCategory(DKind) == Category::Executable ||
- getDirectiveCategory(DKind) == Category::Subsidiary) &&
- "Directive with an unexpected category");
+ assert(isOpenMPExecutableDirective(DKind) && "Unexpected directive category");
+
bool HasAssociatedStatement = true;
Association Assoc = getDirectiveAssociation(DKind);
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 29104b2c0de94..b17c7e2be968e 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -6357,6 +6357,8 @@ StmtResult SemaOpenMP::ActOnOpenMPExecutableDirective(
OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc,
OpenMPDirectiveKind PrevMappedDirective) {
+ assert(isOpenMPExecutableDirective(Kind) && "Unexpected directive category");
+
StmtResult Res = StmtError();
OpenMPBindClauseKind BindKind = OMPC_BIND_unknown;
llvm::SmallVector<OMPClause *> ClausesWithoutBind;
>From 1d5ca2e5309924bc9d4e1bf1f382b08ad6b20805 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Fri, 28 Jun 2024 13:22:11 -0500
Subject: [PATCH 2/2] Fix wording
---
clang/include/clang/Basic/OpenMPKinds.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/include/clang/Basic/OpenMPKinds.h b/clang/include/clang/Basic/OpenMPKinds.h
index 6d9d6ebc58e2c..29a852d666511 100644
--- a/clang/include/clang/Basic/OpenMPKinds.h
+++ b/clang/include/clang/Basic/OpenMPKinds.h
@@ -371,7 +371,7 @@ bool checkFailClauseParameter(OpenMPClauseKind FailClauseParameter);
/// Checks if the specified directive is considered as "executable". This
/// combines the OpenMP categories of "executable" and "subsidiary", plus
-/// any other directives that are should be treated as executable.
+/// any other directives that should be treated as executable.
/// \param DKind Specified directive.
/// \return true - if the above condition is met for this directive
/// otherwise - false.
More information about the cfe-commits
mailing list