diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp index 52c977a3651a3..6b7e74c04f6d5 100644 --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -63,6 +63,10 @@ using namespace llvm; +static cl::opt + PrintMIAddrs("print-mi-addrs", cl::Hidden, + cl::desc("Print addresses of MachineInstrs when dumping")); + static const MachineFunction *getMFIfAvailable(const MachineInstr &MI) { if (const MachineBasicBlock *MBB = MI.getParent()) if (const MachineFunction *MF = MBB->getParent()) @@ -2059,6 +2063,9 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, } // TODO: DBG_LABEL + if (PrintMIAddrs) + OS << " ; " << this; + if (AddNewLine) OS << '\n'; } diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 57e9cccdc0fb6..73e6d1c9b0b2f 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -88,6 +88,14 @@ using namespace llvm; +static cl::opt + PrintInstAddrs("print-inst-addrs", cl::Hidden, + cl::desc("Print addresses of instructions when dumping")); + +static cl::opt PrintInstDebugLocs( + "print-inst-debug-locs", cl::Hidden, + cl::desc("Pretty print debug locations of instructions when dumping")); + // Make virtual table appear in this compilation unit. AssemblyAnnotationWriter::~AssemblyAnnotationWriter() = default; @@ -4236,6 +4244,18 @@ void AssemblyWriter::printInfoComment(const Value &V) { if (AnnotationWriter) { AnnotationWriter->printInfoComment(V, Out); } + + if (PrintInstDebugLocs) { + if (auto *I = dyn_cast(&V)) { + if (I->getDebugLoc()) { + Out << " ; "; + I->getDebugLoc().print(Out); + } + } + } + + if (PrintInstAddrs) + Out << " ; " << &V; } static void maybePrintCallAddrSpace(const Value *Operand, const Instruction *I, diff --git a/llvm/test/Other/print-inst-addrs.ll b/llvm/test/Other/print-inst-addrs.ll new file mode 100644 index 0000000000000..5907b30f0f12c --- /dev/null +++ b/llvm/test/Other/print-inst-addrs.ll @@ -0,0 +1,6 @@ +; RUN: opt -S -print-inst-addrs %s | FileCheck %s + +define void @foo() { + ; CHECK: ret void ; 0x + ret void +} diff --git a/llvm/test/Other/print-inst-debug-locs.ll b/llvm/test/Other/print-inst-debug-locs.ll new file mode 100644 index 0000000000000..93210527e27a7 --- /dev/null +++ b/llvm/test/Other/print-inst-debug-locs.ll @@ -0,0 +1,20 @@ +; RUN: opt -S -print-inst-debug-locs < %s | FileCheck %s + +define weak i32 @foo(i32 %a, i32 %b) !dbg !3 { +entry: + ; CHECK: call {{.*}} ; foo.c:52 + %sum = call i32 @fastadd(i32 %a, i32 %b), !dbg !DILocation(line: 52, scope: !3) + ; CHECK: ret {{.*}} ; foo.c:53 + ret i32 %sum, !dbg !DILocation(line: 53, scope: !3) +} + +declare i32 @fastadd(i32, i32) + +!llvm.module.flags = !{!0} +!0 = !{i32 2, !"Debug Info Version", i32 3} + +!llvm.dbg.cu = !{!1} +!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, emissionKind: FullDebug) +!2 = !DIFile(filename: "foo.c", directory: "/path/to/dir") +!3 = distinct !DISubprogram(file: !2, scope: !2, line: 51, name: "foo", type: !4, unit: !1) +!4 = !DISubroutineType(types: !{}) diff --git a/llvm/test/Other/print-mi-addrs.ll b/llvm/test/Other/print-mi-addrs.ll new file mode 100644 index 0000000000000..5be006d9df282 --- /dev/null +++ b/llvm/test/Other/print-mi-addrs.ll @@ -0,0 +1,11 @@ +; RUN: llc -print-after=slotindexes -print-mi-addrs < %s 2>&1 | FileCheck %s +; REQUIRES: default_triple + +; CHECK: IR Dump {{.*}} +; CHECK: # Machine code for function foo{{.*}} + +define void @foo() { + ; CHECK: ; 0x + ret void +} +