[llvm] [MemProf] Remove empty edges once after cloning (PR #85320)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 26 11:09:19 PDT 2024
================
@@ -2427,11 +2430,42 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
}
}
+template <typename DerivedCCG, typename FuncTy, typename CallTy>
+void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
+ recursivelyRemoveNoneTypeCalleeEdges(
+ ContextNode *Node, DenseSet<const ContextNode *> &Visited) {
+ auto Inserted = Visited.insert(Node);
+ if (!Inserted.second)
+ return;
+
+ removeNoneTypeCalleeEdges(Node);
+
+ for (auto *Clone : Node->Clones)
+ recursivelyRemoveNoneTypeCalleeEdges(Clone, Visited);
+
+ // The recursive call may remove some of this Node's caller edges.
+ // Iterate over a copy and skip any that were removed.
+ auto CallerEdges = Node->CallerEdges;
+ for (auto &Edge : CallerEdges) {
+ // Skip any that have been removed by an earlier recursive call.
+ if (Edge->Callee == nullptr && Edge->Caller == nullptr) {
+ assert(!std::count(Node->CallerEdges.begin(), Node->CallerEdges.end(),
+ Edge));
+ continue;
+ }
+ recursivelyRemoveNoneTypeCalleeEdges(Edge->Caller, Visited);
+ }
+}
+
template <typename DerivedCCG, typename FuncTy, typename CallTy>
void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::identifyClones() {
DenseSet<const ContextNode *> Visited;
for (auto &Entry : AllocationCallToContextNodeMap)
identifyClones(Entry.second, Visited);
+ Visited.clear();
+ for (auto &Entry : AllocationCallToContextNodeMap)
+ recursivelyRemoveNoneTypeCalleeEdges(Entry.second, Visited);
+ check();
----------------
teresajohnson wrote:
Good catch, this was unconditional from when I was debugging. It should be guarded by the VerifyCCG option like other invocations of this function. Fixed.
https://github.com/llvm/llvm-project/pull/85320
More information about the llvm-commits
mailing list