diff --git a/mlir/include/mlir/Target/LLVMIR/Import.h b/mlir/include/mlir/Target/LLVMIR/Import.h index 4a1242a8eb059..4aa8f2ab7d8ce 100644 --- a/mlir/include/mlir/Target/LLVMIR/Import.h +++ b/mlir/include/mlir/Target/LLVMIR/Import.h @@ -39,10 +39,13 @@ class ModuleOp; /// be imported without elements. If set, the option avoids the recursive /// traversal of composite type debug information, which can be expensive for /// adversarial inputs. +/// The `loadAllDialects` flag (default on) will load all dialects in the +/// context. OwningOpRef translateLLVMIRToModule(std::unique_ptr llvmModule, MLIRContext *context, bool emitExpensiveWarnings = true, - bool dropDICompositeTypeElements = false); + bool dropDICompositeTypeElements = false, + bool loadAllDialects = true); /// Translate the given LLVM data layout into an MLIR equivalent using the DLTI /// dialect. diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp index 2d8d7745eca9b..eba86f06d0905 100644 --- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp @@ -2325,7 +2325,8 @@ ModuleImport::translateLoopAnnotationAttr(const llvm::MDNode *node, OwningOpRef mlir::translateLLVMIRToModule(std::unique_ptr llvmModule, MLIRContext *context, bool emitExpensiveWarnings, - bool dropDICompositeTypeElements) { + bool dropDICompositeTypeElements, + bool loadAllDialects) { // Preload all registered dialects to allow the import to iterate the // registered LLVMImportDialectInterface implementations and query the // supported LLVM IR constructs before starting the translation. Assumes the @@ -2335,7 +2336,8 @@ mlir::translateLLVMIRToModule(std::unique_ptr llvmModule, LLVMDialect::getDialectNamespace())); assert(llvm::is_contained(context->getAvailableDialects(), DLTIDialect::getDialectNamespace())); - context->loadAllAvailableDialects(); + if (loadAllDialects) + context->loadAllAvailableDialects(); OwningOpRef module(ModuleOp::create(FileLineColLoc::get( StringAttr::get(context, llvmModule->getSourceFileName()), /*line=*/0, /*column=*/0)));