Skip to content

Commit e5ac263

Browse files
committed
Optionally print !prof metadata inline
1 parent d1bd1c7 commit e5ac263

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

llvm/lib/IR/AsmWriter.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ static cl::opt<bool> PrintInstDebugLocs(
9696
"print-inst-debug-locs", cl::Hidden,
9797
cl::desc("Pretty print debug locations of instructions when dumping"));
9898

99+
static cl::opt<bool> PrintPerfData(
100+
"print-perf-data", cl::Hidden,
101+
cl::desc("Pretty print perf data (branch weights, etc) when dumping"));
102+
99103
// Make virtual table appear in this compilation unit.
100104
AssemblyAnnotationWriter::~AssemblyAnnotationWriter() = default;
101105

@@ -4161,6 +4165,11 @@ void AssemblyWriter::printFunction(const Function *F) {
41614165
writeOperand(F->getPersonalityFn(), /*PrintType=*/true);
41624166
}
41634167

4168+
if (PrintPerfData && F->getEntryCount()) {
4169+
Out << " ";
4170+
F->getMetadata(LLVMContext::MD_prof)->print(Out, TheModule, true);
4171+
}
4172+
41644173
if (F->isDeclaration()) {
41654174
Out << '\n';
41664175
} else {
@@ -4287,6 +4296,14 @@ void AssemblyWriter::printInfoComment(const Value &V) {
42874296
}
42884297
}
42894298
}
4299+
if (PrintPerfData) {
4300+
if (auto *I = dyn_cast<Instruction>(&V)) {
4301+
if (auto *MD = I->getMetadata(LLVMContext::MD_prof)) {
4302+
Out << " ; ";
4303+
MD->print(Out, TheModule, true);
4304+
}
4305+
}
4306+
}
42904307

42914308
if (PrintInstAddrs)
42924309
Out << " ; " << &V;

llvm/test/Other/print-prof-data.ll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; RUN: opt %s -print-prof-data -S | FileCheck %s
2+
3+
define void @foo(ptr %p) !prof !0 {
4+
%isnull = icmp eq ptr %p, null
5+
br i1 %isnull, label %yes, label %no, !prof !1
6+
yes:
7+
%something = select i1 %isnull, i32 1, i32 2, !prof !2
8+
br label %exit
9+
no:
10+
call void %p(), !prof !3
11+
br label %exit
12+
exit:
13+
ret void
14+
}
15+
16+
!0 = !{!"function_entry_count", i64 42}
17+
!1 = !{!"branch_weights", i64 20, i64 101}
18+
!2 = !{!"branch_weights", i64 5, i64 70}
19+
!3 = !{!"VP", i32 0, i64 4, i64 4445083295448962937, i64 2, i64 -2718743882639408571, i64 2}
20+
21+
; CHECK: define void @foo(ptr %p) !0 = !{!"function_entry_count", i64 42} !prof !0 {
22+
; CHECK: br i1 %isnull, label %yes, label %no, !prof !1 ; !1 = !{!"branch_weights", i64 20, i64 101}
23+
; CHECK: %something = select i1 %isnull, i32 1, i32 2, !prof !2 ; !2 = !{!"branch_weights", i64 5, i64 70}
24+
; CHECK: call void %p(), !prof !3 ; !3 = !{!"VP", i32 0, i64 4, i64 4445083295448962937, i64 2, i64 -2718743882639408571, i64 2}

llvm/test/Other/print-prof-data.s

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.file "print-prof-data.ll"
2+
.text
3+
.globl foo # -- Begin function foo
4+
.p2align 4
5+
.type foo,@function
6+
foo: # @foo
7+
.cfi_startproc
8+
# %bb.0:
9+
testq %rdi, %rdi
10+
je .LBB0_2
11+
# %bb.1: # %no
12+
pushq %rax
13+
.cfi_def_cfa_offset 16
14+
callq *%rdi
15+
addq $8, %rsp
16+
.cfi_def_cfa_offset 8
17+
.LBB0_2: # %exit
18+
retq
19+
.Lfunc_end0:
20+
.size foo, .Lfunc_end0-foo
21+
.cfi_endproc
22+
# -- End function
23+
.section ".note.GNU-stack","",@progbits

0 commit comments

Comments
 (0)