Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Frontend][OpenMP] Add functions for checking construct type #87076

Closed
wants to merge 2 commits into from

Conversation

kparzysz
Copy link
Contributor

Implement helper functions to identify leaf, composite, and combined constructs.

@kparzysz kparzysz requested a review from skatrak March 29, 2024 15:00
@llvmbot llvmbot added flang:openmp clang:openmp OpenMP related changes to Clang labels Mar 29, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 29, 2024

@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)

Changes

Implement helper functions to identify leaf, composite, and combined constructs.


Full diff: https://github.com/llvm/llvm-project/pull/87076.diff

2 Files Affected:

  • (modified) llvm/include/llvm/Frontend/OpenMP/OMP.h (+6)
  • (modified) llvm/lib/Frontend/OpenMP/OMP.cpp (+25)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.h b/llvm/include/llvm/Frontend/OpenMP/OMP.h
index a85cd9d344c6d7..36fe77a94de7c7 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.h
@@ -15,4 +15,10 @@
 
 #include "llvm/Frontend/OpenMP/OMP.h.inc"
 
+namespace llvm::omp {
+bool isLeafConstruct(Directive D);
+bool isCompositeConstruct(Directive D);
+bool isCombinedConstruct(Directive D);
+} // namespace llvm::omp
+
 #endif // LLVM_FRONTEND_OPENMP_OMP_H
diff --git a/llvm/lib/Frontend/OpenMP/OMP.cpp b/llvm/lib/Frontend/OpenMP/OMP.cpp
index 4f2f95392648b3..07f33785495681 100644
--- a/llvm/lib/Frontend/OpenMP/OMP.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMP.cpp
@@ -8,6 +8,7 @@
 
 #include "llvm/Frontend/OpenMP/OMP.h"
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -17,3 +18,27 @@ using namespace omp;
 
 #define GEN_DIRECTIVES_IMPL
 #include "llvm/Frontend/OpenMP/OMP.inc"
+
+namespace llvm::omp {
+bool isLeafConstruct(Directive D) {
+  return getLeafConstructs(D).empty();
+}
+
+bool isCompositeConstruct(Directive D) {
+  // OpenMP Spec 5.2: [17.3, 8-9]
+  // If directive-name-A and directive-name-B both correspond to loop-
+  // associated constructs then directive-name is a composite construct
+  size_t numLoopConstructs =
+      llvm::count_if(getLeafConstructs(D), [](Directive L) {
+        return getDirectiveAssociation(L) == Association::Loop;
+      });
+  return numLoopConstructs > 1;
+}
+
+bool isCombinedConstruct(Directive D) {
+  // OpenMP Spec 5.2: [17.3, 9-10]
+  // Otherwise directive-name is a combined construct.
+  return !getLeafConstructs(D).empty() && !isCompositeConstruct(D);
+}
+
+} // namespace llvm::omp

Copy link

github-actions bot commented Mar 29, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Implement helper functions to identify leaf, composite, and combined
constructs.
@kparzysz kparzysz force-pushed the users/kparzysz/spr/construct-type branch from 16366ac to 9935ba8 Compare March 29, 2024 15:04
@kparzysz kparzysz marked this pull request as draft March 29, 2024 16:48
@kparzysz
Copy link
Contributor Author

kparzysz commented Apr 1, 2024

Replaced by #87258.

@kparzysz kparzysz closed this Apr 1, 2024
@kparzysz kparzysz deleted the users/kparzysz/spr/construct-type branch April 1, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:openmp OpenMP related changes to Clang flang:openmp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants