@@ -470,8 +470,20 @@ class CallsiteContextGraph {
470
470
private:
471
471
using EdgeIter = typename std::vector<std::shared_ptr<ContextEdge>>::iterator;
472
472
473
- using CallContextInfo = std::tuple<CallTy, std::vector<uint64_t >,
474
- const FuncTy *, DenseSet<uint32_t >>;
473
+ // Structure to keep track of information for each call as we are matching
474
+ // non-allocation callsites onto context nodes created from the allocation
475
+ // call metadata / summary contexts.
476
+ struct CallContextInfo {
477
+ // The callsite we're trying to match.
478
+ CallTy Call;
479
+ // The callsites stack ids that have a context node in the graph.
480
+ std::vector<uint64_t > StackIds;
481
+ // The function containing this callsite.
482
+ const FuncTy *Func;
483
+ // Initially empty, if needed this will be updated to contain the context
484
+ // ids for use in a new context node created for this callsite.
485
+ DenseSet<uint32_t > ContextIds;
486
+ };
475
487
476
488
// / Assigns the given Node to calls at or inlined into the location with
477
489
// / the Node's stack id, after post order traversing and processing its
@@ -1458,7 +1470,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
1458
1470
auto &Calls = It.getSecond ();
1459
1471
// Skip single calls with a single stack id. These don't need a new node.
1460
1472
if (Calls.size () == 1 ) {
1461
- auto &Ids = std::get< 1 >( Calls[0 ]) ;
1473
+ auto &Ids = Calls[0 ]. StackIds ;
1462
1474
if (Ids.size () == 1 )
1463
1475
continue ;
1464
1476
}
@@ -1474,18 +1486,15 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
1474
1486
// that to sort by.
1475
1487
DenseMap<const FuncTy *, unsigned > FuncToIndex;
1476
1488
for (const auto &[Idx, CallCtxInfo] : enumerate(Calls))
1477
- FuncToIndex.insert ({std::get< 2 >( CallCtxInfo) , Idx});
1489
+ FuncToIndex.insert ({CallCtxInfo. Func , Idx});
1478
1490
std::stable_sort (
1479
1491
Calls.begin (), Calls.end (),
1480
1492
[&FuncToIndex](const CallContextInfo &A, const CallContextInfo &B) {
1481
- auto &IdsA = std::get<1 >(A);
1482
- auto &IdsB = std::get<1 >(B);
1483
- auto *FuncA = std::get<2 >(A);
1484
- auto *FuncB = std::get<2 >(B);
1485
- return IdsA.size () > IdsB.size () ||
1486
- (IdsA.size () == IdsB.size () &&
1487
- (IdsA < IdsB ||
1488
- (IdsA == IdsB && FuncToIndex[FuncA] < FuncToIndex[FuncB])));
1493
+ return A.StackIds .size () > B.StackIds .size () ||
1494
+ (A.StackIds .size () == B.StackIds .size () &&
1495
+ (A.StackIds < B.StackIds ||
1496
+ (A.StackIds == B.StackIds &&
1497
+ FuncToIndex[A.Func ] < FuncToIndex[B.Func ])));
1489
1498
});
1490
1499
1491
1500
// Find the node for the last stack id, which should be the same
@@ -1520,7 +1529,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
1520
1529
#ifndef NDEBUG
1521
1530
// If this call has a different set of ids than the last one, clear the
1522
1531
// set used to ensure they are sorted properly.
1523
- if (I > 0 && Ids != std::get< 1 >( Calls[I - 1 ]) )
1532
+ if (I > 0 && Ids != Calls[I - 1 ]. StackIds )
1524
1533
MatchingIdsFuncSet.clear ();
1525
1534
else
1526
1535
// If the prior call had the same stack ids this set would not be empty.
@@ -1607,17 +1616,18 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
1607
1616
// assigned to the same context node, and skip them.
1608
1617
bool DuplicateContextIds = false ;
1609
1618
for (unsigned J = I + 1 ; J < Calls.size (); J++) {
1610
- auto &NextIds = std::get<1 >(Calls[J]);
1619
+ auto &CallCtxInfo = Calls[J];
1620
+ auto &NextIds = CallCtxInfo.StackIds ;
1611
1621
if (NextIds != Ids)
1612
1622
break ;
1613
- auto *NextFunc = std::get< 2 >(Calls[J]) ;
1623
+ auto *NextFunc = CallCtxInfo. Func ;
1614
1624
if (NextFunc != Func) {
1615
1625
// We have another Call with the same ids but that cannot share this
1616
1626
// node, must duplicate ids for it.
1617
1627
DuplicateContextIds = true ;
1618
1628
break ;
1619
1629
}
1620
- auto &NextCall = std::get< 0 >(Calls[J]) ;
1630
+ auto &NextCall = CallCtxInfo. Call ;
1621
1631
CallToMatchingCall[NextCall] = Call;
1622
1632
// Update I so that it gets incremented correctly to skip this call.
1623
1633
I = J;
0 commit comments