[Mlir-commits] [flang] [mlir] [mlir][LLVMIR] Decouple ModuleTranslation from the OpenMP dialect (PR #236777)
Markus Böck
llvmlistbot at llvm.org
Thu Oct 29 06:32:32 PDT 2026
https://github.com/zero9178 created https://github.com/llvm/llvm-project/pull/236777
`ModuleTranslation.h` included `OpenMPDialect.h` and owned OpenMP-specific state. Every consumer of the LLVM IR export, and every dialect whose header includes `ModuleTranslation.h` (NVVM, XeVM), therefore depended on the OpenMP dialect, and `MLIRNVVMDialect`, `MLIRXeVMDialect` and `MLIRLLVMIRTransforms` linked `MLIROpenMPDialect` for that reason only.
This PR decouples this by adding a TypeID-keyed
`ModuleTranslation::Extension` mechanism (similar to ones seen in bufferization or the transform dialect) for state that lives as long as the translation and move the OpenMP state into an extension owned by the OpenMP translation.
>From a49a8bc4ff6c83ad9b19d12d051dbad86561f2d0 Mon Sep 17 00:00:00 2001
From: Markus Boeck <mboeck at nvidia.com>
Date: Thu, 29 Oct 2026 13:25:50 +0000
Subject: [PATCH] [mlir][LLVMIR] Decouple ModuleTranslation from the OpenMP
dialect
`ModuleTranslation.h` included `OpenMPDialect.h` and owned OpenMP-specific
state. Every consumer of the LLVM IR export, and every dialect whose
header includes `ModuleTranslation.h` (NVVM, XeVM), therefore depended on
the OpenMP dialect, and `MLIRNVVMDialect`, `MLIRXeVMDialect` and
`MLIRLLVMIRTransforms` linked `MLIROpenMPDialect` for that reason only.
This PR decouples this by adding a TypeID-keyed
`ModuleTranslation::Extension` mechanism (similar to ones seen in
bufferization or the transform dialect) for state that lives as long as
the translation and move the OpenMP state into an extension owned by
the OpenMP translation.
---
.../include/flang/Optimizer/Support/InitFIR.h | 1 +
.../mlir/Target/LLVMIR/ModuleTranslation.h | 85 ++--
mlir/lib/Dialect/LLVMIR/CMakeLists.txt | 2 -
mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp | 1 +
.../Dialect/LLVMIR/Transforms/CMakeLists.txt | 1 -
mlir/lib/Target/LLVMIR/CMakeLists.txt | 2 -
.../LLVMIR/Dialect/OpenMP/CMakeLists.txt | 2 +
.../Dialect/{ => OpenMP}/OpenMPCommon.cpp | 0
.../OpenMP/OpenMPToLLVMIRTranslation.cpp | 392 +++++++++++-------
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 42 +-
10 files changed, 296 insertions(+), 232 deletions(-)
rename mlir/lib/Target/LLVMIR/Dialect/{ => OpenMP}/OpenMPCommon.cpp (100%)
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/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..c52a27954e7581 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
@@ -962,8 +1052,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 +1088,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 +1139,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 +1150,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 +1209,7 @@ struct PrivateVarsInfo {
}
}
};
+} // namespace
/// Populates `reductions` with reduction declarations used in the given op.
template <typename T>
@@ -1381,8 +1474,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 +1509,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 +1548,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 +1679,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 +1882,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 +2205,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::opInSharedDeviceContext(*op);
unsigned int allocaAS =
moduleTranslation.getLLVMModule()->getDataLayout().getAllocaAddrSpace();
@@ -2236,7 +2332,7 @@ emitPrivatizationBarrier(mlir::Operation *op, llvm::IRBuilderBase &builder,
if (!opMightBeSafeForBarriers(op))
return success();
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::OpenMPIRBuilder::InsertPointOrErrorTy res =
ompBuilder->createBarrier(builder, llvm::omp::OMPD_barrier);
return handleError(res, *op);
@@ -2346,7 +2442,7 @@ cleanupPrivateVars(T op, llvm::IRBuilderBase &builder,
"`omp.private` op in");
setInsertPointForPossiblyEmptyBlock(builder);
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
bool mightUseDeviceSharedMem = omp::opInSharedDeviceContext(*op);
for (auto [privDecl, llvmPrivVar, blockArg] :
llvm::zip_equal(privateVarsInfo.privatizers, privateVarsInfo.llvmVars,
@@ -2507,9 +2603,9 @@ convertOmpSections(Operation &opInst, llvm::IRBuilderBase &builder,
bool isCancellable = constructIsCancellable(sectionsOp);
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
- moduleTranslation.getOpenMPBuilder()->createSections(
- ompLoc, allocaIP, sectionCBs, privCB, finiCB, isCancellable,
- sectionsOp.getNowait());
+ getOpenMPBuilder(moduleTranslation)
+ ->createSections(ompLoc, allocaIP, sectionCBs, privCB, finiCB,
+ isCancellable, sectionsOp.getNowait());
if (failed(handleError(afterIP, opInst)))
return failure();
@@ -2532,7 +2628,7 @@ static LogicalResult
convertOmpScope(omp::ScopeOp &scopeOp, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
if (failed(checkImplementationStatus(*scopeOp)))
return failure();
@@ -2662,9 +2758,9 @@ convertOmpSingle(omp::SingleOp &singleOp, llvm::IRBuilderBase &builder,
}
llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
- moduleTranslation.getOpenMPBuilder()->createSingle(
- ompLoc, bodyCB, finiCB, singleOp.getNowait(), llvmCPVars,
- llvmCPFuncs);
+ getOpenMPBuilder(moduleTranslation)
+ ->createSingle(ompLoc, bodyCB, finiCB, singleOp.getNowait(),
+ llvmCPVars, llvmCPFuncs);
if (failed(handleError(afterIP, *singleOp)))
return failure();
@@ -2776,8 +2872,9 @@ convertOmpTeams(omp::TeamsOp op, llvm::IRBuilderBase &builder,
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
- moduleTranslation.getOpenMPBuilder()->createTeams(
- ompLoc, bodyCB, numTeamsLower, numTeamsUpper, threadLimit, ifExpr);
+ getOpenMPBuilder(moduleTranslation)
+ ->createTeams(ompLoc, bodyCB, numTeamsLower, numTeamsUpper,
+ threadLimit, ifExpr);
if (failed(handleError(afterIP, *op)))
return failure();
@@ -2981,9 +3078,10 @@ class IteratorInfo {
llvm::Value *stop = builder.CreateSExt(ub, countTy);
llvm::Value *step = builder.CreateSExt(st, countTy);
llvm::Value *count =
- moduleTranslation.getOpenMPBuilder()->calculateCanonicalLoopTripCount(
- builder, start, stop, step, /*IsSigned=*/true,
- /*InclusiveStop=*/true);
+ getOpenMPBuilder(moduleTranslation)
+ ->calculateCanonicalLoopTripCount(builder, start, stop, step,
+ /*IsSigned=*/true,
+ /*InclusiveStop=*/true);
trips[d] = builder.CreateZExtOrTrunc(count, builder.getInt64Ty());
}
@@ -2999,7 +3097,6 @@ class IteratorInfo {
llvm::ArrayRef<llvm::Value *> getTrips() const { return trips; }
llvm::Value *getTotalTrips() const { return totalTrips; }
};
-
} // namespace
void TaskContextStructManager::generateTaskContextStruct() {
@@ -3107,7 +3204,7 @@ static void fillAffinityLocators(Operation::operand_range affinityVars,
llvm::Value *addr = moduleTranslation.lookupValue(entryOp.getAddr());
llvm::Value *len = moduleTranslation.lookupValue(entryOp.getLen());
assert(addr && len && "expect affinity addr and len to be non-null");
- storeAffinityEntry(builder, *moduleTranslation.getOpenMPBuilder(),
+ storeAffinityEntry(builder, *getOpenMPBuilder(moduleTranslation),
affinityList, builder.getInt64(i), addr, len);
}
}
@@ -3206,8 +3303,9 @@ fillIteratorLoop(mlir::omp::IteratorOp itersOp, llvm::IRBuilderBase &builder,
};
llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
- moduleTranslation.getOpenMPBuilder()->createIteratorLoop(
- loc, iterInfo.getTotalTrips(), bodyGen, loopName);
+ getOpenMPBuilder(moduleTranslation)
+ ->createIteratorLoop(loc, iterInfo.getTotalTrips(), bodyGen,
+ loopName);
if (failed(handleError(afterIP, *itersOp)))
return failure();
@@ -3229,7 +3327,7 @@ buildAffinityData(mlir::omp::TaskOp &taskOp, llvm::IRBuilderBase &builder,
llvm::SmallVector<llvm::OpenMPIRBuilder::AffinityData> ads;
llvm::StructType *kmpTaskAffinityInfoTy =
- moduleTranslation.getOpenMPBuilder()->getKmpTaskAffinityInfoTy();
+ getOpenMPBuilder(moduleTranslation)->getKmpTaskAffinityInfoTy();
auto allocateAffinityList = [&](llvm::Value *count) -> llvm::Value * {
llvm::IRBuilderBase::InsertPointGuard guard(builder);
@@ -3275,7 +3373,7 @@ buildAffinityData(mlir::omp::TaskOp &taskOp, llvm::IRBuilderBase &builder,
llvm::Value *len =
moduleTranslation.lookupValue(entryOp.getLen());
storeAffinityEntry(builder,
- *moduleTranslation.getOpenMPBuilder(),
+ *getOpenMPBuilder(moduleTranslation),
affList, linearIV, addr, len);
})))
return llvm::failure();
@@ -3293,7 +3391,7 @@ buildAffinityData(mlir::omp::TaskOp &taskOp, llvm::IRBuilderBase &builder,
llvm::Value *affinityInfo = ads.front().Info;
if (ads.size() > 1) {
llvm::StructType *kmpTaskAffinityInfoTy =
- moduleTranslation.getOpenMPBuilder()->getKmpTaskAffinityInfoTy();
+ getOpenMPBuilder(moduleTranslation)->getKmpTaskAffinityInfoTy();
llvm::Value *affinityInfoElemSize = builder.getInt64(
moduleTranslation.getLLVMModule()->getDataLayout().getTypeAllocSize(
kmpTaskAffinityInfoTy));
@@ -3350,7 +3448,7 @@ buildDependData(OperandRange dependVars, std::optional<ArrayAttr> dependKinds,
return mlir::success();
}
- llvm::OpenMPIRBuilder &ompBuilder = *moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder &ompBuilder = *getOpenMPBuilder(moduleTranslation);
llvm::Type *dependInfoTy = ompBuilder.DependInfo;
unsigned numLocator = dependVars.size();
@@ -3636,7 +3734,7 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
// OpenMPIRBuilder::finalize.
if (!inRedDecls.empty()) {
auto iface = cast<omp::BlockArgOpenMPOpInterface>(taskOp.getOperation());
- llvm::OpenMPIRBuilder &ompB = *moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder &ompB = *getOpenMPBuilder(moduleTranslation);
llvm::Module *m = moduleTranslation.getLLVMModule();
llvm::LLVMContext &llvmCtx = m->getContext();
llvm::OpenMPIRBuilder::LocationDescription bodyLoc(builder);
@@ -3693,7 +3791,7 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
return llvm::Error::success();
};
- llvm::OpenMPIRBuilder &ompBuilder = *moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder &ompBuilder = *getOpenMPBuilder(moduleTranslation);
SmallVector<llvm::UncondBrInst *> cancelTerminators;
// The directive to match here is OMPD_taskgroup because it is the taskgroup
// which is canceled. This is handled here because it is the task's cleanup
@@ -3710,14 +3808,15 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
- moduleTranslation.getOpenMPBuilder()->createTask(
- ompLoc, allocaIP, deallocBlocks, bodyCB, !taskOp.getUntied(),
- moduleTranslation.lookupValue(taskOp.getFinal()),
- moduleTranslation.lookupValue(taskOp.getIfExpr()), dependencies, ad,
- taskOp.getMergeable(),
- moduleTranslation.lookupValue(taskOp.getEventHandle()),
- moduleTranslation.lookupValue(taskOp.getPriority()),
- taskOp.getThreadset() == omp::ThreadsetPolicy::omp_pool);
+ getOpenMPBuilder(moduleTranslation)
+ ->createTask(ompLoc, allocaIP, deallocBlocks, bodyCB,
+ !taskOp.getUntied(),
+ moduleTranslation.lookupValue(taskOp.getFinal()),
+ moduleTranslation.lookupValue(taskOp.getIfExpr()),
+ dependencies, ad, taskOp.getMergeable(),
+ moduleTranslation.lookupValue(taskOp.getEventHandle()),
+ moduleTranslation.lookupValue(taskOp.getPriority()),
+ taskOp.getThreadset() == omp::ThreadsetPolicy::omp_pool);
if (failed(handleError(afterIP, *taskOp)))
return failure();
@@ -4041,7 +4140,7 @@ convertOmpTaskloopContextOp(omp::TaskloopContextOp contextOp,
// setup (if any) and for the subsequent call to createTaskloop().
builder.SetInsertPoint(taskloopStartBlock);
- llvm::OpenMPIRBuilder &ompBuilderRef = *moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder &ompBuilderRef = *getOpenMPBuilder(moduleTranslation);
llvm::Module *module = moduleTranslation.getLLVMModule();
// If we have task_reduction items, we must emit our own implicit
@@ -4157,7 +4256,7 @@ convertOmpTaskloopContextOp(omp::TaskloopContextOp contextOp,
if (!redDecls.empty() || !inRedDecls.empty()) {
auto iface =
cast<omp::BlockArgOpenMPOpInterface>(contextOp.getOperation());
- llvm::OpenMPIRBuilder &ompB = *moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder &ompB = *getOpenMPBuilder(moduleTranslation);
llvm::Module *m = moduleTranslation.getLLVMModule();
llvm::LLVMContext &llvmCtx = m->getContext();
llvm::OpenMPIRBuilder::LocationDescription bodyLoc(builder);
@@ -4335,7 +4434,7 @@ convertOmpTaskloopContextOp(omp::TaskloopContextOp contextOp,
if (taskStructMgr.getStructPtr())
taskDupOrNull = taskDupCB;
- llvm::OpenMPIRBuilder &ompBuilder = *moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder &ompBuilder = *getOpenMPBuilder(moduleTranslation);
SmallVector<llvm::UncondBrInst *> cancelTerminators;
// The directive to match here is OMPD_taskgroup because it is the
// taskgroup which is canceled. This is handled here because it is the
@@ -4348,15 +4447,17 @@ convertOmpTaskloopContextOp(omp::TaskloopContextOp contextOp,
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
bool effectiveNoGroup = contextOp.getNogroup() || implicitTaskgroup;
llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
- moduleTranslation.getOpenMPBuilder()->createTaskloop(
- ompLoc, allocaIP, deallocBlocks, bodyCB, loopInfo, lbVal, ubVal,
- stepVal, contextOp.getUntied(), ifCond, grainsize, effectiveNoGroup,
- sched, moduleTranslation.lookupValue(contextOp.getFinal()),
- contextOp.getMergeable(),
- moduleTranslation.lookupValue(contextOp.getPriority()),
- loopOp.getCollapseNumLoops(), taskDupOrNull,
- taskStructMgr.getStructPtr(),
- contextOp.getThreadset() == omp::ThreadsetPolicy::omp_pool);
+ getOpenMPBuilder(moduleTranslation)
+ ->createTaskloop(
+ ompLoc, allocaIP, deallocBlocks, bodyCB, loopInfo, lbVal, ubVal,
+ stepVal, contextOp.getUntied(), ifCond, grainsize,
+ effectiveNoGroup, sched,
+ moduleTranslation.lookupValue(contextOp.getFinal()),
+ contextOp.getMergeable(),
+ moduleTranslation.lookupValue(contextOp.getPriority()),
+ loopOp.getCollapseNumLoops(), taskDupOrNull,
+ taskStructMgr.getStructPtr(),
+ contextOp.getThreadset() == omp::ThreadsetPolicy::omp_pool);
if (failed(handleError(afterIP, opInst)))
return failure();
@@ -4510,7 +4611,7 @@ static llvm::Value *emitTaskReductionInitCall(
bool isWorksharing) {
assert(redDecls.size() == origPtrs.size() &&
"expected one orig pointer per reduction decl");
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
llvm::LLVMContext &ctx = llvmModule->getContext();
const llvm::DataLayout &dl = llvmModule->getDataLayout();
@@ -4608,7 +4709,7 @@ static llvm::Value *emitTaskReductionInitCall(
static void
emitTaskReductionModifierFini(bool isWorksharing, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
uint32_t srcLocSize;
@@ -4697,8 +4798,8 @@ convertOmpTaskgroupOp(omp::TaskgroupOp tgOp, llvm::IRBuilderBase &builder,
findAllocInsertPoints(builder, moduleTranslation, &deallocBlocks);
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
- moduleTranslation.getOpenMPBuilder()->createTaskgroup(
- ompLoc, allocaIP, deallocBlocks, bodyCB);
+ getOpenMPBuilder(moduleTranslation)
+ ->createTaskgroup(ompLoc, allocaIP, deallocBlocks, bodyCB);
if (failed(handleError(afterIP, *tgOp)))
return failure();
@@ -4716,7 +4817,7 @@ convertOmpInteropInitOp(omp::InteropInitOp initOp, llvm::IRBuilderBase &builder,
<< "not yet implemented: Unhandled clause depend in "
<< omp::InteropInitOp::getOperationName() << " operation";
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::Value *interopVar =
moduleTranslation.lookupValue(initOp.getInteropVar());
llvm::Value *device = initOp.getDevice()
@@ -4763,7 +4864,7 @@ convertOmpInteropDestroyOp(omp::InteropDestroyOp destroyOp,
<< "not yet implemented: Unhandled clause depend in "
<< omp::InteropDestroyOp::getOperationName() << " operation";
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::Value *interopVar =
moduleTranslation.lookupValue(destroyOp.getInteropVar());
llvm::Value *device =
@@ -4789,7 +4890,7 @@ convertOmpInteropUseOp(omp::InteropUseOp useOp, llvm::IRBuilderBase &builder,
<< "not yet implemented: Unhandled clause depend in "
<< omp::InteropUseOp::getOperationName() << " operation";
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::Value *interopVar =
moduleTranslation.lookupValue(useOp.getInteropVar());
llvm::Value *device = useOp.getDevice()
@@ -4818,8 +4919,8 @@ convertOmpTaskwaitOp(omp::TaskwaitOp twOp, llvm::IRBuilderBase &builder,
return failure();
}
- moduleTranslation.getOpenMPBuilder()->createTaskwait(builder, dds,
- twOp.getNowait());
+ getOpenMPBuilder(moduleTranslation)
+ ->createTaskwait(builder, dds, twOp.getNowait());
if (dds.DepArray) {
builder.CreateFree(dds.DepArray);
}
@@ -4831,7 +4932,7 @@ convertOmpTaskwaitOp(omp::TaskwaitOp twOp, llvm::IRBuilderBase &builder,
static LogicalResult
convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
auto wsloopOp = cast<omp::WsloopOp>(opInst);
if (failed(checkImplementationStatus(opInst)))
return failure();
@@ -4986,8 +5087,8 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
opInst)))
return failure();
llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterBarrierIP =
- moduleTranslation.getOpenMPBuilder()->createBarrier(
- builder, llvm::omp::OMPD_barrier);
+ getOpenMPBuilder(moduleTranslation)
+ ->createBarrier(builder, llvm::omp::OMPD_barrier);
if (failed(handleError(afterBarrierIP, *loopOp)))
return failure();
builder.restoreIP(*afterBarrierIP);
@@ -5073,7 +5174,7 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
ArrayRef<bool> isByRef = getIsByRef(opInst.getReductionByref());
assert(isByRef.size() == opInst.getNumReductionVars());
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
bool isCancellable = constructIsCancellable(opInst);
if (failed(checkImplementationStatus(*opInst)))
@@ -5298,7 +5399,7 @@ convertOrderKind(std::optional<omp::ClauseOrderKind> o) {
static LogicalResult
convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
auto simdOp = cast<omp::SimdOp>(opInst);
if (failed(checkImplementationStatus(opInst)))
@@ -5495,7 +5596,7 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder,
static LogicalResult
convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
auto loopOp = cast<omp::LoopNestOp>(opInst);
if (failed(checkImplementationStatus(opInst)))
@@ -5621,7 +5722,7 @@ convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
static LogicalResult
convertOmpCanonicalLoopOp(omp::CanonicalLoopOp op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::OpenMPIRBuilder::LocationDescription loopLoc(builder);
Value loopIV = op.getInductionVar();
@@ -5654,7 +5755,7 @@ convertOmpCanonicalLoopOp(omp::CanonicalLoopOp op, llvm::IRBuilderBase &builder,
// Register the mapping of MLIR loop to LLVM-IR OpenMPIRBuilder loop
if (Value cli = op.getCli())
- moduleTranslation.mapOmpLoop(cli, llvmCLI);
+ mapOmpLoop(moduleTranslation, cli, llvmCLI);
return success();
}
@@ -5664,17 +5765,17 @@ convertOmpCanonicalLoopOp(omp::CanonicalLoopOp op, llvm::IRBuilderBase &builder,
static LogicalResult
applyUnrollHeuristic(omp::UnrollHeuristicOp op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
Value applyee = op.getApplyee();
assert(applyee && "Loop to apply unrolling on required");
llvm::CanonicalLoopInfo *consBuilderCLI =
- moduleTranslation.lookupOMPLoop(applyee);
+ lookupOMPLoop(moduleTranslation, applyee);
llvm::OpenMPIRBuilder::LocationDescription loc(builder);
ompBuilder->unrollLoopHeuristic(loc.DL, consBuilderCLI);
- moduleTranslation.invalidateOmpLoop(applyee);
+ invalidateOmpLoop(moduleTranslation, applyee);
return success();
}
@@ -5683,17 +5784,17 @@ applyUnrollHeuristic(omp::UnrollHeuristicOp op, llvm::IRBuilderBase &builder,
static LogicalResult
applyUnrollFull(omp::UnrollFullOp op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
Value applyee = op.getApplyee();
assert(applyee && "Loop to apply unrolling on required");
llvm::CanonicalLoopInfo *consBuilderCLI =
- moduleTranslation.lookupOMPLoop(applyee);
+ lookupOMPLoop(moduleTranslation, applyee);
llvm::OpenMPIRBuilder::LocationDescription loc(builder);
ompBuilder->unrollLoopFull(loc.DL, consBuilderCLI);
- moduleTranslation.invalidateOmpLoop(applyee);
+ invalidateOmpLoop(moduleTranslation, applyee);
return success();
}
@@ -5702,13 +5803,13 @@ applyUnrollFull(omp::UnrollFullOp op, llvm::IRBuilderBase &builder,
static LogicalResult
applyUnrollPartial(omp::UnrollPartialOp op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
Value applyee = op.getApplyee();
assert(applyee && "Loop to apply unrolling on required");
llvm::CanonicalLoopInfo *consBuilderCLI =
- moduleTranslation.lookupOMPLoop(applyee);
+ lookupOMPLoop(moduleTranslation, applyee);
llvm::OpenMPIRBuilder::LocationDescription loc(builder);
// No generatee is supported yet, so the unrolled loop's CanonicalLoopInfo is
@@ -5717,7 +5818,7 @@ applyUnrollPartial(omp::UnrollPartialOp op, llvm::IRBuilderBase &builder,
ompBuilder->unrollLoopPartial(loc.DL, consBuilderCLI, factor,
/*UnrolledCLI=*/nullptr);
- moduleTranslation.invalidateOmpLoop(applyee);
+ invalidateOmpLoop(moduleTranslation, applyee);
return success();
}
@@ -5725,7 +5826,7 @@ applyUnrollPartial(omp::UnrollPartialOp op, llvm::IRBuilderBase &builder,
/// OpenMPIRBuilder.
static LogicalResult applyTile(omp::TileOp op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::OpenMPIRBuilder::LocationDescription loc(builder);
SmallVector<llvm::CanonicalLoopInfo *> translatedLoops;
@@ -5740,7 +5841,7 @@ static LogicalResult applyTile(omp::TileOp op, llvm::IRBuilderBase &builder,
for (Value applyee : op.getApplyees()) {
llvm::CanonicalLoopInfo *consBuilderCLI =
- moduleTranslation.lookupOMPLoop(applyee);
+ lookupOMPLoop(moduleTranslation, applyee);
assert(applyee && "Canonical loop must already been translated");
translatedLoops.push_back(consBuilderCLI);
}
@@ -5750,12 +5851,12 @@ static LogicalResult applyTile(omp::TileOp op, llvm::IRBuilderBase &builder,
if (!op.getGeneratees().empty()) {
for (auto [mlirLoop, genLoop] :
zip_equal(op.getGeneratees(), generatedLoops))
- moduleTranslation.mapOmpLoop(mlirLoop, genLoop);
+ mapOmpLoop(moduleTranslation, mlirLoop, genLoop);
}
// CLIs can only be consumed once
for (Value applyee : op.getApplyees())
- moduleTranslation.invalidateOmpLoop(applyee);
+ invalidateOmpLoop(moduleTranslation, applyee);
return success();
}
@@ -5764,7 +5865,7 @@ static LogicalResult applyTile(omp::TileOp op, llvm::IRBuilderBase &builder,
/// OpenMPIRBuilder.
static LogicalResult applyFuse(omp::FuseOp op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::OpenMPIRBuilder::LocationDescription loc(builder);
// Select what CLIs are going to be fused
@@ -5772,7 +5873,7 @@ static LogicalResult applyFuse(omp::FuseOp op, llvm::IRBuilderBase &builder,
for (size_t i = 0; i < op.getApplyees().size(); i++) {
Value applyee = op.getApplyees()[i];
llvm::CanonicalLoopInfo *consBuilderCLI =
- moduleTranslation.lookupOMPLoop(applyee);
+ lookupOMPLoop(moduleTranslation, applyee);
assert(applyee && "Canonical loop must already been translated");
if (op.getFirst().has_value() && i < op.getFirst().value() - 1)
beforeFuse.push_back(consBuilderCLI);
@@ -5792,15 +5893,15 @@ static LogicalResult applyFuse(omp::FuseOp op, llvm::IRBuilderBase &builder,
if (!op.getGeneratees().empty()) {
size_t i = 0;
for (; i < beforeFuse.size(); i++)
- moduleTranslation.mapOmpLoop(op.getGeneratees()[i], beforeFuse[i]);
- moduleTranslation.mapOmpLoop(op.getGeneratees()[i++], generatedLoop);
+ mapOmpLoop(moduleTranslation, op.getGeneratees()[i], beforeFuse[i]);
+ mapOmpLoop(moduleTranslation, op.getGeneratees()[i++], generatedLoop);
for (; i < afterFuse.size(); i++)
- moduleTranslation.mapOmpLoop(op.getGeneratees()[i], afterFuse[i]);
+ mapOmpLoop(moduleTranslation, op.getGeneratees()[i], afterFuse[i]);
}
// CLIs can only be consumed once
for (Value applyee : op.getApplyees())
- moduleTranslation.invalidateOmpLoop(applyee);
+ invalidateOmpLoop(moduleTranslation, applyee);
return success();
}
@@ -5846,7 +5947,7 @@ convertOmpAtomicRead(Operation &opInst, llvm::IRBuilderBase &builder,
if (failed(checkImplementationStatus(opInst)))
return failure();
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
findAllocInsertPoints(builder, moduleTranslation);
@@ -5873,7 +5974,7 @@ convertOmpAtomicWrite(Operation &opInst, llvm::IRBuilderBase &builder,
if (failed(checkImplementationStatus(opInst)))
return failure();
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
findAllocInsertPoints(builder, moduleTranslation);
@@ -5934,7 +6035,7 @@ static LogicalResult
convertOmpAtomicUpdate(omp::AtomicUpdateOp &opInst,
llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
if (failed(checkImplementationStatus(*opInst)))
return failure();
@@ -6313,7 +6414,7 @@ static LogicalResult
convertOmpAtomicCapture(omp::AtomicCaptureOp atomicCaptureOp,
llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
if (failed(checkImplementationStatus(*atomicCaptureOp)))
return failure();
@@ -6761,7 +6862,7 @@ static LogicalResult
convertOmpAtomicCompare(omp::AtomicCompareOp atomicCompareOp,
llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
if (failed(checkImplementationStatus(*atomicCompareOp)))
return failure();
@@ -6979,7 +7080,7 @@ convertOmpCancel(omp::CancelOp op, llvm::IRBuilderBase &builder,
return failure();
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::Value *ifCond = nullptr;
if (Value ifVar = op.getIfExpr())
@@ -7007,7 +7108,7 @@ convertOmpCancellationPoint(omp::CancellationPointOp op,
return failure();
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::omp::Directive cancelledDirective =
convertCancellationConstructType(op.getCancelDirective());
@@ -7029,7 +7130,7 @@ static LogicalResult
convertOmpThreadprivate(Operation &opInst, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
auto threadprivateOp = cast<omp::ThreadprivateOp>(opInst);
if (failed(checkImplementationStatus(opInst)))
@@ -7234,7 +7335,7 @@ static bool isDeclareTargetTo(Value value) {
static llvm::Value *
getRefPtrIfDeclareTarget(Value value,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
if (auto gOp =
dyn_cast_or_null<LLVM::GlobalOp>(getGlobalOpFromValue(value))) {
// In this case, we must utilise the reference pointer generated by
@@ -7320,7 +7421,6 @@ static TargetDirectiveEnumTy getTargetDirectiveEnumTyFromOp(Operation *op) {
.Case([&](omp::TargetOp) { return TargetDirectiveEnumTy::Target; })
.Default([&](Operation *op) { return TargetDirectiveEnumTy::None; });
}
-
} // namespace
static uint64_t getArrayElementSizeInBits(LLVM::LLVMArrayType arrTy,
@@ -7614,7 +7714,7 @@ static void collectMapDataFromMapOperands(
// TODO: set HasAttachPtr from Flang for pointee-storage entries.
mapData.HasAttachPtr.push_back(false);
mapData.Names.push_back(LLVM::createMappingInformation(
- mapOp.getLoc(), *moduleTranslation.getOpenMPBuilder(),
+ mapOp.getLoc(), *getOpenMPBuilder(moduleTranslation),
getMapClauseName(mapOp)));
mapData.DevicePointers.push_back(llvm::OpenMPIRBuilder::DeviceInfoTy::None);
if (mapOp.getMapperId())
@@ -7685,7 +7785,7 @@ static void collectMapDataFromMapOperands(
// TODO: set HasAttachPtr from Flang for pointee-storage entries.
mapData.HasAttachPtr.push_back(false);
mapData.Names.push_back(LLVM::createMappingInformation(
- mapOp.getLoc(), *moduleTranslation.getOpenMPBuilder(),
+ mapOp.getLoc(), *getOpenMPBuilder(moduleTranslation),
getMapClauseName(mapOp)));
mapData.DevicePointers.push_back(devInfoTy);
mapData.Mappers.push_back(nullptr);
@@ -7748,7 +7848,7 @@ static void collectMapDataFromMapOperands(
mapData.Mappers.push_back(nullptr);
}
mapData.Names.push_back(LLVM::createMappingInformation(
- mapOp.getLoc(), *moduleTranslation.getOpenMPBuilder(),
+ mapOp.getLoc(), *getOpenMPBuilder(moduleTranslation),
getMapClauseName(mapOp)));
mapData.DevicePointers.push_back(
isDevicePtr ? llvm::OpenMPIRBuilder::DeviceInfoTy::Pointer
@@ -8447,7 +8547,7 @@ static void
createAlteredByCaptureMap(MapInfoData &mapData,
LLVM::ModuleTranslation &moduleTranslation,
llvm::IRBuilderBase &builder) {
- assert(!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
+ assert(!getOpenMPBuilder(moduleTranslation)->Config.isTargetDevice() &&
"function only supported for host device codegen");
for (size_t i = 0; i < mapData.MapClause.size(); ++i) {
auto mapOp = cast<omp::MapInfoOp>(mapData.MapClause[i]);
@@ -8526,7 +8626,7 @@ static void genMapInfos(llvm::IRBuilderBase &builder,
DataLayout &dl, MapInfosTy &combinedInfo,
MapInfoData &mapData,
TargetDirectiveEnumTy targetDirective) {
- assert(!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
+ assert(!getOpenMPBuilder(moduleTranslation)->Config.isTargetDevice() &&
"function only supported for host device codegen");
// We wish to modify some of the methods in which arguments are
// passed based on their capture type by the target region, this can
@@ -8541,7 +8641,7 @@ static void genMapInfos(llvm::IRBuilderBase &builder,
// pass thee pointer byref as both basePointer and pointer.
createAlteredByCaptureMap(mapData, moduleTranslation, builder);
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
// We operate under the assumption that all vectors that are
// required in MapInfoData are of equal lengths (either filled with
@@ -8574,12 +8674,13 @@ static llvm::Expected<llvm::Function *>
getOrCreateUserDefinedMapperFunc(Operation *op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation,
TargetDirectiveEnumTy targetDirective) {
- assert(!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
+ assert(!getOpenMPBuilder(moduleTranslation)->Config.isTargetDevice() &&
"function only supported for host device codegen");
auto declMapperOp = cast<omp::DeclareMapperOp>(op);
std::string mapperFuncName =
- moduleTranslation.getOpenMPBuilder()->createPlatformSpecificName(
- {"omp_mapper", declMapperOp.getSymName()});
+ getOpenMPBuilder(moduleTranslation)
+ ->createPlatformSpecificName(
+ {"omp_mapper", declMapperOp.getSymName()});
if (auto *lookupFunc = moduleTranslation.lookupFunction(mapperFuncName))
return lookupFunc;
@@ -8604,7 +8705,7 @@ emitUserDefinedMapper(Operation *op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation,
llvm::StringRef mapperFuncName,
TargetDirectiveEnumTy targetDirective) {
- assert(!moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
+ assert(!getOpenMPBuilder(moduleTranslation)->Config.isTargetDevice() &&
"function only supported for host device codegen");
auto declMapperOp = cast<omp::DeclareMapperOp>(op);
auto declMapperInfoOp = declMapperOp.getDeclareMapperInfo();
@@ -8612,7 +8713,7 @@ emitUserDefinedMapper(Operation *op, llvm::IRBuilderBase &builder,
return llvm::make_error<PreviouslyReportedError>();
DataLayout dl = DataLayout(declMapperOp->getParentOfType<ModuleOp>());
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::Type *varType = moduleTranslation.convertType(declMapperOp.getType());
SmallVector<Value> mapVars = declMapperInfoOp.getMapVars();
@@ -8691,7 +8792,7 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
DataLayout DL = DataLayout(op->getParentOfType<ModuleOp>());
TargetDirectiveEnumTy targetDirective = getTargetDirectiveEnumTyFromOp(op);
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::OpenMPIRBuilder::TargetDataInfo info(
/*RequiresDevicePointerInfo=*/true,
/*SeparateBeginEndCalls=*/true);
@@ -8937,7 +9038,7 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
static LogicalResult
convertOmpDistribute(Operation &opInst, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
auto distributeOp = cast<omp::DistributeOp>(opInst);
if (failed(checkImplementationStatus(opInst)))
return failure();
@@ -9004,7 +9105,7 @@ convertOmpDistribute(Operation &opInst, llvm::IRBuilderBase &builder,
distributeOp.getPrivateNeedsBarrier())))
return llvm::make_error<PreviouslyReportedError>();
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
llvm::Expected<llvm::BasicBlock *> regionBlock =
convertOmpOpRegions(distributeOp.getRegion(), "omp.distribute.region",
@@ -9085,7 +9186,7 @@ convertFlagsAttr(Operation *op, mlir::omp::FlagsAttr attribute,
if (!offloadMod)
return op->emitOpError() << "omp flags attached to non offload module op";
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
if (offloadMod.getIsTargetDevice())
ompBuilder->M.addModuleFlag(llvm::Module::Max, "openmp-device",
@@ -9597,7 +9698,7 @@ initTargetRuntimeAttrs(llvm::IRBuilderBase &builder,
attrs.MaxThreads.front() = moduleTranslation.lookupValue(numThreads);
if (targetOp.hasHostEvalTripCount()) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
attrs.LoopTripCount = nullptr;
// To calculate the trip count, we multiply together the trip counts of
@@ -9690,7 +9791,7 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
if (outlinedFnLoc && parentLLVMFn->getSubprogram())
outlinedFnDbgLoc = outlinedFnLoc;
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
bool isTargetDevice = ompBuilder->Config.isTargetDevice();
bool isGPU = ompBuilder->Config.isGPU();
@@ -9943,7 +10044,7 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
llvm::TargetRegionEntryInfo entryInfo;
getTargetEntryUniqueInfo(entryInfo, targetOp,
- *moduleTranslation.getOpenMPBuilder(),
+ *getOpenMPBuilder(moduleTranslation),
moduleTranslation.getFileSystem(), parentName);
MapInfoData mapData;
@@ -10100,12 +10201,13 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
: nullptr;
llvm::OpenMPIRBuilder::InsertPointOrErrorTy afterIP =
- moduleTranslation.getOpenMPBuilder()->createTarget(
- ompLoc, isOffloadEntry, allocaIP, builder.saveIP(), deallocBlocks,
- info, entryInfo, defaultAttrs, runtimeAttrs, ifCond, kernelInput,
- genMapInfoCB, bodyCB, argAccessorCB, customMapperCB, dds,
- targetOp.getNowait(), dynSizeVal, fallbackType, outlinedFnDbgLoc,
- rtLocOverride);
+ getOpenMPBuilder(moduleTranslation)
+ ->createTarget(ompLoc, isOffloadEntry, allocaIP, builder.saveIP(),
+ deallocBlocks, info, entryInfo, defaultAttrs,
+ runtimeAttrs, ifCond, kernelInput, genMapInfoCB,
+ bodyCB, argAccessorCB, customMapperCB, dds,
+ targetOp.getNowait(), dynSizeVal, fallbackType,
+ outlinedFnDbgLoc, rtLocOverride);
if (failed(handleError(afterIP, opInst)))
return failure();
@@ -10171,7 +10273,7 @@ convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute,
llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
if (auto *gVal = llvmModule->getNamedValue(gOp.getSymName())) {
auto *gVar = cast<llvm::GlobalVariable>(gVal);
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
bool isDeclaration = gOp.isDeclaration();
bool isExternallyVisible =
gOp.getVisibility() != mlir::SymbolTable::Visibility::Private;
@@ -10362,7 +10464,7 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
[&](Attribute attr) {
if (auto deviceAttr = dyn_cast<BoolAttr>(attr)) {
llvm::OpenMPIRBuilderConfig &config =
- moduleTranslation.getOpenMPBuilder()->Config;
+ getOpenMPBuilder(moduleTranslation)->Config;
config.setIsTargetDevice(deviceAttr.getValue());
return success();
}
@@ -10372,7 +10474,7 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
[&](Attribute attr) {
if (auto gpuAttr = dyn_cast<BoolAttr>(attr)) {
llvm::OpenMPIRBuilderConfig &config =
- moduleTranslation.getOpenMPBuilder()->Config;
+ getOpenMPBuilder(moduleTranslation)->Config;
config.setIsGPU(gpuAttr.getValue());
return success();
}
@@ -10382,7 +10484,7 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
[&](Attribute attr) {
if (auto filepathAttr = dyn_cast<StringAttr>(attr)) {
llvm::OpenMPIRBuilder *ompBuilder =
- moduleTranslation.getOpenMPBuilder();
+ getOpenMPBuilder(moduleTranslation);
ompBuilder->loadOffloadInfoMetadata(
moduleTranslation.getFileSystem(), filepathAttr.getValue());
return success();
@@ -10399,7 +10501,7 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
[&](Attribute attr) {
if (auto versionAttr = dyn_cast<omp::VersionAttr>(attr)) {
llvm::OpenMPIRBuilder *ompBuilder =
- moduleTranslation.getOpenMPBuilder();
+ getOpenMPBuilder(moduleTranslation);
ompBuilder->M.addModuleFlag(llvm::Module::Max, "openmp",
versionAttr.getVersion());
return success();
@@ -10411,7 +10513,7 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
if (auto declareTargetAttr =
dyn_cast<omp::DeclareTargetAttr>(attr)) {
llvm::OpenMPIRBuilder *ompBuilder =
- moduleTranslation.getOpenMPBuilder();
+ getOpenMPBuilder(moduleTranslation);
return convertDeclareTargetAttr(op, declareTargetAttr,
ompBuilder, moduleTranslation);
}
@@ -10423,7 +10525,7 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
using Requires = omp::ClauseRequires;
Requires flags = requiresAttr.getValue();
llvm::OpenMPIRBuilderConfig &config =
- moduleTranslation.getOpenMPBuilder()->Config;
+ getOpenMPBuilder(moduleTranslation)->Config;
config.setHasRequiresReverseOffload(
bitEnumContainsAll(flags, Requires::reverse_offload));
config.setHasRequiresUnifiedAddress(
@@ -10440,7 +10542,7 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
[&](Attribute attr) {
if (auto triplesAttr = dyn_cast<ArrayAttr>(attr)) {
llvm::OpenMPIRBuilderConfig &config =
- moduleTranslation.getOpenMPBuilder()->Config;
+ getOpenMPBuilder(moduleTranslation)->Config;
config.TargetTriples.clear();
config.TargetTriples.reserve(triplesAttr.size());
for (Attribute tripleAttr : triplesAttr) {
@@ -10457,7 +10559,7 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation(
[&](Attribute attr) {
if (auto wrapAttr = dyn_cast<omp::IntegerWrapAroundAttr>(attr)) {
llvm::OpenMPIRBuilderConfig &config =
- moduleTranslation.getOpenMPBuilder()->Config;
+ getOpenMPBuilder(moduleTranslation)->Config;
config.setNoSignedWrap(!wrapAttr.getIntegerWrapAround());
return success();
}
@@ -10578,7 +10680,7 @@ static LogicalResult
convertAllocSharedMemOp(omp::AllocSharedMemOp allocMemOp,
llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::Value *size = getAllocationSize(builder, moduleTranslation, allocMemOp);
moduleTranslation.mapValue(allocMemOp.getResult(),
ompBuilder->createOMPAllocShared(builder, size));
@@ -10590,7 +10692,7 @@ convertAllocateDirOp(Operation &opInst, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation,
const OpenMPDialectLLVMIRTranslationInterface &ompIface) {
auto allocateDirOp = cast<omp::AllocateDirOp>(opInst);
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
llvm::Module *llvmModule = moduleTranslation.getLLVMModule();
@@ -10669,7 +10771,7 @@ convertAllocateFreeOp(Operation &opInst, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation,
const OpenMPDialectLLVMIRTranslationInterface &ompIface) {
auto freeOp = cast<omp::AllocateFreeOp>(opInst);
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
llvm::Value *allocator;
@@ -10735,7 +10837,7 @@ static LogicalResult
convertFreeSharedMemOp(omp::FreeSharedMemOp freeMemOp,
llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
llvm::Value *size = getAllocationSize(builder, moduleTranslation, freeMemOp);
ompBuilder->createOMPFreeShared(
builder, moduleTranslation.lookupValue(freeMemOp.getHeapref()), size);
@@ -10746,7 +10848,7 @@ convertFreeSharedMemOp(omp::FreeSharedMemOp freeMemOp,
static LogicalResult
convertOmpGroupprivate(Operation &opInst, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
auto groupprivateOp = cast<omp::GroupprivateOp>(opInst);
if (failed(checkImplementationStatus(opInst)))
@@ -10817,7 +10919,7 @@ convertOmpGroupprivate(Operation &opInst, llvm::IRBuilderBase &builder,
LogicalResult OpenMPDialectLLVMIRTranslationInterface::convertOperation(
Operation *op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) const {
- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+ llvm::OpenMPIRBuilder *ompBuilder = getOpenMPBuilder(moduleTranslation);
if (ompBuilder->Config.isTargetDevice() &&
!isa<omp::TargetOp, omp::MapInfoOp, omp::TerminatorOp, omp::YieldOp>(
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 1e90f6534a969b..8a208580f36045 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -36,7 +36,6 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Analysis/TargetFolder.h"
-#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constants.h"
@@ -803,10 +802,12 @@ ModuleTranslation::ModuleTranslation(Operation *module,
}
ModuleTranslation::~ModuleTranslation() {
- if (ompBuilder && !ompBuilder->isFinalized())
- ompBuilder->finalize();
+ // Destroy extensions while the rest of the translation state is still alive.
+ extensions.clear();
}
+ModuleTranslation::Extension::~Extension() = default;
+
void ModuleTranslation::forgetMapping(Region ®ion) {
SmallVector<Region *> toProcess;
toProcess.push_back(®ion);
@@ -2595,32 +2596,6 @@ void ModuleTranslation::remapAllValuesWith(llvm::Value *oldValue,
entry.second = newValue;
}
-llvm::OpenMPIRBuilder *ModuleTranslation::getOpenMPBuilder() {
- if (!ompBuilder) {
- ompBuilder = std::make_unique<llvm::OpenMPIRBuilder>(*llvmModule);
-
- // 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);
- unsigned int defaultAS =
- llvmModule->getDataLayout().getProgramAddressSpace();
- config.setDefaultTargetAS(defaultAS);
- config.setRuntimeCC(llvmModule->getTargetTriple().isSPIRV()
- ? llvm::CallingConv::SPIR_FUNC
- : llvm::CallingConv::C);
- ompBuilder->setConfig(std::move(config));
- ompBuilder->initialize();
- }
- return ompBuilder.get();
-}
-
llvm::vfs::FileSystem &ModuleTranslation::getFileSystem() {
if (fileSystem)
return *fileSystem;
@@ -2790,9 +2765,12 @@ mlir::translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext,
// beforehand.
translator.debugTranslation->addModuleFlagsIfNotPresent();
- // Call the OpenMP IR Builder callbacks prior to verifying the module
- if (auto *ompBuilder = translator.getOpenMPBuilder())
- ompBuilder->finalize();
+ // Let dialect translations complete their pending work (e.g. OpenMP region
+ // outlining) prior to verifying the module. Index-based iteration tolerates
+ // extensions created during finalization.
+ for (size_t i = 0; i < translator.extensions.size(); ++i)
+ if (failed(translator.extensions.begin()[i].second->finalize()))
+ return nullptr;
if (!disableVerification &&
llvm::verifyModule(*translator.llvmModule, &llvm::errs()))
More information about the Mlir-commits
mailing list