aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/InstrProfWriter.cpp
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2024-06-07 07:19:36 -0700
committerGitHub <noreply@github.com>2024-06-07 07:19:36 -0700
commitc348e265bd1284f770e66639633199fefd8015ec (patch)
tree2a7c1dd2226d3a372cfd79406df8d72327994e97 /llvm/lib/ProfileData/InstrProfWriter.cpp
parent55bdb36e39670d07aaaf04a24783a2008e8e60dd (diff)
downloadllvm-c348e265bd1284f770e66639633199fefd8015ec.zip
llvm-c348e265bd1284f770e66639633199fefd8015ec.tar.gz
llvm-c348e265bd1284f770e66639633199fefd8015ec.tar.bz2
[memprof] Use CallStackRadixTreeBuilder in the V3 format (#94708)
This patch integrates CallStackRadixTreeBuilder into the V3 format, reducing the profile size to about 27% of the V2 profile size. - Serialization: writeMemProfCallStackArray just needs to write out the radix tree array prepared by CallStackRadixTreeBuilder. Mappings from CallStackIds to LinearCallStackIds are moved by new function CallStackRadixTreeBuilder::takeCallStackPos. - Deserialization: Deserializing a call stack is the same as deserializing an array encoded in the obvious manner -- the length followed by the payload, except that we need to follow a pointer to the parent to take advantage of common prefixes once in a while. This patch teaches LinearCallStackIdConverter to how to handle those pointers.
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfWriter.cpp')
-rw-r--r--llvm/lib/ProfileData/InstrProfWriter.cpp22
1 files changed, 7 insertions, 15 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index e58e6b8..a73f72a 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -547,19 +547,11 @@ writeMemProfCallStackArray(
llvm::DenseMap<memprof::CallStackId, memprof::LinearCallStackId>
MemProfCallStackIndexes;
- MemProfCallStackIndexes.reserve(MemProfCallStackData.size());
- uint64_t CallStackBase = OS.tell();
- for (const auto &[CSId, CallStack] : MemProfCallStackData) {
- memprof::LinearCallStackId CallStackIndex =
- (OS.tell() - CallStackBase) / sizeof(memprof::LinearCallStackId);
- MemProfCallStackIndexes.insert({CSId, CallStackIndex});
- const llvm::SmallVector<memprof::FrameId> CS = CallStack;
- OS.write32(CS.size());
- for (const auto F : CS) {
- assert(MemProfFrameIndexes.contains(F));
- OS.write32(MemProfFrameIndexes[F]);
- }
- }
+ memprof::CallStackRadixTreeBuilder Builder;
+ Builder.build(std::move(MemProfCallStackData), MemProfFrameIndexes);
+ for (auto I : Builder.getRadixArray())
+ OS.write32(I);
+ MemProfCallStackIndexes = Builder.takeCallStackPos();
// Release the memory of this vector as it is no longer needed.
MemProfCallStackData.clear();
@@ -695,8 +687,8 @@ static Error writeMemProfV2(ProfOStream &OS,
// uint64_t Schema entry 1
// ....
// uint64_t Schema entry N - 1
-// OnDiskChainedHashTable MemProfFrameData
-// OnDiskChainedHashTable MemProfCallStackData
+// Frames serialized one after another
+// Call stacks encoded as a radix tree
// OnDiskChainedHashTable MemProfRecordData
static Error writeMemProfV3(ProfOStream &OS,
memprof::IndexedMemProfData &MemProfData,