[llvm] [Frontend][OpenMP] Add functions for checking construct type (PR #87076)

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 29 08:04:39 PDT 2024


https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/87076

>From 9935ba849b55dfa2bc622b628c2e1609b5fdf10d Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Mon, 11 Mar 2024 12:55:38 -0500
Subject: [PATCH] [Frontend][OpenMP] Add functions for checking construct type

Implement helper functions to identify leaf, composite, and combined
constructs.
---
 llvm/include/llvm/Frontend/OpenMP/OMP.h |  6 ++++++
 llvm/lib/Frontend/OpenMP/OMP.cpp        | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+)

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..0ef12cb106426e 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,24 @@ 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



More information about the llvm-commits mailing list