[llvm] [MemProf] Make sure call clones without callsite node clones get updated (PR #159861)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 20 18:28:22 PDT 2025
================
@@ -4986,6 +5014,63 @@ bool CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::assignFunctions() {
}
}
}
+
+ if (FuncCloneInfos.size() < 2)
+ continue;
+
+ // In this case there is more than just the original function copy.
+ // Record call clones of any callsite nodes in the function that did not
+ // themselves get cloned for all of the function clones.
+ for (auto &Call : CallsWithMetadata) {
+ ContextNode *Node = getNodeForInst(Call);
+ if (!Node || !Node->hasCall() || Node->emptyContextIds())
+ continue;
+ // If Node has enough clones already to cover all function clones, we can
+ // skip it. Need to add one for the original copy.
+ // Use >= in case there were clones that were skipped due to having empty
+ // context ids
+ if (Node->Clones.size() + 1 >= FuncCloneInfos.size())
+ continue;
+ // First collect all function clones we cloned this callsite node for.
+ // They may not be sequential due to empty clones e.g.
+ DenseSet<unsigned> NodeCallClones;
+ for (auto *C : Node->Clones)
+ NodeCallClones.insert(C->Call.cloneNo());
+ unsigned I = 0;
+ // Now check all the function clones.
+ for (auto &FC : FuncCloneInfos) {
+ // Function clones should be sequential.
+ assert(FC.FuncClone.cloneNo() == I);
+ // Skip the first clone which got the original call.
+ // Also skip any other clones created for this Node.
+ if (++I == 1 || NodeCallClones.contains(I)) {
+ continue;
+ }
+ // Record the call clones created for this callsite in this function
+ // clone.
+ auto &CallVector = UnassignedCallClones[Node][I];
+ DenseMap<CallInfo, CallInfo> &CallMap = FC.CallMap;
+ CallInfo CallClone(Call);
+ if (auto It = CallMap.find(Call); It != CallMap.end())
+ CallClone = It->second;
+ else
+ // All but the original clone (skipped earlier) should have an entry
+ // for all calls.
+ assert(false && "Expected to find call in CallMap");
+ CallVector.push_back(CallClone);
+ // Need to do the same for all matching calls.
+ for (auto &MatchingCall : Node->MatchingCalls) {
+ CallInfo CallClone(MatchingCall);
----------------
snehasish wrote:
This `CallClone` var shadows the one outside this scope. Can we rewrite this condition too to drop the construction and then assignment?
https://github.com/llvm/llvm-project/pull/159861
More information about the llvm-commits
mailing list