Skip to content

Commit ae5f1a7

Browse files
[MemProf] Convert CallContextInfo to a struct (NFC) (#108086)
As suggested in #107918, improve readability by converting this tuple to a struct.
1 parent 829ea59 commit ae5f1a7

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,20 @@ class CallsiteContextGraph {
470470
private:
471471
using EdgeIter = typename std::vector<std::shared_ptr<ContextEdge>>::iterator;
472472

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+
};
475487

476488
/// Assigns the given Node to calls at or inlined into the location with
477489
/// the Node's stack id, after post order traversing and processing its
@@ -1458,7 +1470,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
14581470
auto &Calls = It.getSecond();
14591471
// Skip single calls with a single stack id. These don't need a new node.
14601472
if (Calls.size() == 1) {
1461-
auto &Ids = std::get<1>(Calls[0]);
1473+
auto &Ids = Calls[0].StackIds;
14621474
if (Ids.size() == 1)
14631475
continue;
14641476
}
@@ -1474,18 +1486,15 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
14741486
// that to sort by.
14751487
DenseMap<const FuncTy *, unsigned> FuncToIndex;
14761488
for (const auto &[Idx, CallCtxInfo] : enumerate(Calls))
1477-
FuncToIndex.insert({std::get<2>(CallCtxInfo), Idx});
1489+
FuncToIndex.insert({CallCtxInfo.Func, Idx});
14781490
std::stable_sort(
14791491
Calls.begin(), Calls.end(),
14801492
[&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])));
14891498
});
14901499

14911500
// Find the node for the last stack id, which should be the same
@@ -1520,7 +1529,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::updateStackNodes() {
15201529
#ifndef NDEBUG
15211530
// If this call has a different set of ids than the last one, clear the
15221531
// 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)
15241533
MatchingIdsFuncSet.clear();
15251534
else
15261535
// 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() {
16071616
// assigned to the same context node, and skip them.
16081617
bool DuplicateContextIds = false;
16091618
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;
16111621
if (NextIds != Ids)
16121622
break;
1613-
auto *NextFunc = std::get<2>(Calls[J]);
1623+
auto *NextFunc = CallCtxInfo.Func;
16141624
if (NextFunc != Func) {
16151625
// We have another Call with the same ids but that cannot share this
16161626
// node, must duplicate ids for it.
16171627
DuplicateContextIds = true;
16181628
break;
16191629
}
1620-
auto &NextCall = std::get<0>(Calls[J]);
1630+
auto &NextCall = CallCtxInfo.Call;
16211631
CallToMatchingCall[NextCall] = Call;
16221632
// Update I so that it gets incremented correctly to skip this call.
16231633
I = J;

0 commit comments

Comments
 (0)