[flang-commits] [flang] [flang][OpenMP] Implement getOpenMPVersion helper function, NFC (PR #90086)

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Fri Apr 26 08:37:18 PDT 2024


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

>From 4cf41a60afacefbbc7098309ba1f099b867a8806 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Tue, 26 Mar 2024 09:58:18 -0500
Subject: [PATCH 1/2] [flang][OpenMP] Implement getOpenMPVersion helper
 function, NFC

---
 flang/lib/Lower/OpenMP/Utils.cpp | 6 ++++++
 flang/lib/Lower/OpenMP/Utils.h   | 1 +
 2 files changed, 7 insertions(+)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index da3f2be73e5095..1400f1f4cc8dd2 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -47,6 +47,12 @@ int64_t getCollapseValue(const List<Clause> &clauses) {
   return 1;
 }
 
+uint32_t getOpenMPVersion(mlir::ModuleOp mod) {
+  if (mlir::Attribute verAttr = mod->getAttr("omp.version"))
+    return llvm::cast<mlir::omp::VersionAttr>(verAttr).getVersion();
+  llvm_unreachable("Expecting OpenMP version attribute in module");
+}
+
 void genObjectList(const ObjectList &objects,
                    Fortran::lower::AbstractConverter &converter,
                    llvm::SmallVectorImpl<mlir::Value> &operands) {
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index b3a9f7f30c98bd..693a91f7cc6954 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -59,6 +59,7 @@ void gatherFuncAndVarSyms(
     llvm::SmallVectorImpl<DeclareTargetCapturePair> &symbolAndClause);
 
 int64_t getCollapseValue(const List<Clause> &clauses);
+uint32_t getOpenMPVersion(mlir::ModuleOp mod);
 
 Fortran::semantics::Symbol *
 getOmpObjectSymbol(const Fortran::parser::OmpObject &ompObject);

>From 15586c432463faf5f8688570536fb3dff75d2731 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Fri, 26 Apr 2024 10:36:27 -0500
Subject: [PATCH 2/2] Return a fallback value instead of crashing if no version
 present

---
 flang/lib/Lower/OpenMP/Utils.cpp | 4 ++--
 flang/lib/Lower/OpenMP/Utils.h   | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 1400f1f4cc8dd2..e4f6fa027ec938 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -47,10 +47,10 @@ int64_t getCollapseValue(const List<Clause> &clauses) {
   return 1;
 }
 
-uint32_t getOpenMPVersion(mlir::ModuleOp mod) {
+uint32_t getOpenMPVersion(mlir::ModuleOp mod, uint32_t fallback) {
   if (mlir::Attribute verAttr = mod->getAttr("omp.version"))
     return llvm::cast<mlir::omp::VersionAttr>(verAttr).getVersion();
-  llvm_unreachable("Expecting OpenMP version attribute in module");
+  return fallback;
 }
 
 void genObjectList(const ObjectList &objects,
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index 693a91f7cc6954..3007aeee11af18 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -59,7 +59,7 @@ void gatherFuncAndVarSyms(
     llvm::SmallVectorImpl<DeclareTargetCapturePair> &symbolAndClause);
 
 int64_t getCollapseValue(const List<Clause> &clauses);
-uint32_t getOpenMPVersion(mlir::ModuleOp mod);
+uint32_t getOpenMPVersion(mlir::ModuleOp mod, uint32_t fallback = ~0u);
 
 Fortran::semantics::Symbol *
 getOmpObjectSymbol(const Fortran::parser::OmpObject &ompObject);



More information about the flang-commits mailing list