Skip to content

Commit 89145f3

Browse files
committed
[Profiler] NFC: Rename assignCounter -> assignKnownCounter
Make it clearer that we expect an existing counter to have been assigned by MapRegionCounters.
1 parent 2c9819a commit 89145f3

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

lib/SIL/IR/SILProfiler.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,9 @@ struct CoverageMapping : public ASTWalker {
757757
Res.first->second = std::move(Expr);
758758
}
759759

760-
/// Create a counter expression referencing \c Node's own counter.
761-
CounterExpr assignCounter(ASTNode Node) {
760+
/// Create a counter expression referencing \c Node's own counter. This must
761+
/// have been previously mapped by MapRegionCounters.
762+
CounterExpr assignKnownCounter(ASTNode Node) {
762763
auto Counter = CounterExpr::Leaf(Node);
763764
assignCounter(Node, Counter);
764765
return Counter;
@@ -966,10 +967,10 @@ struct CoverageMapping : public ASTWalker {
966967
PreWalkAction walkToDeclPre(Decl *D) override {
967968
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) {
968969
return visitFunctionDecl(*this, AFD, [&] {
969-
assignCounter(AFD->getBody());
970+
assignKnownCounter(AFD->getBody());
970971
});
971972
} else if (auto *TLCD = dyn_cast<TopLevelCodeDecl>(D)) {
972-
assignCounter(TLCD->getBody());
973+
assignKnownCounter(TLCD->getBody());
973974
ImplicitTopLevelBody = TLCD->getBody();
974975
return Action::Continue();
975976
}
@@ -1005,15 +1006,15 @@ struct CoverageMapping : public ASTWalker {
10051006

10061007
// We emit a counter for the then block, and define the else block in
10071008
// terms of it.
1008-
auto ThenCounter = assignCounter(IS->getThenStmt());
1009+
auto ThenCounter = assignKnownCounter(IS->getThenStmt());
10091010
if (IS->getElseStmt()) {
10101011
auto ElseCounter =
10111012
CounterExpr::Sub(getCurrentCounter(), ThenCounter, CounterAlloc);
10121013
assignCounter(IS->getElseStmt(), ElseCounter);
10131014
}
10141015
} else if (auto *GS = dyn_cast<GuardStmt>(S)) {
10151016
assignCounter(GS, CounterExpr::Zero());
1016-
assignCounter(GS->getBody());
1017+
assignKnownCounter(GS->getBody());
10171018

10181019
} else if (auto *WS = dyn_cast<WhileStmt>(S)) {
10191020
// The counter for the while statement itself tracks the number of jumps
@@ -1022,22 +1023,22 @@ struct CoverageMapping : public ASTWalker {
10221023

10231024
if (auto *E = getConditionNode(WS->getCond()))
10241025
assignCounter(E, getCurrentCounter());
1025-
assignCounter(WS->getBody());
1026+
assignKnownCounter(WS->getBody());
10261027

10271028
} else if (auto *RWS = dyn_cast<RepeatWhileStmt>(S)) {
10281029
// The counter for the while statement itself tracks the number of jumps
10291030
// to it by break and continue statements.
10301031
assignCounter(RWS, CounterExpr::Zero());
10311032

1032-
auto BodyCounter = assignCounter(RWS->getBody());
1033+
auto BodyCounter = assignKnownCounter(RWS->getBody());
10331034
assignCounter(RWS->getCond(), BodyCounter);
10341035
RepeatWhileStack.push_back(RWS);
10351036

10361037
} else if (auto *FES = dyn_cast<ForEachStmt>(S)) {
10371038
// The counter for the for statement itself tracks the number of jumps
10381039
// to it by break and continue statements.
10391040
assignCounter(FES, CounterExpr::Zero());
1040-
assignCounter(FES->getBody());
1041+
assignKnownCounter(FES->getBody());
10411042

10421043
} else if (auto *SS = dyn_cast<SwitchStmt>(S)) {
10431044
// The counter for the switch statement itself tracks the number of jumps
@@ -1049,7 +1050,7 @@ struct CoverageMapping : public ASTWalker {
10491050

10501051
// Assign counters for cases so they're available for fallthrough.
10511052
for (CaseStmt *Case : SS->getCases())
1052-
assignCounter(Case);
1053+
assignKnownCounter(Case);
10531054

10541055
} else if (auto caseStmt = dyn_cast<CaseStmt>(S)) {
10551056
if (caseStmt->getParentKind() == CaseParentKind::Switch)
@@ -1066,7 +1067,7 @@ struct CoverageMapping : public ASTWalker {
10661067
assignCounter(DCS->getBody(), getCurrentCounter());
10671068

10681069
for (CaseStmt *Catch : DCS->getCatches())
1069-
assignCounter(Catch->getBody());
1070+
assignKnownCounter(Catch->getBody());
10701071

10711072
// Initialize the exit count of the do-catch to the entry count, then
10721073
// subtract off non-local exits as they are visited.
@@ -1183,19 +1184,19 @@ struct CoverageMapping : public ASTWalker {
11831184
if (Parent.isNull()) {
11841185
assert(RegionStack.empty() &&
11851186
"Mapped a region before visiting the root?");
1186-
assignCounter(E);
1187+
assignKnownCounter(E);
11871188
}
11881189

11891190
if (isa<LazyInitializerExpr>(E))
1190-
assignCounter(E);
1191+
assignKnownCounter(E);
11911192

11921193
if (hasCounter(E))
11931194
pushRegion(E);
11941195

11951196
assert(!RegionStack.empty() && "Must be within a region");
11961197

11971198
if (auto *IE = dyn_cast<TernaryExpr>(E)) {
1198-
auto ThenCounter = assignCounter(IE->getThenExpr());
1199+
auto ThenCounter = assignKnownCounter(IE->getThenExpr());
11991200
auto ElseCounter =
12001201
CounterExpr::Sub(getCurrentCounter(), ThenCounter, CounterAlloc);
12011202
assignCounter(IE->getElseExpr(), ElseCounter);

0 commit comments

Comments
 (0)