[llvm] [MemProf] Use radix tree for alloc contexts in bitcode summaries (PR #117066)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 20 23:28:04 PST 2024
================
@@ -4735,6 +4834,39 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
NameVals.clear();
};
+ // First walk through all the functions and collect the allocation contexts in
+ // their associated summaries, for use in constructing a radix tree of
+ // contexts. Note that we need to do this in the same order as the functions
+ // are processed further below since the call stack positions in the resulting
+ // radix tree array are identified based on this order.
+ MapVector<CallStackId, llvm::SmallVector<LinearFrameId>> CallStacks;
+ forEachSummary([&](GVInfo I, bool IsAliasee) {
+ GlobalValueSummary *S = I.second;
+ assert(S);
+ auto *FS = dyn_cast<FunctionSummary>(S);
+ if (!FS)
+ return;
+ collectMemProfCallStacks(
+ FS,
+ /*GetStackIndex*/
+ [&](unsigned I) {
+ // Get the corresponding index into the list of StackIds actually
+ // being written for this combined index (which may be a subset in
+ // the case of distributed indexes).
+ assert(StackIdIndicesToIndex.contains(I));
+ return StackIdIndicesToIndex[I];
+ },
+ CallStacks);
+ });
+ // Finalize the radix tree, write it out, and get the map of positions in the
+ // linearized tree array.
+ DenseMap<CallStackId, LinearCallStackId> CallStackPos;
+ if (!CallStacks.empty())
+ CallStackPos = writeMemoryProfileRadixTree(CallStacks, Stream, RadixAbbrev);
----------------
kazutakahirata wrote:
May I suggest `std::move` here?
```suggestion
CallStackPos = writeMemoryProfileRadixTree(std::move(CallStacks), Stream, RadixAbbrev);
```
https://github.com/llvm/llvm-project/pull/117066
More information about the llvm-commits
mailing list