Skip to content

Commit 9b2a349

Browse files
authored
[MLIR][ModuleTranslation] Add disableVerification parameter (NFC) (#94445)
This commit adds a boolean parameter that allows downstream users to disable the verification when translating an MLIR module to LLVM IR. This is helpful for debugging broken LLVM IR modules post translation.
1 parent 851710d commit 9b2a349

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

mlir/include/mlir/Target/LLVMIR/Export.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class Operation;
2626
/// LLVMTranslationDialectInterface.
2727
std::unique_ptr<llvm::Module>
2828
translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext,
29-
llvm::StringRef name = "LLVMDialectModule");
29+
llvm::StringRef name = "LLVMDialectModule",
30+
bool disableVerification = false);
3031
} // namespace mlir
3132

3233
#endif // MLIR_TARGET_LLVMIR_EXPORT_H

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class ComdatSelectorOp;
5757
/// needs to look up block and function mappings.
5858
class ModuleTranslation {
5959
friend std::unique_ptr<llvm::Module>
60-
mlir::translateModuleToLLVMIR(Operation *, llvm::LLVMContext &, StringRef);
60+
mlir::translateModuleToLLVMIR(Operation *, llvm::LLVMContext &, StringRef,
61+
bool);
6162

6263
public:
6364
/// Stores the mapping between a function name and its LLVM IR representation.

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext,
18181818

18191819
std::unique_ptr<llvm::Module>
18201820
mlir::translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext,
1821-
StringRef name) {
1821+
StringRef name, bool disableVerification) {
18221822
if (!satisfiesLLVMModule(module)) {
18231823
module->emitOpError("can not be translated to an LLVMIR module");
18241824
return nullptr;
@@ -1867,7 +1867,8 @@ mlir::translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext,
18671867
if (failed(translator.convertFunctions()))
18681868
return nullptr;
18691869

1870-
if (llvm::verifyModule(*translator.llvmModule, &llvm::errs()))
1870+
if (!disableVerification &&
1871+
llvm::verifyModule(*translator.llvmModule, &llvm::errs()))
18711872
return nullptr;
18721873

18731874
return std::move(translator.llvmModule);

0 commit comments

Comments
 (0)