[flang-commits] [flang] [mlir] [NFC][OpenMP][mlir][flang] Move OMP offloading module attribute handling from flang to mlir (PR #186409)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Thu Mar 19 07:16:00 PDT 2026


================
@@ -0,0 +1,105 @@
+//===- OpenMPOffloadUtils.h - OpenMP offload utilities ----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Shared utilities for setting OpenMP offload module interface attributes.
+// These are used by both Flang and Clang (CIR) frontends.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_DIALECT_OPENMP_OPENMPOFFLOADUTILS_H_
+#define MLIR_DIALECT_OPENMP_OPENMPOFFLOADUTILS_H_
+
+#include "mlir/Dialect/OpenMP/OpenMPInterfaces.h"
+#include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/TargetParser/Triple.h"
+#include <cstdint>
+#include <string>
+#include <vector>
+
+namespace mlir::omp {
+
+struct OffloadModuleOpts {
+  OffloadModuleOpts() = default;
+  OffloadModuleOpts(uint32_t openMPTargetDebug, bool openMPTeamSubscription,
+                    bool openMPThreadSubscription, bool openMPNoThreadState,
+                    bool openMPNoNestedParallelism, bool openMPIsTargetDevice,
+                    bool openMPIsGPU, bool openMPForceUSM,
+                    uint32_t openMPVersion, std::string ompHostIRFile = {},
+                    const std::vector<llvm::Triple> &ompTargetTriples = {},
+                    bool noGPULib = false)
+      : OpenMPTargetDebug(openMPTargetDebug),
+        OpenMPTeamSubscription(openMPTeamSubscription),
+        OpenMPThreadSubscription(openMPThreadSubscription),
+        OpenMPNoThreadState(openMPNoThreadState),
+        OpenMPNoNestedParallelism(openMPNoNestedParallelism),
+        OpenMPIsTargetDevice(openMPIsTargetDevice), OpenMPIsGPU(openMPIsGPU),
+        OpenMPForceUSM(openMPForceUSM), OpenMPVersion(openMPVersion),
+        OMPHostIRFile(std::move(ompHostIRFile)),
+        OMPTargetTriples(ompTargetTriples.begin(), ompTargetTriples.end()),
+        NoGPULib(noGPULib) {}
+
+  uint32_t OpenMPTargetDebug = 0;
+  bool OpenMPTeamSubscription = false;
+  bool OpenMPThreadSubscription = false;
+  bool OpenMPNoThreadState = false;
+  bool OpenMPNoNestedParallelism = false;
+  bool OpenMPIsTargetDevice = false;
+  bool OpenMPIsGPU = false;
+  bool OpenMPForceUSM = false;
+  uint32_t OpenMPVersion = 31;
+  std::string OMPHostIRFile = {};
+  std::vector<llvm::Triple> OMPTargetTriples = {};
+  bool NoGPULib = false;
+};
+
+/// Sets OpenMP offload module interface attributes on a ModuleOp, shared
+/// between Flang and Clang (CIR) frontends.
+[[maybe_unused]] static void
+setOffloadModuleInterfaceAttributes(mlir::ModuleOp module,
----------------
skatrak wrote:

Nit: We don't need to specify `mlir::` or `mlir::omp` here anymore, since we're already inside of that namespace.

https://github.com/llvm/llvm-project/pull/186409


More information about the flang-commits mailing list