Skip to content

Commit ae8b560

Browse files
[MemProf] Disable hot hints by default (#124338)
By default we were marking some contexts as hot, and adding hot hints to unambiguously hot allocations. However, there is not yet support for cloning to expose hot allocation contexts, and none is planned for the forseeable future. While we convert hot contexts to notcold contexts during the cloning step, their existence was greatly limiting the context trimming performed when we add the MemProf profile to the IR. This change simply disables the generation of hot contexts / hints by default, as few allocations were unambiguously hot. A subsequent change will address the issue when hot hints are optionally enabled. See PR124219 for details. This change resulted in significant overhead reductions for a large target: ~48% reduction in the per-module ThinLTO bitcode summary sizes ~72% reduction in the distributed ThinLTO bitcode combined summary sizes ~68% reduction in thin link time ~34% reduction in thin link peak memory
1 parent 074a25f commit ae8b560

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

llvm/lib/Analysis/MemoryProfileInfo.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ cl::opt<unsigned> MemProfMinAveLifetimeAccessDensityHotThreshold(
4242
cl::desc("The minimum TotalLifetimeAccessDensity / AllocCount for an "
4343
"allocation to be considered hot"));
4444

45+
cl::opt<bool>
46+
MemProfUseHotHints("memprof-use-hot-hints", cl::init(false), cl::Hidden,
47+
cl::desc("Enable use of hot hints (only supported for "
48+
"unambigously hot allocations)"));
49+
4550
cl::opt<bool> MemProfReportHintedSizes(
4651
"memprof-report-hinted-sizes", cl::init(false), cl::Hidden,
4752
cl::desc("Report total allocation sizes of hinted allocations"));
@@ -60,8 +65,9 @@ AllocationType llvm::memprof::getAllocType(uint64_t TotalLifetimeAccessDensity,
6065

6166
// The access densities are multiplied by 100 to hold 2 decimal places of
6267
// precision, so need to divide by 100.
63-
if (((float)TotalLifetimeAccessDensity) / AllocCount / 100 >
64-
MemProfMinAveLifetimeAccessDensityHotThreshold)
68+
if (MemProfUseHotHints &&
69+
((float)TotalLifetimeAccessDensity) / AllocCount / 100 >
70+
MemProfMinAveLifetimeAccessDensityHotThreshold)
6571
return AllocationType::Hot;
6672

6773
return AllocationType::NotCold;

llvm/test/Transforms/PGOProfile/memprof.ll

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
; RUN: llvm-profdata merge -memprof-random-hotness -memprof-random-hotness-seed=1730170724 %S/Inputs/memprof.memprofraw --profiled-binary %S/Inputs/memprof.exe -o %t.memprofdatarand2 2>&1 | FileCheck %s --check-prefix=RAND2
8585
; RAND2: random hotness seed = 1730170724
8686
; RUN: opt < %s -passes='memprof-use<profile-filename=%t.memprofdatarand2>' -pgo-warn-missing-function -S -stats 2>&1 | FileCheck %s --check-prefixes=MEMPROFRAND2,ALL,MEMPROFONLY,MEMPROFSTATS
87+
;; Check with hot hints enabled
88+
; RUN: opt < %s -memprof-use-hot-hints -passes='memprof-use<profile-filename=%t.memprofdatarand2>' -pgo-warn-missing-function -S -stats 2>&1 | FileCheck %s --check-prefixes=MEMPROFRAND2HOT
8789

8890
; MEMPROFMATCHINFO: MemProf notcold context with id 1093248920606587996 has total profiled size 10 is matched
8991
; MEMPROFMATCHINFO: MemProf notcold context with id 5725971306423925017 has total profiled size 10 is matched
@@ -408,8 +410,15 @@ for.end: ; preds = %for.cond
408410
; MEMPROFRAND2: !"cold"
409411
; MEMPROFRAND2: !"cold"
410412
; MEMPROFRAND2: !"cold"
411-
; MEMPROFRAND2: !"hot"
412-
; MEMPROFRAND2: !"hot"
413+
; MEMPROFRAND2: !"notcold"
414+
; MEMPROFRAND2: !"notcold"
415+
416+
;; With hot hints enabled the last 2 should be hot.
417+
; MEMPROFRAND2HOT: !"cold"
418+
; MEMPROFRAND2HOT: !"cold"
419+
; MEMPROFRAND2HOT: !"cold"
420+
; MEMPROFRAND2HOT: !"hot"
421+
; MEMPROFRAND2HOT: !"hot"
413422

414423
; MEMPROFSTATS: 8 memprof - Number of alloc contexts in memory profile.
415424
; MEMPROFSTATS: 10 memprof - Number of callsites in memory profile.

llvm/test/Transforms/PGOProfile/memprof_loop_unroll.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
;; $ clang++ -gmlt -fdebug-info-for-profiling -S %S/Inputs/memprof_loop_unroll_b.cc -emit-llvm
1111

1212
; RUN: llvm-profdata merge %S/Inputs/memprof_loop_unroll.memprofraw --profiled-binary %S/Inputs/memprof_loop_unroll.exe -o %t.memprofdata
13-
; RUN: opt < %s -passes='memprof-use<profile-filename=%t.memprofdata>' -S -memprof-report-hinted-sizes 2>&1 | FileCheck %s
13+
;; Set the minimum lifetime threshold to 0 to ensure that one context is
14+
;; considered cold (the other will be notcold).
15+
; RUN: opt < %s -passes='memprof-use<profile-filename=%t.memprofdata>' -S -memprof-report-hinted-sizes -memprof-ave-lifetime-cold-threshold=0 2>&1 | FileCheck %s
1416

1517
;; Conservatively annotate as not cold. We get two messages as there are two
1618
;; unrolled copies of the allocation.

llvm/unittests/Analysis/MemoryProfileInfoTest.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using namespace llvm::memprof;
2525
extern cl::opt<float> MemProfLifetimeAccessDensityColdThreshold;
2626
extern cl::opt<unsigned> MemProfAveLifetimeColdThreshold;
2727
extern cl::opt<unsigned> MemProfMinAveLifetimeAccessDensityHotThreshold;
28+
extern cl::opt<bool> MemProfUseHotHints;
2829

2930
namespace {
3031

@@ -81,14 +82,23 @@ TEST_F(MemoryProfileInfoTest, GetAllocType) {
8182
// MemProfMinAveLifetimeAccessDensityHotThreshold
8283
// so compute the HotTotalLifetimeAccessDensityThreshold at the threshold.
8384
const uint64_t HotTotalLifetimeAccessDensityThreshold =
84-
(uint64_t)(MemProfMinAveLifetimeAccessDensityHotThreshold * AllocCount * 100);
85-
86-
85+
(uint64_t)(MemProfMinAveLifetimeAccessDensityHotThreshold * AllocCount *
86+
100);
87+
88+
// Make sure the option for detecting hot allocations is set.
89+
MemProfUseHotHints = true;
8790
// Test Hot
8891
// More accesses per byte per sec than hot threshold is hot.
8992
EXPECT_EQ(getAllocType(HotTotalLifetimeAccessDensityThreshold + 1, AllocCount,
9093
ColdTotalLifetimeThreshold + 1),
91-
AllocationType::Hot);
94+
AllocationType::Hot);
95+
// Undo the manual set of the option above.
96+
cl::ResetAllOptionOccurrences();
97+
98+
// Without MemProfUseHotHints (default) we should treat simply as NotCold.
99+
EXPECT_EQ(getAllocType(HotTotalLifetimeAccessDensityThreshold + 1, AllocCount,
100+
ColdTotalLifetimeThreshold + 1),
101+
AllocationType::NotCold);
92102

93103
// Test Cold
94104
// Long lived with less accesses per byte per sec than cold threshold is cold.

0 commit comments

Comments
 (0)