Skip to content

Commit 1bd3a6f

Browse files
authored
Merge pull request swiftlang#69917 from hamishknight/to-err
2 parents 66e4487 + 5e348c2 commit 1bd3a6f

16 files changed

+908
-433
lines changed

include/swift/SIL/SILCoverageMap.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,16 @@ class SILCoverageMap : public llvm::ilist_node<SILCoverageMap>,
162162
return Expressions;
163163
}
164164

165-
void printCounter(llvm::raw_ostream &OS, llvm::coverage::Counter C) const;
165+
/// Print a given profiling counter expression, given the reference to the
166+
/// counter, and the list of counters it may reference.
167+
static void
168+
printCounter(llvm::raw_ostream &OS, llvm::coverage::Counter C,
169+
ArrayRef<llvm::coverage::CounterExpression> Expressions);
170+
171+
/// Print a given profiling counter expression.
172+
void printCounter(llvm::raw_ostream &OS, llvm::coverage::Counter C) const {
173+
printCounter(OS, C, getExpressions());
174+
}
166175

167176
/// Print the coverage map.
168177
void print(llvm::raw_ostream &OS, bool Verbose = false,

include/swift/SIL/SILProfiler.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ class ProfileCounterRef final {
3636
public:
3737
enum class Kind : uint8_t {
3838
/// References an ASTNode.
39-
// TODO: This is the currently the only kind, but it will be expanded in
40-
// the future for e.g top-level entry and error branches.
41-
Node
39+
Node,
40+
41+
/// References the error branch for an apply or access.
42+
ErrorBranch
4243
};
4344

4445
private:
@@ -56,6 +57,12 @@ class ProfileCounterRef final {
5657
return ProfileCounterRef(node, Kind::Node);
5758
}
5859

60+
/// A profile counter that is associated with the error branch of a particular
61+
/// error-throwing AST node.
62+
static ProfileCounterRef errorBranchOf(ASTNode node) {
63+
return ProfileCounterRef(node, Kind::ErrorBranch);
64+
}
65+
5966
/// Retrieve the corresponding location of the counter.
6067
SILLocation getLocation() const;
6168

@@ -135,11 +142,13 @@ class SILProfiler : public SILAllocated<SILProfiler> {
135142
/// Get the number of region counters.
136143
unsigned getNumRegionCounters() const { return NumRegionCounters; }
137144

138-
/// Get the mapping from a \c ProfileCounterRef to its corresponding
139-
/// profile counter.
140-
const llvm::DenseMap<ProfileCounterRef, unsigned> &
141-
getRegionCounterMap() const {
142-
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);
143152
}
144153

145154
private:

lib/SIL/IR/SILCoverageMap.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ struct Printer {
100100
};
101101
} // end anonymous namespace
102102

103-
void SILCoverageMap::printCounter(llvm::raw_ostream &OS,
104-
llvm::coverage::Counter C) const {
105-
OS << Printer(C, getExpressions());
103+
void SILCoverageMap::printCounter(
104+
llvm::raw_ostream &OS, llvm::coverage::Counter C,
105+
ArrayRef<llvm::coverage::CounterExpression> Expressions) {
106+
OS << Printer(C, Expressions);
106107
}

0 commit comments

Comments
 (0)