@@ -242,16 +242,9 @@ class CallsiteContextGraph {
242
242
// recursion.
243
243
bool Recursive = false ;
244
244
245
- // The corresponding allocation or interior call. This is the primary call
246
- // for which we have created this node.
245
+ // The corresponding allocation or interior call.
247
246
CallInfo Call;
248
247
249
- // List of other calls that can be treated the same as the primary call
250
- // through cloning. I.e. located in the same function and have the same
251
- // (possibly pruned) stack ids. They will be updated the same way as the
252
- // primary call when assigning to function clones.
253
- std::vector<CallInfo> MatchingCalls;
254
-
255
248
// For alloc nodes this is a unique id assigned when constructed, and for
256
249
// callsite stack nodes it is the original stack id when the node is
257
250
// constructed from the memprof MIB metadata on the alloc nodes. Note that
@@ -464,9 +457,6 @@ class CallsiteContextGraph {
464
457
// / iteration.
465
458
MapVector<FuncTy *, std::vector<CallInfo>> FuncToCallsWithMetadata;
466
459
467
- // / Records the function each call is located in.
468
- DenseMap<CallInfo, const FuncTy *> CallToFunc;
469
-
470
460
// / Map from callsite node to the enclosing caller function.
471
461
std::map<const ContextNode *, const FuncTy *> NodeToCallingFunc;
472
462
@@ -484,8 +474,7 @@ class CallsiteContextGraph {
484
474
// / StackIdToMatchingCalls map.
485
475
void assignStackNodesPostOrder (
486
476
ContextNode *Node, DenseSet<const ContextNode *> &Visited,
487
- DenseMap<uint64_t , std::vector<CallContextInfo>> &StackIdToMatchingCalls,
488
- DenseMap<CallInfo, CallInfo> &CallToMatchingCall);
477
+ DenseMap<uint64_t , std::vector<CallContextInfo>> &StackIdToMatchingCalls);
489
478
490
479
// / Duplicates the given set of context ids, updating the provided
491
480
// / map from each original id with the newly generated context ids,
@@ -1241,11 +1230,10 @@ static void checkNode(const ContextNode<DerivedCCG, FuncTy, CallTy> *Node,
1241
1230
1242
1231
template <typename DerivedCCG, typename FuncTy, typename CallTy>
1243
1232
void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
1244
- assignStackNodesPostOrder (
1245
- ContextNode *Node, DenseSet<const ContextNode *> &Visited,
1246
- DenseMap<uint64_t , std::vector<CallContextInfo>>
1247
- &StackIdToMatchingCalls,
1248
- DenseMap<CallInfo, CallInfo> &CallToMatchingCall) {
1233
+ assignStackNodesPostOrder (ContextNode *Node,
1234
+ DenseSet<const ContextNode *> &Visited,
1235
+ DenseMap<uint64_t , std::vector<CallContextInfo>>
1236
+ &StackIdToMatchingCalls) {
1249
1237
auto Inserted = Visited.insert (Node);
1250
1238
if (!Inserted.second )
1251
1239
return ;
@@ -1258,8 +1246,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
1258
1246
// Skip any that have been removed during the recursion.
1259
1247
if (!Edge)
1260
1248
continue ;
1261
- assignStackNodesPostOrder (Edge->Caller , Visited, StackIdToMatchingCalls,
1262
- CallToMatchingCall);
1249
+ assignStackNodesPostOrder (Edge->Caller , Visited, StackIdToMatchingCalls);
1263
1250
}
1264
1251
1265
1252
// If this node's stack id is in the map, update the graph to contain new
@@ -1302,19 +1289,8 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
1302
1289
auto &[Call, Ids, Func, SavedContextIds] = Calls[I];
1303
1290
// Skip any for which we didn't assign any ids, these don't get a node in
1304
1291
// the graph.
1305
- if (SavedContextIds.empty ()) {
1306
- // If this call has a matching call (located in the same function and
1307
- // having the same stack ids), simply add it to the context node created
1308
- // for its matching call earlier. These can be treated the same through
1309
- // cloning and get updated at the same time.
1310
- if (!CallToMatchingCall.contains (Call))
1311
- continue ;
1312
- auto MatchingCall = CallToMatchingCall[Call];
1313
- assert (NonAllocationCallToContextNodeMap.contains (MatchingCall));
1314
- NonAllocationCallToContextNodeMap[MatchingCall]->MatchingCalls .push_back (
1315
- Call);
1292
+ if (SavedContextIds.empty ())
1316
1293
continue ;
1317
- }
1318
1294
1319
1295
assert (LastId == Ids.back ());
1320
1296
@@ -1446,10 +1422,6 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
1446
1422
// there is more than one call with the same stack ids. Their (possibly newly
1447
1423
// duplicated) context ids are saved in the StackIdToMatchingCalls map.
1448
1424
DenseMap<uint32_t , DenseSet<uint32_t >> OldToNewContextIds;
1449
- // Save a map from each call to any that are found to match it. I.e. located
1450
- // in the same function and have the same (possibly pruned) stack ids. We use
1451
- // this to avoid creating extra graph nodes as they can be treated the same.
1452
- DenseMap<CallInfo, CallInfo> CallToMatchingCall;
1453
1425
for (auto &It : StackIdToMatchingCalls) {
1454
1426
auto &Calls = It.getSecond ();
1455
1427
// Skip single calls with a single stack id. These don't need a new node.
@@ -1488,13 +1460,6 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
1488
1460
DenseSet<uint32_t > LastNodeContextIds = LastNode->getContextIds ();
1489
1461
assert (!LastNodeContextIds.empty ());
1490
1462
1491
- // Map from function to the first call from the below list (with matching
1492
- // stack ids) found in that function. Note that calls from different
1493
- // functions can have the same stack ids because this is the list of stack
1494
- // ids that had (possibly pruned) nodes after building the graph from the
1495
- // allocation MIBs.
1496
- DenseMap<const FuncTy *, CallInfo> FuncToCallMap;
1497
-
1498
1463
for (unsigned I = 0 ; I < Calls.size (); I++) {
1499
1464
auto &[Call, Ids, Func, SavedContextIds] = Calls[I];
1500
1465
assert (SavedContextIds.empty ());
@@ -1568,18 +1533,6 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
1568
1533
continue ;
1569
1534
}
1570
1535
1571
- const FuncTy *CallFunc = CallToFunc[Call];
1572
-
1573
- // If the prior call had the same stack ids this map would not be empty.
1574
- // Check if we already have a call that "matches" because it is located
1575
- // in the same function.
1576
- if (FuncToCallMap.contains (CallFunc)) {
1577
- // Record the matching call found for this call, and skip it. We
1578
- // will subsequently combine it into the same node.
1579
- CallToMatchingCall[Call] = FuncToCallMap[CallFunc];
1580
- continue ;
1581
- }
1582
-
1583
1536
// Check if the next set of stack ids is the same (since the Calls vector
1584
1537
// of tuples is sorted by the stack ids we can just look at the next one).
1585
1538
bool DuplicateContextIds = false ;
@@ -1609,14 +1562,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
1609
1562
set_subtract (LastNodeContextIds, StackSequenceContextIds);
1610
1563
if (LastNodeContextIds.empty ())
1611
1564
break ;
1612
- // No longer possibly in a sequence of calls with duplicate stack ids,
1613
- // clear the map.
1614
- FuncToCallMap.clear ();
1615
- } else
1616
- // Record the call with its function, so we can locate it the next time
1617
- // we find a call from this function when processing the calls with the
1618
- // same stack ids.
1619
- FuncToCallMap[CallFunc] = Call;
1565
+ }
1620
1566
}
1621
1567
}
1622
1568
@@ -1633,8 +1579,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
1633
1579
// associated context ids over to the new nodes.
1634
1580
DenseSet<const ContextNode *> Visited;
1635
1581
for (auto &Entry : AllocationCallToContextNodeMap)
1636
- assignStackNodesPostOrder (Entry.second , Visited, StackIdToMatchingCalls,
1637
- CallToMatchingCall);
1582
+ assignStackNodesPostOrder (Entry.second , Visited, StackIdToMatchingCalls);
1638
1583
if (VerifyCCG)
1639
1584
check ();
1640
1585
}
@@ -1734,7 +1679,6 @@ ModuleCallsiteContextGraph::ModuleCallsiteContextGraph(
1734
1679
continue ;
1735
1680
if (auto *MemProfMD = I.getMetadata (LLVMContext::MD_memprof)) {
1736
1681
CallsWithMetadata.push_back (&I);
1737
- CallToFunc[&I] = &F;
1738
1682
auto *AllocNode = addAllocNode (&I, &F);
1739
1683
auto *CallsiteMD = I.getMetadata (LLVMContext::MD_callsite);
1740
1684
assert (CallsiteMD);
@@ -1756,10 +1700,8 @@ ModuleCallsiteContextGraph::ModuleCallsiteContextGraph(
1756
1700
I.setMetadata (LLVMContext::MD_callsite, nullptr );
1757
1701
}
1758
1702
// For callsite metadata, add to list for this function for later use.
1759
- else if (I.getMetadata (LLVMContext::MD_callsite)) {
1703
+ else if (I.getMetadata (LLVMContext::MD_callsite))
1760
1704
CallsWithMetadata.push_back (&I);
1761
- CallToFunc[&I] = &F;
1762
- }
1763
1705
}
1764
1706
}
1765
1707
if (!CallsWithMetadata.empty ())
@@ -1814,10 +1756,8 @@ IndexCallsiteContextGraph::IndexCallsiteContextGraph(
1814
1756
// correlate properly in applyImport in the backends.
1815
1757
if (AN.MIBs .empty ())
1816
1758
continue ;
1817
- IndexCall AllocCall (&AN);
1818
- CallsWithMetadata.push_back (AllocCall);
1819
- CallToFunc[AllocCall] = FS;
1820
- auto *AllocNode = addAllocNode (AllocCall, FS);
1759
+ CallsWithMetadata.push_back ({&AN});
1760
+ auto *AllocNode = addAllocNode ({&AN}, FS);
1821
1761
// Pass an empty CallStack to the CallsiteContext (second)
1822
1762
// parameter, since for ThinLTO we already collapsed out the inlined
1823
1763
// stack ids on the allocation call during ModuleSummaryAnalysis.
@@ -1848,11 +1788,8 @@ IndexCallsiteContextGraph::IndexCallsiteContextGraph(
1848
1788
}
1849
1789
// For callsite metadata, add to list for this function for later use.
1850
1790
if (!FS->callsites ().empty ())
1851
- for (auto &SN : FS->mutableCallsites ()) {
1852
- IndexCall StackNodeCall (&SN);
1853
- CallsWithMetadata.push_back (StackNodeCall);
1854
- CallToFunc[StackNodeCall] = FS;
1855
- }
1791
+ for (auto &SN : FS->mutableCallsites ())
1792
+ CallsWithMetadata.push_back ({&SN});
1856
1793
1857
1794
if (!CallsWithMetadata.empty ())
1858
1795
FuncToCallsWithMetadata[FS] = CallsWithMetadata;
@@ -2288,14 +2225,6 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::ContextNode::print(
2288
2225
if (Recursive)
2289
2226
OS << " (recursive)" ;
2290
2227
OS << " \n " ;
2291
- if (!MatchingCalls.empty ()) {
2292
- OS << " \t MatchingCalls:\n " ;
2293
- for (auto &MatchingCall : MatchingCalls) {
2294
- OS << " \t " ;
2295
- MatchingCall.print (OS);
2296
- OS << " \n " ;
2297
- }
2298
- }
2299
2228
OS << " \t AllocTypes: " << getAllocTypeString (AllocTypes) << " \n " ;
2300
2229
OS << " \t ContextIds:" ;
2301
2230
// Make a copy of the computed context ids that we can sort for stability.
@@ -2549,7 +2478,6 @@ CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::moveEdgeToNewCalleeClone(
2549
2478
std::make_unique<ContextNode>(Node->IsAllocation , Node->Call ));
2550
2479
ContextNode *Clone = NodeOwner.back ().get ();
2551
2480
Node->addClone (Clone);
2552
- Clone->MatchingCalls = Node->MatchingCalls ;
2553
2481
assert (NodeToCallingFunc.count (Node));
2554
2482
NodeToCallingFunc[Clone] = NodeToCallingFunc[Node];
2555
2483
moveEdgeToExistingCalleeClone (Edge, Clone, CallerEdgeI, /* NewClone=*/ true ,
@@ -3093,14 +3021,6 @@ bool CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::assignFunctions() {
3093
3021
if (CallMap.count (Call))
3094
3022
CallClone = CallMap[Call];
3095
3023
CallsiteClone->setCall (CallClone);
3096
- // Need to do the same for all matching calls.
3097
- for (auto &MatchingCall : Node->MatchingCalls ) {
3098
- CallInfo CallClone (MatchingCall);
3099
- if (CallMap.count (MatchingCall))
3100
- CallClone = CallMap[MatchingCall];
3101
- // Updates the call in the list.
3102
- MatchingCall = CallClone;
3103
- }
3104
3024
};
3105
3025
3106
3026
// Keep track of the clones of callsite Node that need to be assigned to
@@ -3267,16 +3187,6 @@ bool CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::assignFunctions() {
3267
3187
CallInfo NewCall (CallMap[OrigCall]);
3268
3188
assert (NewCall);
3269
3189
NewClone->setCall (NewCall);
3270
- // Need to do the same for all matching calls.
3271
- for (auto &MatchingCall : NewClone->MatchingCalls ) {
3272
- CallInfo OrigMatchingCall (MatchingCall);
3273
- OrigMatchingCall.setCloneNo (0 );
3274
- assert (CallMap.count (OrigMatchingCall));
3275
- CallInfo NewCall (CallMap[OrigMatchingCall]);
3276
- assert (NewCall);
3277
- // Updates the call in the list.
3278
- MatchingCall = NewCall;
3279
- }
3280
3190
}
3281
3191
}
3282
3192
// Fall through to handling below to perform the recording of the
@@ -3463,7 +3373,6 @@ bool CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::assignFunctions() {
3463
3373
3464
3374
if (Node->IsAllocation ) {
3465
3375
updateAllocationCall (Node->Call , allocTypeToUse (Node->AllocTypes ));
3466
- assert (Node->MatchingCalls .empty ());
3467
3376
return ;
3468
3377
}
3469
3378
@@ -3472,9 +3381,6 @@ bool CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::assignFunctions() {
3472
3381
3473
3382
auto CalleeFunc = CallsiteToCalleeFuncCloneMap[Node];
3474
3383
updateCall (Node->Call , CalleeFunc);
3475
- // Update all the matching calls as well.
3476
- for (auto &Call : Node->MatchingCalls )
3477
- updateCall (Call, CalleeFunc);
3478
3384
};
3479
3385
3480
3386
// Performs DFS traversal starting from allocation nodes to update calls to
0 commit comments