[PATCH] D98226: [CSSPGO][llvm-profgen] Fix getCanonicalFnName usage in llvm-profgen
Lei Wang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 13 19:10:13 PST 2021
wlei updated this revision to Diff 330488.
wlei added a comment.
Add test cases
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98226/new/
https://reviews.llvm.org/D98226
Files:
llvm/test/tools/llvm-profgen/Inputs/unique-linkage-name-dwarf.perfbin
llvm/test/tools/llvm-profgen/Inputs/unique-linkage-name-dwarf.perfscript
llvm/test/tools/llvm-profgen/Inputs/unique-linkage-name-probe.perfbin
llvm/test/tools/llvm-profgen/Inputs/unique-linkage-name-probe.perfscript
llvm/test/tools/llvm-profgen/fname-canonicalization.test
llvm/tools/llvm-profgen/PseudoProbe.cpp
Index: llvm/tools/llvm-profgen/PseudoProbe.cpp
===================================================================
--- llvm/tools/llvm-profgen/PseudoProbe.cpp
+++ llvm/tools/llvm-profgen/PseudoProbe.cpp
@@ -162,7 +162,7 @@
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));
Index: llvm/test/tools/llvm-profgen/fname-canonicalization.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-profgen/fname-canonicalization.test
@@ -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;
+}
Index: llvm/test/tools/llvm-profgen/Inputs/unique-linkage-name-probe.perfscript
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-profgen/Inputs/unique-linkage-name-probe.perfscript
@@ -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
Index: llvm/test/tools/llvm-profgen/Inputs/unique-linkage-name-dwarf.perfscript
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-profgen/Inputs/unique-linkage-name-dwarf.perfscript
@@ -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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98226.330488.patch
Type: text/x-patch
Size: 4730 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210314/46f3b3f8/attachment.bin>
More information about the llvm-commits
mailing list