[llvm-branch-commits] [llvm] [llvm-profgen] Infer callsite samples from callee head samples (PR #235988)
Kunal Pathak via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 18 14:09:06 PST 2026
================
@@ -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
More information about the llvm-branch-commits
mailing list