[llvm] [Frontend][OpenMP] Add functions for checking construct type (PR #87076)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 29 08:01:33 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-openmp
Author: Krzysztof Parzyszek (kparzysz)
<details>
<summary>Changes</summary>
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
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/87076
More information about the llvm-commits
mailing list