diff --git a/llvm/test/tools/llvm-profgen/Inputs/unique-linkage-name-dwarf.perfbin b/llvm/test/tools/llvm-profgen/Inputs/unique-linkage-name-dwarf.perfbin new file mode 100755 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ + +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; +} diff --git a/llvm/test/tools/llvm-profgen/symbolize.ll b/llvm/test/tools/llvm-profgen/symbolize.ll --- a/llvm/test/tools/llvm-profgen/symbolize.ll +++ b/llvm/test/tools/llvm-profgen/symbolize.ll @@ -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: : -; 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: : +; 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: : +; 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: : ; CHECK: 20: mov eax, edi funcLeaf:1 ; CHECK: 22: mov ecx, dword ptr [rip] funcLeaf:2 @@ -34,7 +45,7 @@ @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 @@ !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} diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp --- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp +++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp @@ -30,6 +30,10 @@ cl::init(false), cl::ZeroOrMore, cl::desc("Print source locations.")); +cl::opt ShowCanonicalFnName("show-canonical-fname", cl::ReallyHidden, + cl::init(false), cl::ZeroOrMore, + cl::desc("Print canonical function name.")); + cl::opt ShowPseudoProbe( "show-pseudo-probe", cl::ReallyHidden, cl::init(false), cl::ZeroOrMore, cl::desc("Print pseudo probe section and disassembled info.")); @@ -213,7 +217,10 @@ 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 @@ if (Cur < 40) outs().indent(40 - Cur); InstructionPointer IP(this, Offset); - outs() << getReversedLocWithContext(symbolize(IP)); + outs() << getReversedLocWithContext(symbolize(IP, ShowCanonicalFnName)); } outs() << "\n"; } diff --git a/llvm/tools/llvm-profgen/PseudoProbe.cpp b/llvm/tools/llvm-profgen/PseudoProbe.cpp --- a/llvm/tools/llvm-profgen/PseudoProbe.cpp +++ b/llvm/tools/llvm-profgen/PseudoProbe.cpp @@ -162,7 +162,7 @@ uint64_t GUID = readUnencodedNumber(); uint64_t Hash = readUnencodedNumber(); uint32_t NameSize = readUnsignedNumber(); - StringRef Name = readString(NameSize); + StringRef Name = FunctionSamples::getCanonicalFnName(readString(NameSize)); // Initialize PseudoProbeFuncDesc and populate it into GUID2FuncDescMap GUID2FuncDescMap.emplace(GUID, PseudoProbeFuncDesc(GUID, Hash, Name));