[llvm] [memprof] Use uint32_t for linear call stack IDs (PR #93924)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 10:28:07 PDT 2024


================
@@ -89,15 +100,30 @@ static size_t serializedSizeV2(const IndexedMemProfRecord &Record,
   return Result;
 }
 
+static size_t serializedSizeV3(const IndexedMemProfRecord &Record,
+                               const MemProfSchema &Schema) {
+  // The number of alloc sites to serialize.
+  size_t Result = sizeof(uint64_t);
+  for (const IndexedAllocationInfo &N : Record.AllocSites)
+    Result += N.serializedSize(Schema, Version3);
+
+  // The number of callsites we have information for.
+  Result += sizeof(uint64_t);
+  // The linear call stack ID.
+  Result += Record.CallSiteIds.size() * sizeof(uint32_t);
----------------
kazutakahirata wrote:

I've added a new typename in the latest iteration.

I thought about the TODO that you are suggest suggesting, but it's a bit complicated.  I think the source of confusion is that I am multi-purposing `IndexedAllocationInfo::CSId` and `IndexedMemProfRecord::CallSiteIds`:

- During serialization (like `llvm-profdata merge`), we store 64-bit call stack hash values there -- the original meaning of `CallStackId`.
- During deserialization (in the compiler proper), we temporarily store 32-bit linear IDs in `CSId` and `CallSiteIds` just before constructing `MemProfRecord`.

For now, I'm inclined to keeping the way it is, except we use `LinearCallStackId` for readability where we don't need to store 64-bit call stack hash values.

I thought about putting true `CallStackId` (that is, 64-bit call stack hash values) in these fields during deserialization, replacing a linear ID with `CallStackID` as we deserialize -- the opposite of what we do during serialization.  The problem is that computation of the 64-bit call stack hash value requires a fully reconstructed call stack consisting of `Frame`s.  Now, we have a fully reconstructed call stack of `Frame`s, why not go all the way to `MemProfRecord`?  It seems wasteful to reconstruct a call stack, store it away in some hash table, and immediately retrieve it when we construct `MemProfRecord`.

https://github.com/llvm/llvm-project/pull/93924


More information about the llvm-commits mailing list