[llvm] 3f3103c - [llvm-profgen] Fill zero count for all function ranges
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 1 10:05:32 PDT 2021
Author: wlei
Date: 2021-11-01T09:57:05-07:00
New Revision: 3f3103c6a98fc2af621d6d68ffc1126ae5689351
URL: https://github.com/llvm/llvm-project/commit/3f3103c6a98fc2af621d6d68ffc1126ae5689351
DIFF: https://github.com/llvm/llvm-project/commit/3f3103c6a98fc2af621d6d68ffc1126ae5689351.diff
LOG: [llvm-profgen] Fill zero count for all function ranges
Allow filling zero count for all the function ranges even there is no samples hitting that function. Add a switch for this.
Reviewed By: hoy, wenlei
Differential Revision: https://reviews.llvm.org/D112858
Added:
Modified:
llvm/test/tools/llvm-profgen/inline-noprobe.test
llvm/tools/llvm-profgen/ProfileGenerator.cpp
llvm/tools/llvm-profgen/ProfiledBinary.h
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-profgen/inline-noprobe.test b/llvm/test/tools/llvm-profgen/inline-noprobe.test
index 5203a5968ff94..6ae2726b5a6aa 100644
--- a/llvm/test/tools/llvm-profgen/inline-noprobe.test
+++ b/llvm/test/tools/llvm-profgen/inline-noprobe.test
@@ -6,6 +6,9 @@
; RUN: FileCheck %s --input-file %t1 --check-prefix=CHECK
; RUN: llvm-profgen --format=text --use-dwarf-correlation --perfscript=%S/Inputs/inline-noprobe.perfscript --binary=%S/Inputs/inline-noprobe.perfbin --output=%t
; RUN: FileCheck %s --input-file %t --check-prefix=CHECK
+; RUN: echo -e "0\n0" > %t
+; RUN: llvm-profgen --format=text --unsymbolized-profile=%t --binary=%S/Inputs/inline-noprobe.perfbin --output=%t1 --fill-zero-for-all-funcs
+; RUN: FileCheck %s --input-file %t1 --check-prefix=CHECK-ALL-ZERO
CHECK: main:188:0
CHECK: 0: 0
@@ -20,6 +23,33 @@ CHECK: 1: 42
CHECK: 3.2: bar:21
CHECK: 1: 21
+CHECK-ALL-ZERO: bar:0:0
+CHECK-ALL-ZERO: 1: 0
+CHECK-ALL-ZERO: 5: 0
+CHECK-ALL-ZERO: foo:0:0
+CHECK-ALL-ZERO: 0: 0
+CHECK-ALL-ZERO: 2.1: 0
+CHECK-ALL-ZERO: 3: 0
+CHECK-ALL-ZERO: 3.2: 0
+CHECK-ALL-ZERO: 4: 0
+CHECK-ALL-ZERO: 3.1: bar:0
+CHECK-ALL-ZERO: 1: 0
+CHECK-ALL-ZERO: 3.2: bar:0
+CHECK-ALL-ZERO: 1: 0
+CHECK-ALL-ZERO: 7: 0
+CHECK-ALL-ZERO: main:0:0
+CHECK-ALL-ZERO: 0: 0
+CHECK-ALL-ZERO: 2: 0
+CHECK-ALL-ZERO: 1: foo:0
+CHECK-ALL-ZERO: 2.1: 0
+CHECK-ALL-ZERO: 3: 0
+CHECK-ALL-ZERO: 3.2: 0
+CHECK-ALL-ZERO: 4: 0
+CHECK-ALL-ZERO: 3.1: bar:0
+CHECK-ALL-ZERO: 1: 0
+CHECK-ALL-ZERO: 3.2: bar:0
+CHECK-ALL-ZERO: 1: 0
+
CHECK-RAW-PROFILE: 3
CHECK-RAW-PROFILE-NEXT: 650-691:21
CHECK-RAW-PROFILE-NEXT: 669-677:20
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index 1e857a6d917de..4c7a4a644e2f4 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -36,6 +36,11 @@ static cl::opt<bool> PopulateProfileSymbolList(
"populate-profile-symbol-list", cl::init(false), cl::Hidden,
cl::desc("Populate profile symbol list (only meaningful for -extbinary)"));
+static cl::opt<bool> FillZeroForAllFuncs(
+ "fill-zero-for-all-funcs", cl::init(false), cl::Hidden,
+ cl::desc("Attribute all functions' range with zero count "
+ "even it's not hit by any samples."));
+
static cl::opt<int32_t, true> RecursionCompression(
"compress-recursion",
cl::desc("Compressing recursion by deduplicating adjacent frame "
@@ -347,14 +352,22 @@ FunctionSamples &ProfileGenerator::getLeafFrameProfile(
RangeSample
ProfileGenerator::preprocessRangeCounter(const RangeSample &RangeCounter) {
RangeSample Ranges(RangeCounter.begin(), RangeCounter.end());
- // For each range, we search for all ranges of the function it belongs to and
- // initialize it with zero count, so it remains zero if doesn't hit any
- // samples. This is to be consistent with compiler that interpret zero count
- // as unexecuted(cold).
- for (auto I : RangeCounter) {
- uint64_t StartOffset = I.first.first;
- for (const auto &Range : Binary->getRangesForOffset(StartOffset))
- Ranges[{Range.first, Range.second - 1}] += 0;
+ if (FillZeroForAllFuncs) {
+ for (auto &FuncI : Binary->getAllBinaryFunctions()) {
+ for (auto &R : FuncI.second.Ranges) {
+ Ranges[{R.first, R.second}] += 0;
+ }
+ }
+ } else {
+ // For each range, we search for all ranges of the function it belongs to
+ // and initialize it with zero count, so it remains zero if doesn't hit any
+ // samples. This is to be consistent with compiler that interpret zero count
+ // as unexecuted(cold).
+ for (auto I : RangeCounter) {
+ uint64_t StartOffset = I.first.first;
+ for (const auto &Range : Binary->getRangesForOffset(StartOffset))
+ Ranges[{Range.first, Range.second - 1}] += 0;
+ }
}
RangeSample DisjointRanges;
findDisjointRanges(DisjointRanges, Ranges);
@@ -643,7 +656,7 @@ void CSProfileGenerator::postProcessProfiles() {
CSProfMergeColdContext = false;
}
- // Trim and merge cold context profile using cold threshold above.
+ // Trim and merge cold context profile using cold threshold above.
if (CSProfTrimColdContext || CSProfMergeColdContext) {
SampleContextTrimmer(ProfileMap)
.trimAndMergeColdContextProfiles(
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h
index d6e7ba81fef19..b9049e37a2aa0 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.h
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.h
@@ -378,6 +378,11 @@ class ProfiledBinary {
return FRange->Func->Ranges;
}
+ const std::unordered_map<std::string, BinaryFunction> &
+ getAllBinaryFunctions() {
+ return BinaryFunctions;
+ }
+
uint32_t getFuncSizeForContext(SampleContext &Context) {
return FuncSizeTracker.getFuncSizeForContext(Context);
}
More information about the llvm-commits
mailing list