Skip to content

Commit 16516f8

Browse files
committed
[llvm-profgen] Support symbol list for accurate profile
Differential Revision: https://reviews.llvm.org/D110859
1 parent 569346f commit 16516f8

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

llvm/test/tools/llvm-profgen/inline-cs-noprobe.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/inline-cs-noprobe.perfscript --binary=%S/Inputs/inline-cs-noprobe.perfbin --output=%t --profile-summary-cold-count=0 --ignore-stack-samples
66
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-STRIP-CTX
77

8+
; RUN: llvm-profgen --format=extbinary --perfscript=%S/Inputs/inline-cs-noprobe.perfscript --binary=%S/Inputs/inline-cs-noprobe.perfbin --output=%t --profile-summary-cold-count=0 --populate-profile-symbol-list=1
9+
; RUN: llvm-profdata show -show-prof-sym-list -sample %t | FileCheck %s --check-prefix=CHECK-SYM-LIST
10+
11+
; CHECK-SYM-LIST: Dump profile symbol list
12+
; CHECK-SYM-LIST: bar
13+
; CHECK-SYM-LIST: foo
14+
815
; CHECK:[main:1 @ foo]:225:0
916
; CHECK: 2.1: 14
1017
; CHECK: 3: 15

llvm/test/tools/llvm-profgen/inline-noprobe2.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t
33
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK
44

5+
; RUN: llvm-profgen --format=extbinary --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t
6+
; RUN: llvm-profdata show -show-prof-sym-list -sample %t | FileCheck %s --check-prefix=CHECK-SYM-LIST
7+
8+
; CHECK-SYM-LIST: Dump profile symbol list
9+
; CHECK-SYM-LIST: main
10+
; CHECK-SYM-LIST: partition_pivot_first
11+
; CHECK-SYM-LIST: partition_pivot_last
12+
; CHECK-SYM-LIST: quick_sort
13+
514
;CHECK: partition_pivot_first:1045:5
615
;CHECK-NEXT: 0: 5
716
;CHECK-NEXT: 1: 5

llvm/tools/llvm-profgen/ProfileGenerator.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ cl::opt<bool> UseMD5(
3232
cl::desc("Use md5 to represent function names in the output profile (only "
3333
"meaningful for -extbinary)"));
3434

35+
static cl::opt<bool> PopulateProfileSymbolList(
36+
"populate-profile-symbol-list", cl::init(true), cl::Hidden,
37+
cl::desc("Populate profile symbol list (only meaningful for -extbinary)"));
38+
3539
static cl::opt<int32_t, true> RecursionCompression(
3640
"compress-recursion",
3741
cl::desc("Compressing recursion by deduplicating adjacent frame "
@@ -90,6 +94,22 @@ ProfileGeneratorBase::create(ProfiledBinary *Binary,
9094

9195
void ProfileGeneratorBase::write(std::unique_ptr<SampleProfileWriter> Writer,
9296
SampleProfileMap &ProfileMap) {
97+
// Populate profile symbol list if extended binary format is used.
98+
ProfileSymbolList SymbolList;
99+
100+
// Turn it off temporarily for CS profile.
101+
if (FunctionSamples::ProfileIsCS &&
102+
!PopulateProfileSymbolList.getNumOccurrences())
103+
PopulateProfileSymbolList = false;
104+
105+
if (PopulateProfileSymbolList && OutputFormat == SPF_Ext_Binary) {
106+
for (const auto &Item : ProfileMap) {
107+
auto &Profile = Item.second;
108+
SymbolList.add(Profile.getName(), true);
109+
}
110+
Writer->setProfileSymbolList(&SymbolList);
111+
}
112+
93113
if (std::error_code EC = Writer->write(ProfileMap))
94114
exitWithError(std::move(EC));
95115
}

0 commit comments

Comments
 (0)