[llvm] 16516f8 - [llvm-profgen] Support symbol list for accurate profile
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 6 11:42:06 PDT 2021
Author: wlei
Date: 2021-10-06T11:41:39-07:00
New Revision: 16516f89252ed14ee7e83a0c6d0626875cc4a7fc
URL: https://github.com/llvm/llvm-project/commit/16516f89252ed14ee7e83a0c6d0626875cc4a7fc
DIFF: https://github.com/llvm/llvm-project/commit/16516f89252ed14ee7e83a0c6d0626875cc4a7fc.diff
LOG: [llvm-profgen] Support symbol list for accurate profile
Differential Revision: https://reviews.llvm.org/D110859
Added:
Modified:
llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
llvm/test/tools/llvm-profgen/inline-noprobe2.test
llvm/tools/llvm-profgen/ProfileGenerator.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
index 2b8841ba3897..991602bd2f85 100644
--- a/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
+++ b/llvm/test/tools/llvm-profgen/inline-cs-noprobe.test
@@ -5,6 +5,13 @@
; 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
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK-STRIP-CTX
+; 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
+; RUN: llvm-profdata show -show-prof-sym-list -sample %t | FileCheck %s --check-prefix=CHECK-SYM-LIST
+
+; CHECK-SYM-LIST: Dump profile symbol list
+; CHECK-SYM-LIST: bar
+; CHECK-SYM-LIST: foo
+
; CHECK:[main:1 @ foo]:225:0
; CHECK: 2.1: 14
; CHECK: 3: 15
diff --git a/llvm/test/tools/llvm-profgen/inline-noprobe2.test b/llvm/test/tools/llvm-profgen/inline-noprobe2.test
index f4506fa3272a..d27eaaccdcbc 100644
--- a/llvm/test/tools/llvm-profgen/inline-noprobe2.test
+++ b/llvm/test/tools/llvm-profgen/inline-noprobe2.test
@@ -2,6 +2,15 @@
; RUN: llvm-profgen --format=text --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK
+; RUN: llvm-profgen --format=extbinary --perfscript=%S/Inputs/inline-noprobe2.perfscript --binary=%S/Inputs/inline-noprobe2.perfbin --output=%t
+; RUN: llvm-profdata show -show-prof-sym-list -sample %t | FileCheck %s --check-prefix=CHECK-SYM-LIST
+
+; CHECK-SYM-LIST: Dump profile symbol list
+; CHECK-SYM-LIST: main
+; CHECK-SYM-LIST: partition_pivot_first
+; CHECK-SYM-LIST: partition_pivot_last
+; CHECK-SYM-LIST: quick_sort
+
;CHECK: partition_pivot_first:1045:5
;CHECK-NEXT: 0: 5
;CHECK-NEXT: 1: 5
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index 51ae0115d88e..b5fff0bbf66b 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -32,6 +32,10 @@ cl::opt<bool> UseMD5(
cl::desc("Use md5 to represent function names in the output profile (only "
"meaningful for -extbinary)"));
+static cl::opt<bool> PopulateProfileSymbolList(
+ "populate-profile-symbol-list", cl::init(true), cl::Hidden,
+ cl::desc("Populate profile symbol list (only meaningful for -extbinary)"));
+
static cl::opt<int32_t, true> RecursionCompression(
"compress-recursion",
cl::desc("Compressing recursion by deduplicating adjacent frame "
@@ -90,6 +94,22 @@ ProfileGeneratorBase::create(ProfiledBinary *Binary,
void ProfileGeneratorBase::write(std::unique_ptr<SampleProfileWriter> Writer,
SampleProfileMap &ProfileMap) {
+ // Populate profile symbol list if extended binary format is used.
+ ProfileSymbolList SymbolList;
+
+ // Turn it off temporarily for CS profile.
+ if (FunctionSamples::ProfileIsCS &&
+ !PopulateProfileSymbolList.getNumOccurrences())
+ PopulateProfileSymbolList = false;
+
+ if (PopulateProfileSymbolList && OutputFormat == SPF_Ext_Binary) {
+ for (const auto &Item : ProfileMap) {
+ auto &Profile = Item.second;
+ SymbolList.add(Profile.getName(), true);
+ }
+ Writer->setProfileSymbolList(&SymbolList);
+ }
+
if (std::error_code EC = Writer->write(ProfileMap))
exitWithError(std::move(EC));
}
More information about the llvm-commits
mailing list