Skip to content

Commit 38fcf62

Browse files
wsmosesftynse
andauthored
[MLIR] Import LLVM add flag to disable loadalldialects (#122574)
Co-authored-by: Oleksandr "Alex" Zinenko <[email protected]>
1 parent b306eff commit 38fcf62

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

mlir/include/mlir/Target/LLVMIR/Import.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ class ModuleOp;
3939
/// be imported without elements. If set, the option avoids the recursive
4040
/// traversal of composite type debug information, which can be expensive for
4141
/// adversarial inputs.
42+
/// The `loadAllDialects` flag (default on) will load all dialects in the
43+
/// context.
4244
OwningOpRef<ModuleOp>
4345
translateLLVMIRToModule(std::unique_ptr<llvm::Module> llvmModule,
4446
MLIRContext *context, bool emitExpensiveWarnings = true,
45-
bool dropDICompositeTypeElements = false);
47+
bool dropDICompositeTypeElements = false,
48+
bool loadAllDialects = true);
4649

4750
/// Translate the given LLVM data layout into an MLIR equivalent using the DLTI
4851
/// dialect.

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,8 @@ ModuleImport::translateLoopAnnotationAttr(const llvm::MDNode *node,
23252325
OwningOpRef<ModuleOp>
23262326
mlir::translateLLVMIRToModule(std::unique_ptr<llvm::Module> llvmModule,
23272327
MLIRContext *context, bool emitExpensiveWarnings,
2328-
bool dropDICompositeTypeElements) {
2328+
bool dropDICompositeTypeElements,
2329+
bool loadAllDialects) {
23292330
// Preload all registered dialects to allow the import to iterate the
23302331
// registered LLVMImportDialectInterface implementations and query the
23312332
// supported LLVM IR constructs before starting the translation. Assumes the
@@ -2335,7 +2336,8 @@ mlir::translateLLVMIRToModule(std::unique_ptr<llvm::Module> llvmModule,
23352336
LLVMDialect::getDialectNamespace()));
23362337
assert(llvm::is_contained(context->getAvailableDialects(),
23372338
DLTIDialect::getDialectNamespace()));
2338-
context->loadAllAvailableDialects();
2339+
if (loadAllDialects)
2340+
context->loadAllAvailableDialects();
23392341
OwningOpRef<ModuleOp> module(ModuleOp::create(FileLineColLoc::get(
23402342
StringAttr::get(context, llvmModule->getSourceFileName()), /*line=*/0,
23412343
/*column=*/0)));

0 commit comments

Comments
 (0)