diff --git a/mlir/lib/ExecutionEngine/OptUtils.cpp b/mlir/lib/ExecutionEngine/OptUtils.cpp --- a/mlir/lib/ExecutionEngine/OptUtils.cpp +++ b/mlir/lib/ExecutionEngine/OptUtils.cpp @@ -18,6 +18,7 @@ #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LegacyPassNameParser.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Verifier.h" #include "llvm/InitializePasses.h" #include "llvm/Pass.h" #include "llvm/Support/Allocator.h" @@ -112,6 +113,7 @@ llvm::legacy::PassManager modulePM; llvm::legacy::FunctionPassManager funcPM(m); + modulePM.add(llvm::createVerifierPass()); bool insertOptPasses = mbOptLevel.hasValue(); for (unsigned i = 0, e = llvmPasses.size(); i < e; ++i) { const auto *passInfo = llvmPasses[i]; diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp --- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp @@ -71,6 +71,18 @@ if (!compileUnit || !func.walk(interruptIfValidLocation).wasInterrupted()) return; + // If we are to create debug info for the function, we need to ensure that all + // inlinable calls in it are with debug info, otherwise the LLVM verifier will + // complain. For now, be more restricted and treat all calls as inlinable. + const bool hasCallWithoutDebugInfo = + func.walk([](LLVM::CallOp call) { + return call.getLoc().isa() ? WalkResult::interrupt() + : WalkResult::advance(); + }) + .wasInterrupted(); + if (hasCallWithoutDebugInfo) + return; + FileLineColLoc fileLoc = extractFileLoc(func.getLoc()); auto *file = translateFile(fileLoc ? fileLoc.getFilename() : ""); unsigned line = fileLoc ? fileLoc.getLine() : 0;