@@ -530,6 +530,9 @@ class CallsiteContextGraph {
530
530
// / multiple different callee target functions.
531
531
void handleCallsitesWithMultipleTargets ();
532
532
533
+ // / Mark backedges via the standard DFS based backedge algorithm.
534
+ void markBackedges ();
535
+
533
536
// Try to partition calls on the given node (already placed into the AllCalls
534
537
// array) by callee function, creating new copies of Node as needed to hold
535
538
// calls with different callees, and moving the callee edges appropriately.
@@ -740,6 +743,7 @@ class CallsiteContextGraph {
740
743
void moveCalleeEdgeToNewCaller (const std::shared_ptr<ContextEdge> &Edge,
741
744
ContextNode *NewCaller);
742
745
746
+ // / Recursive helper for marking backedges via DFS.
743
747
void markBackedges (ContextNode *Node, DenseSet<const ContextNode *> &Visited,
744
748
DenseSet<const ContextNode *> &CurrentStack);
745
749
@@ -2108,6 +2112,8 @@ ModuleCallsiteContextGraph::ModuleCallsiteContextGraph(
2108
2112
2109
2113
handleCallsitesWithMultipleTargets ();
2110
2114
2115
+ markBackedges ();
2116
+
2111
2117
// Strip off remaining callsite metadata, no longer needed.
2112
2118
for (auto &FuncEntry : FuncToCallsWithMetadata)
2113
2119
for (auto &Call : FuncEntry.second )
@@ -2204,6 +2210,8 @@ IndexCallsiteContextGraph::IndexCallsiteContextGraph(
2204
2210
updateStackNodes ();
2205
2211
2206
2212
handleCallsitesWithMultipleTargets ();
2213
+
2214
+ markBackedges ();
2207
2215
}
2208
2216
2209
2217
template <typename DerivedCCG, typename FuncTy, typename CallTy>
@@ -3405,6 +3413,27 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
3405
3413
3406
3414
// This is the standard DFS based backedge discovery algorithm.
3407
3415
template <typename DerivedCCG, typename FuncTy, typename CallTy>
3416
+ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::markBackedges() {
3417
+ // If we are cloning recursive contexts, find and mark backedges from all root
3418
+ // callers, using the typical DFS based backedge analysis.
3419
+ if (!CloneRecursiveContexts)
3420
+ return ;
3421
+ DenseSet<const ContextNode *> Visited;
3422
+ DenseSet<const ContextNode *> CurrentStack;
3423
+ for (auto &Entry : NonAllocationCallToContextNodeMap) {
3424
+ auto *Node = Entry.second ;
3425
+ if (Node->isRemoved ())
3426
+ continue ;
3427
+ // It is a root if it doesn't have callers.
3428
+ if (!Node->CallerEdges .empty ())
3429
+ continue ;
3430
+ markBackedges (Node, Visited, CurrentStack);
3431
+ assert (CurrentStack.empty ());
3432
+ }
3433
+ }
3434
+
3435
+ // Recursive helper for above markBackedges method.
3436
+ template <typename DerivedCCG, typename FuncTy, typename CallTy>
3408
3437
void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::markBackedges(
3409
3438
ContextNode *Node, DenseSet<const ContextNode *> &Visited,
3410
3439
DenseSet<const ContextNode *> &CurrentStack) {
@@ -3429,22 +3458,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::markBackedges(
3429
3458
3430
3459
template <typename DerivedCCG, typename FuncTy, typename CallTy>
3431
3460
void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::identifyClones() {
3432
- // If we are cloning recursive contexts, find and mark backedges from all root
3433
- // callers, using the typical DFS based backedge analysis.
3434
3461
DenseSet<const ContextNode *> Visited;
3435
- if (CloneRecursiveContexts) {
3436
- DenseSet<const ContextNode *> CurrentStack;
3437
- for (auto &Entry : NonAllocationCallToContextNodeMap) {
3438
- auto *Node = Entry.second ;
3439
- if (Node->isRemoved ())
3440
- continue ;
3441
- // It is a root if it doesn't have callers.
3442
- if (!Node->CallerEdges .empty ())
3443
- continue ;
3444
- markBackedges (Node, Visited, CurrentStack);
3445
- assert (CurrentStack.empty ());
3446
- }
3447
- }
3448
3462
for (auto &Entry : AllocationCallToContextNodeMap) {
3449
3463
Visited.clear ();
3450
3464
identifyClones (Entry.second , Visited, Entry.second ->getContextIds ());
0 commit comments