Skip to content

Commit e6d9f38

Browse files
committed
[Profiler] Introduce error branch ProfileCounterRefs
These reference error branches for AST nodes that can throw errors.
1 parent ade2671 commit e6d9f38

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

include/swift/SIL/SILProfiler.h

Lines changed: 10 additions & 3 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

lib/SIL/IR/SILProfiler.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,15 @@ SILLocation ProfileCounterRef::getLocation() const {
173173

174174
void ProfileCounterRef::dumpSimple(raw_ostream &OS) const {
175175
switch (RefKind) {
176-
case Kind::Node: {
176+
case Kind::Node:
177+
break;
178+
case Kind::ErrorBranch:
179+
OS << "error branch of: ";
180+
break;
181+
}
182+
switch (RefKind) {
183+
case Kind::Node:
184+
case Kind::ErrorBranch: {
177185
OS << Node.getOpaqueValue() << " ";
178186
if (auto *D = Node.dyn_cast<Decl *>()) {
179187
OS << Decl::getKindName(D->getKind());
@@ -190,6 +198,11 @@ void ProfileCounterRef::dump(raw_ostream &OS) const {
190198
switch (RefKind) {
191199
case Kind::Node:
192200
Node.dump(OS);
201+
break;
202+
case Kind::ErrorBranch:
203+
OS << "error branch of:\n";
204+
Node.dump(OS.indent(2));
205+
break;
193206
}
194207
}
195208

0 commit comments

Comments
 (0)