[llvm] [MemProf] Handle missing tail call frames (PR #75823)

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 10 14:25:48 PST 2024


================
@@ -1652,11 +1899,117 @@ bool ModuleCallsiteContextGraph::calleeMatchesFunc(Instruction *Call,
   if (CalleeFunc == Func)
     return true;
   auto *Alias = dyn_cast<GlobalAlias>(CalleeVal);
-  return Alias && Alias->getAliasee() == Func;
+  if (Alias && Alias->getAliasee() == Func)
+    return true;
+
+  // Recursively search for the profiled callee through tail calls starting with
+  // the actual Callee. The discovered tail call chain is saved in
+  // FoundCalleeChain, and we will fixup the graph to include these callsites
+  // after returning.
+  // FIXME: We will currently redo the same recursive walk if we find the same
+  // mismatched callee from another callsite. We can improve this with more
+  // bookkeeping of the created chain of new nodes for each mismatch.
+  unsigned Depth = 1;
+  bool FoundMultipleCalleeChains = false;
+  if (!findProfiledCalleeThroughTailCalls(Func, CalleeVal, Depth,
+                                          FoundCalleeChain,
+                                          FoundMultipleCalleeChains)) {
+    LLVM_DEBUG(dbgs() << "Not found through unique tail call chain: "
+                      << Func->getName() << " from " << CallerFunc->getName()
+                      << " that actually called " << CalleeVal->getName()
+                      << (FoundMultipleCalleeChains
+                              ? " (found multiple possible chains)"
+                              : "")
+                      << "\n");
+    if (FoundMultipleCalleeChains)
+      FoundProfiledCalleeNonUniquelyCount++;
+    return false;
+  }
+
+  return true;
 }
 
-bool IndexCallsiteContextGraph::calleeMatchesFunc(IndexCall &Call,
-                                                  const FunctionSummary *Func) {
+bool IndexCallsiteContextGraph::findProfiledCalleeThroughTailCalls(
----------------
snehasish wrote:

[optional] I wonder if we can refactor the Index and Module version of this method by factoring out the FSToVI lookup as a functor as we have done in other places (if I recall correctly)?

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


More information about the llvm-commits mailing list