Skip to content

Commit 1b8e475

Browse files
committed
[Profiler] Avoid exposing the RegionCounterMap
Not sure why we ever did this, expose the counter index via a lookup method instead.
1 parent e6d9f38 commit 1b8e475

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

include/swift/SIL/SILProfiler.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,13 @@ class SILProfiler : public SILAllocated<SILProfiler> {
142142
/// Get the number of region counters.
143143
unsigned getNumRegionCounters() const { return NumRegionCounters; }
144144

145-
/// Get the mapping from a \c ProfileCounterRef to its corresponding
146-
/// profile counter.
147-
const llvm::DenseMap<ProfileCounterRef, unsigned> &
148-
getRegionCounterMap() const {
149-
return RegionCounterMap;
145+
/// Retrieve the counter index for a given counter reference, asserting that
146+
/// it is present.
147+
unsigned getCounterIndexFor(ProfileCounterRef ref);
148+
149+
/// Whether a counter has been recorded for the given counter reference.
150+
bool hasCounterFor(ProfileCounterRef ref) {
151+
return RegionCounterMap.contains(ref);
150152
}
151153

152154
private:

lib/SIL/IR/SILProfiler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,3 +1491,9 @@ llvm::Optional<ASTNode> SILProfiler::getPGOParent(ASTNode Node) {
14911491
}
14921492
return it->getSecond();
14931493
}
1494+
1495+
unsigned SILProfiler::getCounterIndexFor(ProfileCounterRef ref) {
1496+
auto result = RegionCounterMap.find(ref);
1497+
assert(result != RegionCounterMap.end());
1498+
return result->second;
1499+
}

lib/SILGen/SILGenFunction.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,19 +1726,15 @@ void SILGenFunction::emitProfilerIncrement(ProfileCounterRef Ref) {
17261726
if (!SP->hasRegionCounters() || !getModule().getOptions().UseProfile.empty())
17271727
return;
17281728

1729-
const auto &RegionCounterMap = SP->getRegionCounterMap();
1730-
auto CounterIt = RegionCounterMap.find(Ref);
1731-
1732-
assert(CounterIt != RegionCounterMap.end() &&
1733-
"cannot increment non-existent counter");
1729+
auto CounterIdx = SP->getCounterIndexFor(Ref);
17341730

17351731
// If we're at an unreachable point, the increment can be elided as the
17361732
// counter cannot be incremented.
17371733
if (!B.hasValidInsertionPoint())
17381734
return;
17391735

17401736
B.createIncrementProfilerCounter(
1741-
Ref.getLocation(), CounterIt->second, SP->getPGOFuncName(),
1737+
Ref.getLocation(), CounterIdx, SP->getPGOFuncName(),
17421738
SP->getNumRegionCounters(), SP->getPGOFuncHash());
17431739
}
17441740

0 commit comments

Comments
 (0)