[Mlir-commits] [flang] [mlir] Reland "[mlir][LLVMIR] Decouple ModuleTranslation from the OpenMP dialect" (PR #237979)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Nov 2 05:50:20 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir

@llvm/pr-subscribers-mlir-openmp

Author: Markus Böck (zero9178)

<details>
<summary>Changes</summary>

Relands https://github.com/llvm/llvm-project/pull/236777 with fixed cmake dependencies

---

Patch is 70.97 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/237979.diff


11 Files Affected:

- (modified) flang/include/flang/Optimizer/Support/InitFIR.h (+1) 
- (modified) flang/lib/Optimizer/Dialect/CMakeLists.txt (+1) 
- (modified) mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h (+35-50) 
- (modified) mlir/lib/Dialect/LLVMIR/CMakeLists.txt (-2) 
- (modified) mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp (+1) 
- (modified) mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt (-1) 
- (modified) mlir/lib/Target/LLVMIR/CMakeLists.txt (-2) 
- (modified) mlir/lib/Target/LLVMIR/Dialect/OpenMP/CMakeLists.txt (+2) 
- (renamed) mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPCommon.cpp () 
- (modified) mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+247-146) 
- (modified) mlir/lib/Target/LLVMIR/ModuleTranslation.cpp (+10-32) 


``````````diff
diff --git a/flang/include/flang/Optimizer/Support/InitFIR.h b/flang/include/flang/Optimizer/Support/InitFIR.h
index 20b21767cd3dea..dbcaf4862fa1de 100644
--- a/flang/include/flang/Optimizer/Support/InitFIR.h
+++ b/flang/include/flang/Optimizer/Support/InitFIR.h
@@ -34,6 +34,7 @@
 #include "mlir/Dialect/Math/IR/Math.h"
 #include "mlir/Dialect/OpenACC/OpenACC.h"
 #include "mlir/Dialect/OpenACC/Transforms/Passes.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/Dialect/OpenMP/Transforms/Passes.h"
 #include "mlir/Dialect/SCF/IR/SCF.h"
 #include "mlir/Dialect/SCF/Transforms/Passes.h"
diff --git a/flang/lib/Optimizer/Dialect/CMakeLists.txt b/flang/lib/Optimizer/Dialect/CMakeLists.txt
index e2a67a586752ba..2956bad38109fb 100644
--- a/flang/lib/Optimizer/Dialect/CMakeLists.txt
+++ b/flang/lib/Optimizer/Dialect/CMakeLists.txt
@@ -42,6 +42,7 @@ add_flang_library(FIRDialect
   MLIRGPUDialect
   MLIROpenACCDialect
   MLIROpenACCUtils
+  MLIROpenMPDialect
   MLIRBuiltinToLLVMIRTranslation
   MLIRLLVMToLLVMIRTranslation
   MLIRTargetLLVMIRExport
diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
index c91fd5fea3cbbd..323b44f7ddfa12 100644
--- a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
+++ b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
@@ -15,16 +15,17 @@
 #define MLIR_TARGET_LLVMIR_MODULETRANSLATION_H
 
 #include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
-#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/IR/Operation.h"
 #include "mlir/IR/SymbolTable.h"
 #include "mlir/IR/Value.h"
 #include "mlir/Support/LLVM.h"
 #include "mlir/Support/StateStack.h"
+#include "mlir/Support/TypeID.h"
 #include "mlir/Target/LLVMIR/Export.h"
 #include "mlir/Target/LLVMIR/LLVMTranslationInterface.h"
 #include "mlir/Target/LLVMIR/TypeToLLVM.h"
 
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/IR/FPEnv.h"
 #include "llvm/IR/Module.h"
@@ -33,11 +34,9 @@
 namespace llvm {
 class BasicBlock;
 class CallBase;
-class CanonicalLoopInfo;
 class Function;
 class IRBuilderBase;
 class Metadata;
-class OpenMPIRBuilder;
 class Value;
 } // namespace llvm
 
@@ -120,41 +119,6 @@ class ModuleTranslation {
     return blockMapping.lookup(block);
   }
 
-  /// Find the LLVM-IR loop that represents an MLIR loop.
-  llvm::CanonicalLoopInfo *lookupOMPLoop(omp::NewCliOp mlir) const {
-    llvm::CanonicalLoopInfo *result = loopMapping.lookup(mlir);
-    assert(result && "attempt to get non-existing loop");
-    return result;
-  }
-
-  /// Find the LLVM-IR loop that represents an MLIR loop.
-  llvm::CanonicalLoopInfo *lookupOMPLoop(Value mlir) const {
-    return lookupOMPLoop(mlir.getDefiningOp<omp::NewCliOp>());
-  }
-
-  /// Mark an OpenMP loop as having been consumed.
-  void invalidateOmpLoop(omp::NewCliOp mlir) { loopMapping.erase(mlir); }
-
-  /// Mark an OpenMP loop as having been consumed.
-  void invalidateOmpLoop(Value mlir) {
-    invalidateOmpLoop(mlir.getDefiningOp<omp::NewCliOp>());
-  }
-
-  /// Map an MLIR OpenMP dialect CanonicalLoopInfo to its lowered LLVM-IR
-  /// OpenMPIRBuilder CanonicalLoopInfo
-  void mapOmpLoop(omp::NewCliOp mlir, llvm::CanonicalLoopInfo *llvm) {
-    assert(llvm && "argument must be non-null");
-    llvm::CanonicalLoopInfo *&cur = loopMapping[mlir];
-    assert(cur == nullptr && "attempting to map a loop that is already mapped");
-    cur = llvm;
-  }
-
-  /// Map an MLIR OpenMP dialect CanonicalLoopInfo to its lowered LLVM-IR
-  /// OpenMPIRBuilder CanonicalLoopInfo
-  void mapOmpLoop(Value mlir, llvm::CanonicalLoopInfo *llvm) {
-    mapOmpLoop(mlir.getDefiningOp<omp::NewCliOp>(), llvm);
-  }
-
   /// Stores the mapping between an MLIR operation with successors and a
   /// corresponding LLVM IR instruction.
   void mapBranch(Operation *mlir, llvm::Instruction *llvm) {
@@ -284,10 +248,6 @@ class ModuleTranslation {
     return ifuncMapping.lookup(op);
   }
 
-  /// Returns the OpenMP IR builder associated with the LLVM IR module being
-  /// constructed.
-  llvm::OpenMPIRBuilder *getOpenMPBuilder();
-
   /// Returns the virtual filesystem to use for file operations. Falls back to
   /// the real filesystem if none was provided.
   llvm::vfs::FileSystem &getFileSystem();
@@ -381,6 +341,37 @@ class ModuleTranslation {
   template <typename T>
   using SaveStack = SaveStateStack<T, ModuleTranslation>;
 
+  /// Base class for state that lives as long as the module translation.
+  /// Dialect translations use extensions to keep state shared across the
+  /// translation of several operations (e.g. IR builders or handle mappings)
+  /// without the core translation depending on those dialects. Derived classes
+  /// must provide an explicit TypeID.
+  class Extension {
+  public:
+    virtual ~Extension();
+
+    /// Called once after all operations have been translated and before the
+    /// LLVM module is verified. Extensions are finalized in creation order.
+    virtual LogicalResult finalize() { return success(); }
+  };
+
+  /// Returns the extension of type `T`, constructing it from `args` on first
+  /// use. `T` must derive from `Extension`.
+  template <typename T, typename... Args>
+  T &getOrCreateExtension(Args &&...args) {
+    static_assert(std::is_base_of<Extension, T>::value,
+                  "expected T derived from ModuleTranslation::Extension");
+    TypeID id = TypeID::get<T>();
+    auto it = extensions.find(id);
+    if (it != extensions.end())
+      return static_cast<T &>(*it->second);
+    // Construct before inserting: the constructor may create other extensions.
+    auto extension = std::make_unique<T>(std::forward<Args>(args)...);
+    T &result = *extension;
+    extensions.insert({id, std::move(extension)});
+    return result;
+  }
+
   SymbolTableCollection &symbolTable() { return symbolTableCollection; }
 
   // A helper callback that takes an attribute, and if it is a StringAttr,
@@ -489,8 +480,8 @@ class ModuleTranslation {
   /// A converter for translating loop annotations.
   std::unique_ptr<detail::LoopAnnotationTranslation> loopAnnotationTranslation;
 
-  /// Builder for LLVM IR generation of OpenMP constructs.
-  std::unique_ptr<llvm::OpenMPIRBuilder> ompBuilder;
+  /// Translation-scoped state owned by dialect translations.
+  llvm::MapVector<TypeID, std::unique_ptr<Extension>> extensions;
 
   /// Optional virtual filesystem for file operations. When null, the real
   /// filesystem is used (via getFileSystem()). Not owned.
@@ -525,12 +516,6 @@ class ModuleTranslation {
   DenseMap<Value, llvm::Value *> valueMapping;
   DenseMap<Block *, llvm::BasicBlock *> blockMapping;
 
-  /// List of not yet consumed MLIR loop handles (represented by an omp.new_cli
-  /// operation which creates a value of type CanonicalLoopInfoType) and their
-  /// LLVM-IR representation as CanonicalLoopInfo which is managed by the
-  /// OpenMPIRBuilder.
-  DenseMap<omp::NewCliOp, llvm::CanonicalLoopInfo *> loopMapping;
-
   /// A mapping between MLIR LLVM dialect terminators and LLVM IR terminators
   /// they are converted to. This allows for connecting PHI nodes to the source
   /// values after all operations are converted.
diff --git a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
index 20999d8edb7244..20d00a1f2212e8 100644
--- a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
+++ b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
@@ -107,7 +107,6 @@ add_mlir_dialect_library(MLIRNVVMDialect
   MLIRIR
   MLIRLLVMDialect
   MLIRGPUDialect
-  MLIROpenMPDialect
   MLIRSideEffectInterfaces
   MLIRInferIntRangeInterface
   )
@@ -196,6 +195,5 @@ add_mlir_dialect_library(MLIRXeVMDialect
   MLIRDialectUtils
   MLIRIR
   MLIRLLVMDialect
-  MLIROpenMPDialect
   MLIRSideEffectInterfaces
 )
diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
index bd3e18946393b2..a4c185edbe1191 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
@@ -32,6 +32,7 @@
 #include "mlir/Target/LLVMIR/ModuleTranslation.h"
 #include "mlir/Transforms/InliningUtils.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/NVVMIntrinsicUtils.h"
diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt b/mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt
index ce50c1ff9c3ceb..eec5c34a87d6a5 100644
--- a/mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt
@@ -18,5 +18,4 @@ add_mlir_dialect_library(MLIRLLVMIRTransforms
   MLIRLLVMDialect
   MLIRPass
   MLIRTransforms
-  MLIROpenMPDialect
   )
diff --git a/mlir/lib/Target/LLVMIR/CMakeLists.txt b/mlir/lib/Target/LLVMIR/CMakeLists.txt
index b7ebd9dc19b9f3..8f64d302c39fbb 100644
--- a/mlir/lib/Target/LLVMIR/CMakeLists.txt
+++ b/mlir/lib/Target/LLVMIR/CMakeLists.txt
@@ -22,7 +22,6 @@ add_mlir_translation_library(MLIRTargetLLVMIRExport
   LoopAnnotationTranslation.cpp
   ModuleTranslation.cpp
   TypeToLLVM.cpp
-  Dialect/OpenMPCommon.cpp
 
   ADDITIONAL_HEADER_DIRS
   ${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVMIR
@@ -34,7 +33,6 @@ add_mlir_translation_library(MLIRTargetLLVMIRExport
   LINK_COMPONENTS
   Analysis
   Core
-  FrontendOpenMP
   TransformUtils
   TargetParser
 
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/CMakeLists.txt b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/CMakeLists.txt
index e3f9c63dab105f..5dd65c48515426 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/CMakeLists.txt
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/CMakeLists.txt
@@ -1,8 +1,10 @@
 add_mlir_translation_library(MLIROpenMPToLLVMIRTranslation
+  OpenMPCommon.cpp
   OpenMPToLLVMIRTranslation.cpp
 
   LINK_COMPONENTS
   Core
+  FrontendOpenMP
 
   LINK_LIBS PUBLIC
   MLIRAnalysisBase
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPCommon.cpp
similarity index 100%
rename from mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp
rename to mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPCommon.cpp
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index e8bcc22464439b..92155701c59de9 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -103,6 +103,96 @@ class OpenMPLoopInfoStackFrame
   llvm::CanonicalLoopInfo *loopInfo = nullptr;
 };
 
+/// OpenMP state that lives as long as the module translation: the
+/// OpenMPIRBuilder associated with the LLVM module being constructed and the
+/// not yet consumed canonical loop handles.
+class OpenMPTranslationState : public LLVM::ModuleTranslation::Extension {
+public:
+  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(OpenMPTranslationState)
+
+  explicit OpenMPTranslationState(llvm::Module &module) : ompBuilder(module) {
+    // Flags represented as top-level OpenMP dialect attributes are set in
+    // `OpenMPDialectLLVMIRTranslationInterface::amendOperation()`. Here we set
+    // the default configuration.
+    llvm::OpenMPIRBuilderConfig config(
+        /* IsTargetDevice = */ false, /* IsGPU = */ false,
+        /* OpenMPOffloadMandatory = */ false,
+        /* HasRequiresReverseOffload = */ false,
+        /* HasRequiresUnifiedAddress = */ false,
+        /* HasRequiresUnifiedSharedMemory = */ false,
+        /* HasRequiresDynamicAllocators = */ false);
+    config.setDefaultTargetAS(module.getDataLayout().getProgramAddressSpace());
+    config.setRuntimeCC(module.getTargetTriple().isSPIRV()
+                            ? llvm::CallingConv::SPIR_FUNC
+                            : llvm::CallingConv::C);
+    ompBuilder.setConfig(std::move(config));
+    ompBuilder.initialize();
+  }
+
+  ~OpenMPTranslationState() override {
+    if (!ompBuilder.isFinalized())
+      ompBuilder.finalize();
+  }
+
+  LogicalResult finalize() override {
+    ompBuilder.finalize();
+    return success();
+  }
+
+  /// Builder for LLVM IR generation of OpenMP constructs.
+  llvm::OpenMPIRBuilder ompBuilder;
+
+  /// List of not yet consumed MLIR loop handles (represented by an omp.new_cli
+  /// operation which creates a value of type CanonicalLoopInfoType) and their
+  /// LLVM-IR representation as CanonicalLoopInfo which is managed by the
+  /// OpenMPIRBuilder.
+  DenseMap<omp::NewCliOp, llvm::CanonicalLoopInfo *> loopMapping;
+};
+} // namespace
+
+static OpenMPTranslationState &
+getOpenMPState(LLVM::ModuleTranslation &moduleTranslation) {
+  return moduleTranslation.getOrCreateExtension<OpenMPTranslationState>(
+      *moduleTranslation.getLLVMModule());
+}
+
+/// Returns the OpenMP IR builder associated with the LLVM IR module being
+/// constructed.
+static llvm::OpenMPIRBuilder *
+getOpenMPBuilder(LLVM::ModuleTranslation &moduleTranslation) {
+  return &getOpenMPState(moduleTranslation).ompBuilder;
+}
+
+/// Find the LLVM-IR loop that represents an MLIR loop.
+static llvm::CanonicalLoopInfo *
+lookupOMPLoop(LLVM::ModuleTranslation &moduleTranslation, Value mlir) {
+  auto cli = mlir.getDefiningOp<omp::NewCliOp>();
+  llvm::CanonicalLoopInfo *result =
+      getOpenMPState(moduleTranslation).loopMapping.lookup(cli);
+  assert(result && "attempt to get non-existing loop");
+  return result;
+}
+
+/// Mark an OpenMP loop as having been consumed.
+static void invalidateOmpLoop(LLVM::ModuleTranslation &moduleTranslation,
+                              Value mlir) {
+  auto cli = mlir.getDefiningOp<omp::NewCliOp>();
+  getOpenMPState(moduleTranslation).loopMapping.erase(cli);
+}
+
+/// Map an MLIR OpenMP dialect CanonicalLoopInfo to its lowered LLVM-IR
+/// OpenMPIRBuilder CanonicalLoopInfo.
+static void mapOmpLoop(LLVM::ModuleTranslation &moduleTranslation, Value mlir,
+                       llvm::CanonicalLoopInfo *llvm) {
+  assert(llvm && "argument must be non-null");
+  auto cli = mlir.getDefiningOp<omp::NewCliOp>();
+  llvm::CanonicalLoopInfo *&cur =
+      getOpenMPState(moduleTranslation).loopMapping[cli];
+  assert(cur == nullptr && "attempting to map a loop that is already mapped");
+  cur = llvm;
+}
+
+namespace {
 /// Custom error class to signal translation errors that don't need reporting,
 /// since encountering them will have already triggered relevant error messages.
 ///
@@ -400,8 +490,8 @@ class LinearClauseProcessor {
     linearFinalizationBB->getTerminator()->eraseFromParent();
     // Emit barrier
     builder.SetInsertPoint(linearExitBB->getTerminator());
-    return moduleTranslation.getOpenMPBuilder()->createBarrier(
-        builder, llvm::omp::OMPD_barrier);
+    return getOpenMPBuilder(moduleTranslation)
+        ->createBarrier(builder, llvm::omp::OMPD_barrier);
   }
 
   // Emit stores for linear variables. Useful in case of SIMD
@@ -412,7 +502,6 @@ class LinearClauseProcessor {
     return storeLinearVars(builder, moduleTranslation);
   }
 };
-
 } // namespace
 
 /// Looks up from the operation from and returns the PrivateClauseOp with
@@ -962,8 +1051,8 @@ convertOmpMasked(Operation &opInst, llvm::IRBuilderBase &builder,
   assert(filterVal != nullptr);
   llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
   llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
-      moduleTranslation.getOpenMPBuilder()->createMasked(ompLoc, bodyGenCB,
-                                                         finiCB, filterVal);
+      getOpenMPBuilder(moduleTranslation)
+          ->createMasked(ompLoc, bodyGenCB, finiCB, filterVal);
 
   if (failed(handleError(afterIP, opInst)))
     return failure();
@@ -998,8 +1087,8 @@ convertOmpMaster(Operation &opInst, llvm::IRBuilderBase &builder,
 
   llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
   llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
-      moduleTranslation.getOpenMPBuilder()->createMaster(ompLoc, bodyGenCB,
-                                                         finiCB);
+      getOpenMPBuilder(moduleTranslation)
+          ->createMaster(ompLoc, bodyGenCB, finiCB);
 
   if (failed(handleError(afterIP, opInst)))
     return failure();
@@ -1049,8 +1138,9 @@ convertOmpCritical(Operation &opInst, llvm::IRBuilderBase &builder,
                                static_cast<int>(criticalDeclareOp.getHint()));
   }
   llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
-      moduleTranslation.getOpenMPBuilder()->createCritical(
-          ompLoc, bodyGenCB, finiCB, criticalOp.getName().value_or(""), hint);
+      getOpenMPBuilder(moduleTranslation)
+          ->createCritical(ompLoc, bodyGenCB, finiCB,
+                           criticalOp.getName().value_or(""), hint);
 
   if (failed(handleError(afterIP, opInst)))
     return failure();
@@ -1059,6 +1149,7 @@ convertOmpCritical(Operation &opInst, llvm::IRBuilderBase &builder,
   return success();
 }
 
+namespace {
 /// A util to collect info needed to convert delayed privatizers from MLIR to
 /// LLVM.
 struct PrivateVarsInfo {
@@ -1117,6 +1208,7 @@ struct PrivateVarsInfo {
     }
   }
 };
+} // namespace
 
 /// Populates `reductions` with reduction declarations used in the given op.
 template <typename T>
@@ -1381,8 +1473,10 @@ convertOmpOrdered(Operation &opInst, llvm::IRBuilderBase &builder,
     llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
         findAllocInsertPoints(builder, moduleTranslation);
     llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
-    builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createOrderedDepend(
-        ompLoc, allocaIP, numLoops, storeValues, ".cnt.addr", isDependSource));
+    builder.restoreIP(getOpenMPBuilder(moduleTranslation)
+                          ->createOrderedDepend(ompLoc, allocaIP, numLoops,
+                                                storeValues, ".cnt.addr",
+                                                isDependSource));
   }
   return success();
 }
@@ -1414,8 +1508,9 @@ convertOmpOrderedRegion(Operation &opInst, llvm::IRBuilderBase &builder,
 
   llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
   llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
-      moduleTranslation.getOpenMPBuilder()->createOrderedThreadsSimd(
-          ompLoc, bodyGenCB, finiCB, !orderedRegionOp.getParLevelSimd());
+      getOpenMPBuilder(moduleTranslation)
+          ->createOrderedThreadsSimd(ompLoc, bodyGenCB, finiCB,
+                                     !orderedRegionOp.getParLevelSimd());
 
   if (failed(handleError(afterIP, opInst)))
     return failure();
@@ -1452,7 +1547,7 @@ allocReductionVars(T op, ArrayRef<BlockArgument> reductionArgs,
   llvm::IRBuilderBase::InsertPointGuard guard(builder);
   builder.SetInsertPoint(allocaIP.getNodeParent()->getTerminator());
 
-  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+  llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
   bool useDeviceSharedMem = omp::opInSharedDeviceContext(*op);
 
   // delay creating stores until after all allocas
@@ -1583,7 +1678,7 @@ initReductionVars(OP op, ArrayRef<BlockArgument> reductionArgs,
   if (op.getNumReductionVars() == 0)
     return success();
 
-  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+  llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
   bool useDeviceSharedMem = omp::opInSharedDeviceContext(*op);
 
   llvm::BasicBlock *initBlock = splitBB(builder, true, "omp.reduction.init");
@@ -1786,7 +1881,7 @@ static LogicalResult createReductionsAndCleanup(
   SmallVector<OwningDataPtrPtrReductionGen> owningReductionGenRefDataPtrGens;
   SmallVector<llvm::OpenMPIRBuilder::ReductionInfo, 2> reductionInfos;
 
-  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+  llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
 
   // Create the reduction generators. We need to own them here because
   // ReductionInfo only accepts references to the generators.
@@ -2109,7 +2204,7 @@ static llvm::Expected<llvm::BasicBlock *> allocatePrivateVars(
   llvm::DataLayout dataLayout = builder.getDataLayout();
   llvm::BasicBlock *afterAllocas = allocaTerminator->getSuccessor(0);
 
-  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+  llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
   bool mightUseDeviceSharedMem = omp::opInSha...
[truncated]

``````````

</details>


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


More information about the Mlir-commits mailing list