[llvm] [MemProf] Use radix tree for alloc contexts in bitcode summaries (PR #117066)

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 22 11:45:27 PST 2024


================
@@ -4735,6 +4835,40 @@ 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) {
----------------
snehasish wrote:

Just capture StackIdIndicesToIndex since that's all we use?
Same for the outer lamdba with the additional capture of Callstacks?

I think it makes it clearer to the reader.

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


More information about the llvm-commits mailing list