[CSSPGO][llvm-profgen] Fix getCanonicalFnName usage in llvm-profgen

Previously we didn't support to keep the unique linkage name(-funique-internal-linkage-name) in llvm-profgen. As discussed in https://reviews.llvm.org/D96932, we choose to do canonicalization for it.

Now since "selected" is set as the default parameter of getCanonicalFnName in `D96932`, we don't need to add any attribute here for the previous usage and only fix the missing usage in the pseudo probe decoding.

Differential Revision: https://reviews.llvm.org/D98226
This commit is contained in:
wlei 2021-03-03 20:37:19 -08:00
parent 0a954a528b
commit dddd590fd0
8 changed files with 95 additions and 13 deletions

View File

@ -0,0 +1,5 @@
PERF_RECORD_MMAP2 3021905/3021905: [0x400000(0x1000) @ 0 00:1d 306132807 1941166]: r-xp unique-linkage-name-dwarf.perfbin
4006de
5541f689495641d7
0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0 0x4006fb/0x4006d0/M/-/-/0 0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0 0x400728/0x4006de/P/-/-/0

View File

@ -0,0 +1,5 @@
PERF_RECORD_MMAP2 3933222/3933222: [0x201000(0x1000) @ 0 00:1d 306175638 1941562]: r-xp unique-linkage-name-probe.perfbin
2017ce
5541f689495641d7
0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0 0x201818/0x2017ce/P/-/-/0

View File

@ -0,0 +1,54 @@
; Test unique linkage name decoding and canonicalization from dwarf debug info
; RUN: llvm-profgen --perfscript=%S/Inputs/unique-linkage-name-dwarf.perfscript --binary=%S/Inputs/unique-linkage-name-dwarf.perfbin --output=%t --csprof-cold-thres=0
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-DWARF-FNAME
; CHECK-DWARF-FNAME:[main:1 @ foo]:309:0
; CHECK-DWARF-FNAME: 2: 14
; CHECK-DWARF-FNAME: 3: 29 bar.__uniq.26267048767521081047744692097241227776:14
; CHECK-DWARF-FNAME:[main:1 @ foo:3 @ bar.__uniq.26267048767521081047744692097241227776]:84:0
; CHECK-DWARF-FNAME: 1: 14
; Test unique linkage name decoding and canonicalization from pseudo probe info
; RUN: llvm-profgen --perfscript=%S/Inputs/unique-linkage-name-probe.perfscript --binary=%S/Inputs/unique-linkage-name-probe.perfbin --output=%t --csprof-cold-thres=0
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-PROBE-FNAME
; CHECK-PROBE-FNAME:[main:2 @ foo]:75:0
; CHECK-PROBE-FNAME: 2: 15
; CHECK-PROBE-FNAME: 3: 15
; CHECK-PROBE-FNAME: 4: 15
; CHECK-PROBE-FNAME: 6: 15
; CHECK-PROBE-FNAME: 8: 15 _ZL3barii.__uniq.26267048767521081047744692097241227776:15
; CHECK-PROBE-FNAME: !CFGChecksum: 563088904013236
; CHECK-PROBE-FNAME:[main:2 @ foo:8 @ _ZL3barii.__uniq.26267048767521081047744692097241227776]:30:15
; CHECK-PROBE-FNAME: 1: 15
; CHECK-PROBE-FNAME: 2: 18446744073709551615
; CHECK-PROBE-FNAME: 3: 18446744073709551615
; CHECK-PROBE-FNAME: 4: 15
; CHECK-PROBE-FNAME: !CFGChecksum: 72617220756
; Original code:
; Dwarf: clang -O3 -funique-internal-linkage-names -g test.c -o a.out
; Probe: clang -O3 -funique-internal-linkage-names -fexperimental-new-pass-manager -fuse-ld=lld -fpseudo-probe-for-profiling -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Xclang -mdisable-tail-calls -g test.c -o a.out
#include <stdio.h>
static int bar(int x, int y) {
if (x % 3) {
return x - y;
}
return x + y;
}
void foo() {
int s, i = 0;
while (i++ < 4000 * 4000)
if (i % 91) s = bar(i, s); else s += 30;
printf("sum is %d\n", s);
}
int main() {
foo();
return 0;
}

View File

@ -1,18 +1,29 @@
; REQUIRES: x86-registered-target
; RUN: llc -filetype=obj %s -o %t
; RUN: llvm-profgen --binary=%t --perfscript=%s --output=%t1 --show-disassembly-only -x86-asm-syntax=intel --show-source-locations | FileCheck %s --match-full-lines
; RUN: llvm-profgen --binary=%t --perfscript=%s --output=%t2 --show-disassembly-only -x86-asm-syntax=intel --show-source-locations --show-canonical-fname | FileCheck %s --match-full-lines --check-prefix=CHECK-CANO
; CHECK: Disassembly of section .text [0x0, 0x4a]:
; CHECK: <funcA>:
; CHECK: 0: mov eax, edi funcA:0
; CHECK: 2: mov ecx, dword ptr [rip] funcLeaf:2 @ funcA:1
; CHECK: 8: lea edx, [rcx + 3] fib:2 @ funcLeaf:2 @ funcA:1
; CHECK: b: cmp ecx, 3 fib:2 @ funcLeaf:2 @ funcA:1
; CHECK: e: cmovl edx, ecx fib:2 @ funcLeaf:2 @ funcA:1
; CHECK: 11: sub eax, edx funcLeaf:2 @ funcA:1
; CHECK: 13: ret funcA:2
; CHECK: <funcA.llvm.1000>:
; CHECK: 0: mov eax, edi funcA.llvm.1000:0
; CHECK: 2: mov ecx, dword ptr [rip] funcLeaf:2 @ funcA.llvm.1000:1
; CHECK: 8: lea edx, [rcx + 3] fib:2 @ funcLeaf:2 @ funcA.llvm.1000:1
; CHECK: b: cmp ecx, 3 fib:2 @ funcLeaf:2 @ funcA.llvm.1000:1
; CHECK: e: cmovl edx, ecx fib:2 @ funcLeaf:2 @ funcA.llvm.1000:1
; CHECK: 11: sub eax, edx funcLeaf:2 @ funcA.llvm.1000:1
; CHECK: 13: ret funcA.llvm.1000:2
; CHECK: 14: nop word ptr cs:[rax + rax]
; CHECK: 1e: nop
; CHECK-CANO: <funcA>:
; CHECK-CANO: 0: mov eax, edi funcA:0
; CHECK-CANO: 2: mov ecx, dword ptr [rip] funcLeaf:2 @ funcA:1
; CHECK-CANO: 8: lea edx, [rcx + 3] fib:2 @ funcLeaf:2 @ funcA:1
; CHECK-CANO: b: cmp ecx, 3 fib:2 @ funcLeaf:2 @ funcA:1
; CHECK-CANO: e: cmovl edx, ecx fib:2 @ funcLeaf:2 @ funcA:1
; CHECK-CANO: 11: sub eax, edx funcLeaf:2 @ funcA:1
; CHECK-CANO: 13: ret funcA:2
; CHECK-CANO: 14: nop word ptr cs:[rax + rax]
; CHECK-CANO: 1e: nop
; CHECK: <funcLeaf>:
; CHECK: 20: mov eax, edi funcLeaf:1
; CHECK: 22: mov ecx, dword ptr [rip] funcLeaf:2
@ -34,7 +45,7 @@ target triple = "x86_64-unknown-linux-gnu"
@factor = dso_local global i32 3
define dso_local i32 @funcA(i32 %x) !dbg !12 {
define dso_local i32 @funcA.llvm.1000(i32 %x) !dbg !12 {
entry:
call void @llvm.dbg.value(metadata i32 %x, metadata !16, metadata !DIExpression()), !dbg !18
call void @llvm.dbg.value(metadata i32 %x, metadata !19, metadata !DIExpression()), !dbg !22
@ -85,7 +96,7 @@ declare void @llvm.dbg.value(metadata, metadata, metadata) #2
!8 = !{i32 7, !"Dwarf Version", i32 4}
!9 = !{i32 2, !"Debug Info Version", i32 3}
!10 = !{i32 1, !"wchar_size", i32 4}
!12 = distinct !DISubprogram(name: "funcA", scope: !3, file: !3, line: 6, type: !13, scopeLine: 6, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !15)
!12 = distinct !DISubprogram(name: "funcA.llvm.1000", scope: !3, file: !3, line: 6, type: !13, scopeLine: 6, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !15)
!13 = !DISubroutineType(types: !14)
!14 = !{!7, !7}
!15 = !{!16, !17}

View File

@ -30,6 +30,10 @@ cl::opt<bool> ShowSourceLocations("show-source-locations", cl::ReallyHidden,
cl::init(false), cl::ZeroOrMore,
cl::desc("Print source locations."));
cl::opt<bool> ShowCanonicalFnName("show-canonical-fname", cl::ReallyHidden,
cl::init(false), cl::ZeroOrMore,
cl::desc("Print canonical function name."));
cl::opt<bool> ShowPseudoProbe(
"show-pseudo-probe", cl::ReallyHidden, cl::init(false), cl::ZeroOrMore,
cl::desc("Print pseudo probe section and disassembled info."));
@ -213,7 +217,10 @@ bool ProfiledBinary::dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
if (StartOffset >= EndOffset)
return true;
std::string &&SymbolName = Symbols[SI].Name.str();
StringRef SymbolName =
ShowCanonicalFnName
? FunctionSamples::getCanonicalFnName(Symbols[SI].Name)
: Symbols[SI].Name;
if (ShowDisassemblyOnly)
outs() << '<' << SymbolName << ">:\n";
@ -253,7 +260,7 @@ bool ProfiledBinary::dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
if (Cur < 40)
outs().indent(40 - Cur);
InstructionPointer IP(this, Offset);
outs() << getReversedLocWithContext(symbolize(IP));
outs() << getReversedLocWithContext(symbolize(IP, ShowCanonicalFnName));
}
outs() << "\n";
}

View File

@ -162,7 +162,7 @@ void PseudoProbeDecoder::buildGUID2FuncDescMap(const uint8_t *Start,
uint64_t GUID = readUnencodedNumber<uint64_t>();
uint64_t Hash = readUnencodedNumber<uint64_t>();
uint32_t NameSize = readUnsignedNumber<uint32_t>();
StringRef Name = readString(NameSize);
StringRef Name = FunctionSamples::getCanonicalFnName(readString(NameSize));
// Initialize PseudoProbeFuncDesc and populate it into GUID2FuncDescMap
GUID2FuncDescMap.emplace(GUID, PseudoProbeFuncDesc(GUID, Hash, Name));