Skip to content

Commit

Permalink
[MLIR] Avoid adding debuginfo for a function if it contains calls tha…
Browse files Browse the repository at this point in the history
…t has no debug info.

Also add a verifier pass to ExecutionEngine.

It's hard to come up with a test case, since mlir-opt always add location info after parsing it (?)

Differential Revision: https://reviews.llvm.org/D88135
  • Loading branch information
timshen91 committed Sep 29, 2020
1 parent 01a30fa commit f0506e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@

#include "llvm/ADT/StringRef.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/ToolOutputFile.h"

using namespace mlir;

std::unique_ptr<llvm::Module>
mlir::translateModuleToLLVMIR(ModuleOp m, llvm::LLVMContext &llvmContext,
StringRef name) {
return LLVM::ModuleTranslation::translateModule<>(m, llvmContext, name);
auto llvmModule =
LLVM::ModuleTranslation::translateModule<>(m, llvmContext, name);
if (verifyModule(*llvmModule))
emitError(m.getLoc(), "LLVM IR fails to verify");
return llvmModule;
}

namespace mlir {
Expand Down
12 changes: 12 additions & 0 deletions mlir/lib/Target/LLVMIR/DebugTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ void DebugTranslation::translate(LLVMFuncOp func, llvm::Function &llvmFunc) {
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<UnknownLoc>() ? WalkResult::interrupt()
: WalkResult::advance();
})
.wasInterrupted();
if (hasCallWithoutDebugInfo)
return;

FileLineColLoc fileLoc = extractFileLoc(func.getLoc());
auto *file = translateFile(fileLoc ? fileLoc.getFilename() : "<unknown>");
unsigned line = fileLoc ? fileLoc.getLine() : 0;
Expand Down
4 changes: 0 additions & 4 deletions mlir/test/Target/llvmir-debug.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ llvm.func @func_no_debug() {
// CHECK-LABEL: define void @func_with_debug()
// CHECK-SAME: !dbg ![[FUNC_LOC:[0-9]+]]
llvm.func @func_with_debug() {
// CHECK: call void @func_no_debug()
// CHECK-NOT: !dbg
llvm.call @func_no_debug() : () -> () loc(unknown)

// CHECK: call void @func_no_debug(), !dbg ![[CALLSITE_LOC:[0-9]+]]
llvm.call @func_no_debug() : () -> () loc(callsite("mysource.cc":3:4 at "mysource.cc":5:6))

Expand Down

0 comments on commit f0506e4

Please sign in to comment.