This is an archive of the discontinued LLVM Phabricator instance.

[CSSPGO][llvm-profgen] Instruction symbolization
ClosedPublic

Authored by wlei on Oct 19 2020, 10:20 AM.

Details

Summary

This stack of changes introduces llvm-profgen utility which generates a profile data file from given perf script data files for sample-based PGO. It’s part of(not only) the CSSPGO work. Specifically to support context-sensitive with/without pseudo probe profile, it implements a series of functionalities including perf trace parsing, instruction symbolization, LBR stack/call frame stack unwinding, pseudo probe decoding, etc. Also high throughput is achieved by multiple levels of sample aggregation and compatible format with one stop is generated at the end. Please refer to: https://groups.google.com/g/llvm-dev/c/1p1rdYbL93s for the CSSPGO RFC.

This change adds the support of instruction symbolization. Given the RVA on an instruction pointer, a full calling context can be printed side-by-side with the disassembly code.
E.g.

Disassembly of section .text [0x0, 0x4a]:

<funcA>:
    0:	mov	eax, edi                           funcA:0
    2:	mov	ecx, dword ptr [rip]               funcLeaf:2 @ funcA:1
    8:	lea	edx, [rcx + 3]                     fib:2 @ funcLeaf:2 @ funcA:1
    b:	cmp	ecx, 3                             fib:2 @ funcLeaf:2 @ funcA:1
    e:	cmovl	edx, ecx                           fib:2 @ funcLeaf:2 @ funcA:1
   11:	sub	eax, edx                           funcLeaf:2 @ funcA:1
   13:	ret                                        funcA:2
   14:	nop	word ptr cs:[rax + rax]
   1e:	nop

<funcLeaf>:
   20:	mov	eax, edi                           funcLeaf:1
   22:	mov	ecx, dword ptr [rip]               funcLeaf:2
   28:	lea	edx, [rcx + 3]                     fib:2 @ funcLeaf:2
   2b:	cmp	ecx, 3                             fib:2 @ funcLeaf:2
   2e:	cmovl	edx, ecx                           fib:2 @ funcLeaf:2
   31:	sub	eax, edx                           funcLeaf:2
   33:	ret                                        funcLeaf:3
   34:	nop	word ptr cs:[rax + rax]
   3e:	nop

<fib>:
   40:	lea	eax, [rdi + 3]                     fib:2
   43:	cmp	edi, 3                             fib:2
   46:	cmovl	eax, edi                           fib:2
   49:	ret                                        fib:8

Test Plan:
ninja check-llvm

Diff Detail

Event Timeline

wlei created this revision.Oct 19 2020, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2020, 10:20 AM
wlei requested review of this revision.Oct 19 2020, 10:20 AM
wlei edited the summary of this revision. (Show Details)Oct 19 2020, 1:20 PM
wlei added reviewers: wenlei, hoy, wmi, davidxl.
wlei retitled this revision from [AutoFDO][llvm-profgen]Instruction symbolization to [CSSPGO][llvm-profgen]Instruction symbolization.Oct 26 2020, 1:16 PM
wlei edited the summary of this revision. (Show Details)
wenlei added inline comments.Oct 30 2020, 2:32 PM
llvm/tools/llvm-profgen/CallContext.h
22

Name it FrameLocation? SourceLocation sounds too general and not different from LineLocation.

25

Name it FrameLocationStack? Also would be good to update the comment to be accurate - this is not a caller, callee pair.

41

std::ostringstream is probably better since there can be quite a few appendings. Same for getReversedLocWithContext.

wlei updated this revision to Diff 303319.Nov 5 2020, 8:27 PM

address reviewers' comments and rebase

wlei updated this revision to Diff 303321.Nov 5 2020, 8:38 PM

fix lint

Harbormaster completed remote builds in B77811: Diff 303321.
wlei updated this revision to Diff 305602.Nov 16 2020, 2:44 PM

rebase and fix clang-tidy warning

wlei updated this revision to Diff 305604.Nov 16 2020, 2:52 PM

miss one clang-tidy warning, fix it

wlei updated this revision to Diff 305630.Nov 16 2020, 5:36 PM

Fix clang-tidy and the wrong type which caused an overflow

wmi accepted this revision.Nov 18 2020, 3:32 PM
wmi added inline comments.
llvm/tools/llvm-profgen/ProfiledBinary.cpp
289

Add some message for the assert(this == IP.Binary && "...");

This revision is now accepted and ready to land.Nov 18 2020, 3:32 PM
wlei updated this revision to Diff 306276.Nov 18 2020, 6:13 PM

[NFC]Add description to an assertion

wenlei accepted this revision.Nov 20 2020, 10:59 AM
wlei retitled this revision from [CSSPGO][llvm-profgen]Instruction symbolization to [CSSPGO][llvm-profgen] Instruction symbolization.Nov 20 2020, 1:36 PM
wlei edited the summary of this revision. (Show Details)
This revision was landed with ongoing or failed builds.Nov 20 2020, 2:27 PM
This revision was automatically updated to reflect the committed changes.