Skip to content

Commit 9f9f89d

Browse files
committed
Remove dependency from LLVM Dialect on the OpenMP dialect
The OmpDialect is in practice optional during translation to LLVM IR: the code is tolerant to have a "nullptr" when not present / needed. The dependency still exists on the export to LLVMIR. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D88351
1 parent 727c422 commit 9f9f89d

File tree

6 files changed

+9
-11
lines changed

6 files changed

+9
-11
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ def LLVM_Dialect : Dialect {
2525
let name = "llvm";
2626
let cppNamespace = "::mlir::LLVM";
2727

28-
/// FIXME: at the moment this is a dependency of the translation to LLVM IR,
29-
/// not really one of this dialect per-se.
30-
let dependentDialects = ["omp::OpenMPDialect"];
31-
3228
let hasRegionArgAttrVerify = 1;
3329
let hasOperationAttrVerify = 1;
3430
let extraClassDeclaration = [{

mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ class ModuleTranslation {
123123

124124
/// Builder for LLVM IR generation of OpenMP constructs.
125125
std::unique_ptr<llvm::OpenMPIRBuilder> ompBuilder;
126-
/// Precomputed pointer to OpenMP dialect.
126+
/// Precomputed pointer to OpenMP dialect. Note this can be nullptr if the
127+
/// OpenMP dialect hasn't been loaded (it is always loaded if there are OpenMP
128+
/// operations in the module though).
127129
const Dialect *ompDialect;
128130

129131
/// Mappings between llvm.mlir.global definitions and corresponding globals.

mlir/lib/Dialect/LLVMIR/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ add_mlir_dialect_library(MLIRLLVMIR
1818
BitReader
1919
BitWriter
2020
Core
21-
FrontendOpenMP
2221

2322
LINK_LIBS PUBLIC
2423
MLIRCallInterfaces
2524
MLIRControlFlowInterfaces
26-
MLIROpenMP
2725
MLIRIR
2826
MLIRSideEffectInterfaces
2927
MLIRSupport

mlir/lib/Target/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ add_mlir_translation_library(MLIRTargetLLVMIR
5151
IRReader
5252

5353
LINK_LIBS PUBLIC
54+
MLIROpenMP
5455
MLIRTargetLLVMIRModuleTranslation
5556
)
5657

mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ void registerToLLVMIRTranslation() {
4141
llvmModule->print(output, nullptr);
4242
return success();
4343
},
44-
[](DialectRegistry &registry) { registry.insert<LLVM::LLVMDialect>(); });
44+
[](DialectRegistry &registry) {
45+
registry.insert<LLVM::LLVMDialect, omp::OpenMPDialect>();
46+
});
4547
}
4648
} // namespace mlir

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ ModuleTranslation::ModuleTranslation(Operation *module,
302302
: mlirModule(module), llvmModule(std::move(llvmModule)),
303303
debugTranslation(
304304
std::make_unique<DebugTranslation>(module, *this->llvmModule)),
305-
ompDialect(module->getContext()->getOrLoadDialect<omp::OpenMPDialect>()),
305+
ompDialect(module->getContext()->getLoadedDialect("omp")),
306306
typeTranslator(this->llvmModule->getContext()) {
307307
assert(satisfiesLLVMModule(mlirModule) &&
308308
"mlirModule should honor LLVM's module semantics.");
@@ -639,9 +639,8 @@ LogicalResult ModuleTranslation::convertOperation(Operation &opInst,
639639
return success();
640640
}
641641

642-
if (opInst.getDialect() == ompDialect) {
642+
if (ompDialect && opInst.getDialect() == ompDialect)
643643
return convertOmpOperation(opInst, builder);
644-
}
645644

646645
return opInst.emitError("unsupported or non-LLVM operation: ")
647646
<< opInst.getName();

0 commit comments

Comments
 (0)