[llvm] Reapply "[MemProf] Reduce cloning overhead by sharing nodes when possible" (#102932) with fixes (PR #106623)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 30 10:44:16 PDT 2024
================
@@ -1892,35 +1899,86 @@ void CallsiteContextGraph<DerivedCCG, FuncTy,
// from the profiled contexts.
MapVector<CallInfo, ContextNode *> TailCallToContextNodeMap;
+ std::vector<std::pair<CallInfo, ContextNode *>> NewCallToNode;
for (auto &Entry : NonAllocationCallToContextNodeMap) {
auto *Node = Entry.second;
assert(Node->Clones.empty());
// Check all node callees and see if in the same function.
- auto Call = Node->Call.call();
- for (auto EI = Node->CalleeEdges.begin(); EI != Node->CalleeEdges.end();
- ++EI) {
- auto Edge = *EI;
- if (!Edge->Callee->hasCall())
- continue;
- assert(NodeToCallingFunc.count(Edge->Callee));
- // Check if the called function matches that of the callee node.
- if (calleesMatch(Call, EI, TailCallToContextNodeMap))
- continue;
+ // We need to check all of the calls recorded in this Node, because in some
+ // cases we may have had multiple calls with the same debug info calling
+ // different callees. Here we will prune any that don't match all callee
+ // nodes.
+ std::vector<CallInfo> AllCalls = Node->MatchingCalls;
+ AllCalls.insert(AllCalls.begin(), Node->Call);
----------------
snehasish wrote:
I think this will trigger an alloc and a copy just to add one element. Maybe rewrite to reserve, insert `Node->Call` and then insert the rest?
https://github.com/llvm/llvm-project/pull/106623
More information about the llvm-commits
mailing list