Skip to content

Commit eba5749

Browse files
committed
[CSSPGO][llvm-profgen] Reimplement CS profile generator using context trie
Our investigation showed ProfileMap's key is the bottleneck of the memory consumption for CS profile generation on some large services. This patch tries to optimize it by storing the CS function samples using the context trie tree structure instead of the context frame array ref. Parts of code in `ContextTrieNode` are reused. Our experiment on one internal service showed that the context key's memory can be reduced from 80GB to 300MB. To be compatible with non-CS profiles, the profile writer still needs to use ProfileMap as input, so rebuild the ProfileMap using the context trie in `postProcessProfiles`. The optimization is not complete yet, next step is to reimplement Pre-inliner or profile trimmer, after that, ProfileMap should be small to be written. Reviewed By: hoy, wenlei Differential Revision: https://reviews.llvm.org/D125246
1 parent 834a38b commit eba5749

File tree

3 files changed

+196
-125
lines changed

3 files changed

+196
-125
lines changed

llvm/include/llvm/Transforms/IPO/SampleContextTracker.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class SampleContextTracker {
105105
// deterministically.
106106
using ContextSamplesTy = std::set<FunctionSamples *, ProfileComparer>;
107107

108+
SampleContextTracker() = default;
108109
SampleContextTracker(SampleProfileMap &Profiles,
109110
const DenseMap<uint64_t, StringRef> *GUIDToFuncNameMap);
110111
// Query context profile for a specific callee with given name at a given
@@ -122,6 +123,8 @@ class SampleContextTracker {
122123
// Get all context profile for given function.
123124
ContextSamplesTy &getAllContextSamplesFor(const Function &Func);
124125
ContextSamplesTy &getAllContextSamplesFor(StringRef Name);
126+
ContextTrieNode *getOrCreateContextPath(const SampleContext &Context,
127+
bool AllowCreate);
125128
// Query base profile for a given function. A base profile is a merged view
126129
// of all context profiles for contexts that are not inlined.
127130
FunctionSamples *getBaseSamplesFor(const Function &Func,
@@ -146,8 +149,6 @@ class SampleContextTracker {
146149
ContextTrieNode *getContextFor(const DILocation *DIL);
147150
ContextTrieNode *getCalleeContextFor(const DILocation *DIL,
148151
StringRef CalleeName);
149-
ContextTrieNode *getOrCreateContextPath(const SampleContext &Context,
150-
bool AllowCreate);
151152
ContextTrieNode *getTopLevelContextNode(StringRef FName);
152153
ContextTrieNode &addTopLevelContextNode(StringRef FName);
153154
ContextTrieNode &promoteMergeContextSamplesTree(ContextTrieNode &NodeToPromo);

0 commit comments

Comments
 (0)