Skip to content

Commit 9af3339

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6-beta.1
1 parent 007f601 commit 9af3339

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

llvm/lib/CodeGen/MachineInstr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363

6464
using namespace llvm;
6565

66+
static cl::opt<bool>
67+
PrintMIAddrs("print-mi-addrs", cl::Hidden,
68+
cl::desc("Print addresses of MachineInstrs when dumping"));
69+
6670
static const MachineFunction *getMFIfAvailable(const MachineInstr &MI) {
6771
if (const MachineBasicBlock *MBB = MI.getParent())
6872
if (const MachineFunction *MF = MBB->getParent())
@@ -2059,6 +2063,9 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST,
20592063
}
20602064
// TODO: DBG_LABEL
20612065

2066+
if (PrintMIAddrs)
2067+
OS << " ; " << this;
2068+
20622069
if (AddNewLine)
20632070
OS << '\n';
20642071
}

llvm/lib/IR/AsmWriter.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@
8888

8989
using namespace llvm;
9090

91+
static cl::opt<bool>
92+
PrintInstAddrs("print-inst-addrs", cl::Hidden,
93+
cl::desc("Print addresses of instructions when dumping"));
94+
95+
static cl::opt<bool> PrintInstDebugLocs(
96+
"print-inst-debug-locs", cl::Hidden,
97+
cl::desc("Pretty print debug locations of instructions when dumping"));
98+
9199
// Make virtual table appear in this compilation unit.
92100
AssemblyAnnotationWriter::~AssemblyAnnotationWriter() = default;
93101

@@ -4236,6 +4244,18 @@ void AssemblyWriter::printInfoComment(const Value &V) {
42364244
if (AnnotationWriter) {
42374245
AnnotationWriter->printInfoComment(V, Out);
42384246
}
4247+
4248+
if (PrintInstDebugLocs) {
4249+
if (auto *I = dyn_cast<Instruction>(&V)) {
4250+
if (I->getDebugLoc()) {
4251+
Out << " ; ";
4252+
I->getDebugLoc().print(Out);
4253+
}
4254+
}
4255+
}
4256+
4257+
if (PrintInstAddrs)
4258+
Out << " ; " << &V;
42394259
}
42404260

42414261
static void maybePrintCallAddrSpace(const Value *Operand, const Instruction *I,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; RUN: opt -S -print-inst-addrs %s | FileCheck %s
2+
3+
define void @foo() {
4+
; CHECK: ret void ; 0x
5+
ret void
6+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: opt -S -print-inst-debug-locs < %s | FileCheck %s
2+
3+
define weak i32 @foo(i32 %a, i32 %b) !dbg !3 {
4+
entry:
5+
; CHECK: call {{.*}} ; foo.c:52
6+
%sum = call i32 @fastadd(i32 %a, i32 %b), !dbg !DILocation(line: 52, scope: !3)
7+
; CHECK: ret {{.*}} ; foo.c:53
8+
ret i32 %sum, !dbg !DILocation(line: 53, scope: !3)
9+
}
10+
11+
declare i32 @fastadd(i32, i32)
12+
13+
!llvm.module.flags = !{!0}
14+
!0 = !{i32 2, !"Debug Info Version", i32 3}
15+
16+
!llvm.dbg.cu = !{!1}
17+
!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, emissionKind: FullDebug)
18+
!2 = !DIFile(filename: "foo.c", directory: "/path/to/dir")
19+
!3 = distinct !DISubprogram(file: !2, scope: !2, line: 51, name: "foo", type: !4, unit: !1)
20+
!4 = !DISubroutineType(types: !{})

llvm/test/Other/print-mi-addrs.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; RUN: llc -print-after=slotindexes -print-mi-addrs < %s 2>&1 | FileCheck %s
2+
; REQUIRES: default_triple
3+
4+
; CHECK: IR Dump {{.*}}
5+
; CHECK: # Machine code for function foo{{.*}}
6+
7+
define void @foo() {
8+
; CHECK: ; 0x
9+
ret void
10+
}
11+

0 commit comments

Comments
 (0)