Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions llvm/lib/CodeGen/MachineInstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@

using namespace llvm;

static cl::opt<bool>
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())
Expand Down Expand Up @@ -2059,6 +2063,9 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST,
}
// TODO: DBG_LABEL

if (PrintMIAddrs)
OS << " ; " << this;

if (AddNewLine)
OS << '\n';
}
Expand Down
20 changes: 20 additions & 0 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@

using namespace llvm;

static cl::opt<bool>
PrintInstAddrs("print-inst-addrs", cl::Hidden,
cl::desc("Print addresses of instructions when dumping"));

static cl::opt<bool> 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;

Expand Down Expand Up @@ -4236,6 +4244,18 @@ void AssemblyWriter::printInfoComment(const Value &V) {
if (AnnotationWriter) {
AnnotationWriter->printInfoComment(V, Out);
}

if (PrintInstDebugLocs) {
if (auto *I = dyn_cast<Instruction>(&V)) {
if (I->getDebugLoc()) {
Out << " ; ";
I->getDebugLoc().print(Out);
}
}
}

if (PrintInstAddrs)
Out << " ; " << &V;
}

static void maybePrintCallAddrSpace(const Value *Operand, const Instruction *I,
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/Other/print-inst-addrs.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; RUN: opt -S -print-inst-addrs %s | FileCheck %s

define void @foo() {
; CHECK: ret void ; 0x
ret void
}
20 changes: 20 additions & 0 deletions llvm/test/Other/print-inst-debug-locs.ll
Original file line number Diff line number Diff line change
@@ -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: !{})
11 changes: 11 additions & 0 deletions llvm/test/Other/print-mi-addrs.ll
Original file line number Diff line number Diff line change
@@ -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
}