================
@@ -1377,6 +1386,96 @@ void 
CSProfileGenerator::populateBoundarySamplesWithProbes(
   }
 }
 
+void CSProfileGenerator::inferCallsiteSamples() {
+  // Walk the context trie bottom-up (children before parents) and for each
+  // node, ensure that callsite body samples are at least as large as callee
+  // entry (head) samples. This serves two purposes:
+  // 1. Create FunctionSamples for nodes without samples and infer called
+  //    target samples using children's head samples.
+  // 2. Fix under-counted callsites for nodes that have callsite counts
+  //    lower than callee entry counts.
+  SmallVector<ContextTrieNode *, 256> AllNodes;
+  for (auto *Node : ContextTracker)
+    AllNodes.push_back(Node);
+
+  for (auto It = AllNodes.rbegin(), End = AllNodes.rend(); It != End; ++It) {
+    ContextTrieNode *Node = *It;
+
+    if (Node == &getRootContext())
+      continue;
+
+    bool HasChildWithSamples = false;
+    for (auto &Child : Node->getAllChildContext()) {
+      if (Child.second.getFunctionSamples()) {
+        HasChildWithSamples = true;
+        break;
+      }
+    }
+    if (!HasChildWithSamples)
+      continue;
+
+    FunctionSamples *FSamples = Node->getFunctionSamples();
+    if (!FSamples) {
+      FSamples = getOrCreateFunctionSamples(Node);
+      const auto *FuncDesc =
+          Binary->getFuncDescForGUID(Node->getFuncName().getHashCode());
----------------
kunalspathak wrote:

nit:  other places that do this look up the descriptor by a probe's GUID. But 
here, we are looking it up using the hash of trie node's name. It should always 
be found in the probe path, but an assert (or a null check) would make that 
explicit.

https://github.com/llvm/llvm-project/pull/235988
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to