[Mlir-commits] [flang] [mlir] [Flang][MLIR] Move setOpenMPIntegerWrapAround function into the OpenMP dialect (PR #217448)

Kaviya Rajendiran llvmlistbot at llvm.org
Tue Aug 25 02:30:00 PDT 2026


https://github.com/kaviya2510 updated https://github.com/llvm/llvm-project/pull/217448

>From 921e7eb0f0d4f5dd76507e592c0c1f5bbcb9c379 Mon Sep 17 00:00:00 2001
From: Kaviya Rajendiran <kaviyara2000 at gmail.com>
Date: Thu, 20 Aug 2026 01:08:46 +0530
Subject: [PATCH 1/2] [Flang] Link flangFrontendTool against MLIROpenMPDialect

---
 flang/lib/FrontendTool/CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/flang/lib/FrontendTool/CMakeLists.txt b/flang/lib/FrontendTool/CMakeLists.txt
index 323d2e73e9a36..8827201339b3c 100644
--- a/flang/lib/FrontendTool/CMakeLists.txt
+++ b/flang/lib/FrontendTool/CMakeLists.txt
@@ -17,6 +17,7 @@ add_flang_library(flangFrontendTool
 
   MLIR_LIBS
   MLIRPass
+  MLIROpenMPDialect
 
   CLANG_LIBS
   clangBasic

>From fe8b024dd302e8cf355e3e4092c77a9d5b68eeb0 Mon Sep 17 00:00:00 2001
From: Kaviya Rajendiran <kaviyara2000 at gmail.com>
Date: Tue, 25 Aug 2026 14:38:29 +0530
Subject: [PATCH 2/2] [Flang][MLIR] Move setOpenMPIntegerWrapAround(..)
 function into the OpenMP dialect

---
 flang/include/flang/Tools/CrossToolHelpers.h   | 6 ------
 flang/lib/Frontend/FrontendActions.cpp         | 2 +-
 flang/lib/FrontendTool/CMakeLists.txt          | 1 -
 flang/tools/bbc/bbc.cpp                        | 2 +-
 mlir/include/mlir/Dialect/OpenMP/Utils/Utils.h | 3 +++
 mlir/lib/Dialect/OpenMP/Utils/Utils.cpp        | 6 ++++++
 6 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h
index fb8007637b114..6569d34e0f255 100644
--- a/flang/include/flang/Tools/CrossToolHelpers.h
+++ b/flang/include/flang/Tools/CrossToolHelpers.h
@@ -206,10 +206,4 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks {
       Opts.NoGPULib);
 }
 
-[[maybe_unused]] static void setOpenMPIntegerWrapAround(
-    mlir::ModuleOp module, bool value) {
-  module.getOperation()->setAttr("omp.integer_wrap_around",
-      mlir::omp::IntegerWrapAroundAttr::get(module.getContext(), value));
-}
-
 #endif // FORTRAN_TOOLS_CROSS_TOOL_HELPERS_H
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 7ecda651027e2..8a2d1a6c2e2a2 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -278,7 +278,7 @@ bool CodeGenAction::beginSourceFileAction() {
     mlir::omp::setOpenMPVersionAttribute(
         lb.getModule(), ci.getInvocation().getLangOpts().OpenMPVersion);
     if (!ci.getInvocation().getLoweringOpts().getIntegerWrapAround())
-      setOpenMPIntegerWrapAround(lb.getModule(), false);
+      mlir::omp::setOpenMPIntegerWrapAround(lb.getModule(), false);
   }
 
   if (ci.getInvocation().getLangOpts().FastRealMod) {
diff --git a/flang/lib/FrontendTool/CMakeLists.txt b/flang/lib/FrontendTool/CMakeLists.txt
index 8827201339b3c..323d2e73e9a36 100644
--- a/flang/lib/FrontendTool/CMakeLists.txt
+++ b/flang/lib/FrontendTool/CMakeLists.txt
@@ -17,7 +17,6 @@ add_flang_library(flangFrontendTool
 
   MLIR_LIBS
   MLIRPass
-  MLIROpenMPDialect
 
   CLANG_LIBS
   clangBasic
diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index 7860a0fc77cf3..eddc0415b4257 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -546,7 +546,7 @@ static llvm::LogicalResult convertFortranSourceToMLIR(
                                                    offloadModuleOpts);
     mlir::omp::setOpenMPVersionAttribute(mlirModule, setOpenMPVersion);
     if (!integerWrapAround)
-      setOpenMPIntegerWrapAround(mlirModule, false);
+      mlir::omp::setOpenMPIntegerWrapAround(mlirModule, false);
   }
   burnside.lower(parseTree, semanticsContext);
   std::error_code ec;
diff --git a/mlir/include/mlir/Dialect/OpenMP/Utils/Utils.h b/mlir/include/mlir/Dialect/OpenMP/Utils/Utils.h
index 16b6970441ef6..ed156682b772b 100644
--- a/mlir/include/mlir/Dialect/OpenMP/Utils/Utils.h
+++ b/mlir/include/mlir/Dialect/OpenMP/Utils/Utils.h
@@ -67,6 +67,9 @@ void setOffloadModuleInterfaceAttributes(ModuleOp module,
 /// Adds or updates the omp.version attribute.
 void setOpenMPVersionAttribute(ModuleOp module, int64_t version);
 
+/// Add the omp.integer_wrap_around attribute.
+void setOpenMPIntegerWrapAround(ModuleOp module, bool value);
+
 /// Returns the value of the omp.version attribute, if present, or the fallback.
 int64_t getOpenMPVersionAttribute(ModuleOp module, int64_t fallback = -1);
 
diff --git a/mlir/lib/Dialect/OpenMP/Utils/Utils.cpp b/mlir/lib/Dialect/OpenMP/Utils/Utils.cpp
index 481efdba89e1e..5343905f1ffca 100644
--- a/mlir/lib/Dialect/OpenMP/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/OpenMP/Utils/Utils.cpp
@@ -47,6 +47,12 @@ void mlir::omp::setOpenMPVersionAttribute(ModuleOp module, int64_t version) {
       VersionAttr::get(module.getContext(), version));
 }
 
+void mlir::omp::setOpenMPIntegerWrapAround(ModuleOp module, bool value) {
+  module->setAttr(StringAttr::get(module.getContext(),
+                                  llvm::Twine{"omp.integer_wrap_around"}),
+                  IntegerWrapAroundAttr::get(module.getContext(), value));
+}
+
 int64_t mlir::omp::getOpenMPVersionAttribute(ModuleOp module,
                                              int64_t fallback) {
   if (Attribute verAttr = module->getAttr("omp.version"))



More information about the Mlir-commits mailing list