Skip to content

Commit 1e3256f

Browse files
committed
Address review comments
1 parent 5a57d4e commit 1e3256f

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,18 @@ class CallsiteContextGraph {
319319
// ids.
320320
DenseSet<uint32_t> getContextIds() const {
321321
unsigned Count = 0;
322+
// Compute the number of ids for reserve below. In general we only need to
323+
// look at one set of edges, typically the callee edges, since other than
324+
// allocations and in some cases during recursion cloning, all the context
325+
// ids on the callers should also flow out via callee edges.
322326
for (auto &Edge : CalleeEdges.empty() ? CallerEdges : CalleeEdges)
323327
Count += Edge->getContextIds().size();
324328
DenseSet<uint32_t> ContextIds;
325329
ContextIds.reserve(Count);
326-
std::vector<std::shared_ptr<ContextEdge>> Empty;
327330
auto Edges = llvm::concat<const std::shared_ptr<ContextEdge>>(
328-
CalleeEdges, useCallerEdgesForContextInfo() ? CallerEdges : Empty);
331+
CalleeEdges, useCallerEdgesForContextInfo()
332+
? CallerEdges
333+
: std::vector<std::shared_ptr<ContextEdge>>());
329334
for (const auto &Edge : Edges)
330335
ContextIds.insert(Edge->getContextIds().begin(),
331336
Edge->getContextIds().end());
@@ -338,9 +343,10 @@ class CallsiteContextGraph {
338343
uint8_t BothTypes =
339344
(uint8_t)AllocationType::Cold | (uint8_t)AllocationType::NotCold;
340345
uint8_t AllocType = (uint8_t)AllocationType::None;
341-
std::vector<std::shared_ptr<ContextEdge>> Empty;
342346
auto Edges = llvm::concat<const std::shared_ptr<ContextEdge>>(
343-
CalleeEdges, useCallerEdgesForContextInfo() ? CallerEdges : Empty);
347+
CalleeEdges, useCallerEdgesForContextInfo()
348+
? CallerEdges
349+
: std::vector<std::shared_ptr<ContextEdge>>());
344350
for (const auto &Edge : Edges) {
345351
AllocType |= Edge->AllocTypes;
346352
// Bail early if alloc type reached both, no further refinement.
@@ -353,9 +359,10 @@ class CallsiteContextGraph {
353359
// The context ids set for this node is empty if its edge context ids are
354360
// also all empty.
355361
bool emptyContextIds() const {
356-
std::vector<std::shared_ptr<ContextEdge>> Empty;
357362
auto Edges = llvm::concat<const std::shared_ptr<ContextEdge>>(
358-
CalleeEdges, useCallerEdgesForContextInfo() ? CallerEdges : Empty);
363+
CalleeEdges, useCallerEdgesForContextInfo()
364+
? CallerEdges
365+
: std::vector<std::shared_ptr<ContextEdge>>());
359366
for (const auto &Edge : Edges) {
360367
if (!Edge->getContextIds().empty())
361368
return false;
@@ -3657,7 +3664,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::identifyClones(
36573664
// TODO: Can we do better in the case where the caller was already visited?
36583665
if (CallerEdge->IsBackedge && !CallerEdge->Caller->CloneOf &&
36593666
!Visited.count(CallerEdge->Caller)) {
3660-
auto OrigIdCount = CallerEdge->getContextIds().size();
3667+
const auto OrigIdCount = CallerEdge->getContextIds().size();
36613668
// Now do the recursive cloning of this backedge's caller, which was
36623669
// deferred earlier.
36633670
identifyClones(CallerEdge->Caller, Visited, CallerEdgeContextsForAlloc);
@@ -3714,9 +3721,10 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::identifyClones(
37143721
// updated CallerEdgeContextsForAlloc.
37153722
CallerAllocTypeForAlloc = computeAllocType(CallerEdgeContextsForAlloc);
37163723
CalleeEdgeAllocTypesForCallerEdge.clear();
3717-
for (auto &CalleeEdge : Node->CalleeEdges)
3724+
for (auto &CalleeEdge : Node->CalleeEdges) {
37183725
CalleeEdgeAllocTypesForCallerEdge.push_back(intersectAllocTypes(
37193726
CalleeEdge->getContextIds(), CallerEdgeContextsForAlloc));
3727+
}
37203728
}
37213729

37223730
// First see if we can use an existing clone. Check each clone and its

0 commit comments

Comments
 (0)