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

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 22 12:33:39 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) {
----------------
teresajohnson wrote:

I tried this, but the compiler gave an error because StackIdIndicesToIndex is a class member. I could only get it to work by capturing "this", which I don't think improves clarity at all. Ditto for the outer lambda, "this" needs to be captured there too for StackIdIndicesToIndex. So in the end I left both of these alone.

However, I did remove the capture from the GetStackIndex lambda passed to the other collectMemProfCallStacks invocation as none is needed.

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


More information about the llvm-commits mailing list