Skip to content

Commit 40bb608

Browse files
committed
[Profiler] NFC: Add some comments
1 parent 937d3b9 commit 40bb608

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/SIL/IR/SILProfiler.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ struct PGOMapping : public ASTWalker {
695695
}
696696
};
697697

698+
/// Produce coverage mapping information for a function. This involves taking
699+
/// the counters computed by MapRegionCounters, and annotating the source with
700+
/// regions that are defined in terms of those counters.
698701
struct CoverageMapping : public ASTWalker {
699702
private:
700703
const SourceManager &SM;
@@ -976,6 +979,8 @@ struct CoverageMapping : public ASTWalker {
976979
if (S->isImplicit() && S != ImplicitTopLevelBody)
977980
return {true, S};
978981

982+
// If we're in an 'incomplete' region, update it to include this node. This
983+
// ensures we only create the region if needed.
979984
if (!RegionStack.empty())
980985
extendRegion(S);
981986

@@ -986,7 +991,13 @@ struct CoverageMapping : public ASTWalker {
986991
} else if (auto *IS = dyn_cast<IfStmt>(S)) {
987992
if (auto *Cond = getConditionNode(IS->getCond()))
988993
assignCounter(Cond, CounterExpr::Ref(getCurrentCounter()));
994+
995+
// The counter for the if statement itself tracks the number of jumps to
996+
// it by break statements.
989997
assignCounter(IS, CounterExpr::Zero());
998+
999+
// We emit a counter for the then block, and define the else block in
1000+
// terms of it.
9901001
CounterExpr &ThenCounter = assignCounter(IS->getThenStmt());
9911002
if (IS->getElseStmt())
9921003
assignCounter(IS->getElseStmt(),
@@ -996,18 +1007,26 @@ struct CoverageMapping : public ASTWalker {
9961007
assignCounter(GS->getBody());
9971008

9981009
} else if (auto *WS = dyn_cast<WhileStmt>(S)) {
1010+
// The counter for the while statement itself tracks the number of jumps
1011+
// to it by break and continue statements.
9991012
assignCounter(WS, CounterExpr::Zero());
1013+
10001014
if (auto *E = getConditionNode(WS->getCond()))
10011015
assignCounter(E, CounterExpr::Ref(getCurrentCounter()));
10021016
assignCounter(WS->getBody());
10031017

10041018
} else if (auto *RWS = dyn_cast<RepeatWhileStmt>(S)) {
1019+
// The counter for the while statement itself tracks the number of jumps
1020+
// to it by break and continue statements.
10051021
assignCounter(RWS, CounterExpr::Zero());
1022+
10061023
CounterExpr &BodyCounter = assignCounter(RWS->getBody());
10071024
assignCounter(RWS->getCond(), CounterExpr::Ref(BodyCounter));
10081025
RepeatWhileStack.push_back(RWS);
10091026

10101027
} else if (auto *FES = dyn_cast<ForEachStmt>(S)) {
1028+
// The counter for the for statement itself tracks the number of jumps
1029+
// to it by break and continue statements.
10111030
assignCounter(FES, CounterExpr::Zero());
10121031
assignCounter(FES->getBody());
10131032

@@ -1021,7 +1040,10 @@ struct CoverageMapping : public ASTWalker {
10211040
if (caseStmt->getParentKind() == CaseParentKind::Switch)
10221041
pushRegion(S);
10231042
} else if (auto *DS = dyn_cast<DoStmt>(S)) {
1043+
// The counter for the do statement itself tracks the number of jumps
1044+
// to it by break statements.
10241045
assignCounter(DS, CounterExpr::Zero());
1046+
10251047
assignCounter(DS->getBody(), CounterExpr::Ref(getCurrentCounter()));
10261048

10271049
} else if (auto *DCS = dyn_cast<DoCatchStmt>(S)) {
@@ -1125,6 +1147,8 @@ struct CoverageMapping : public ASTWalker {
11251147
if (isa<AbstractClosureExpr>(E) && !Parent.isNull())
11261148
return {false, E};
11271149

1150+
// If we're in an 'incomplete' region, update it to include this node. This
1151+
// ensures we only create the region if needed.
11281152
if (!RegionStack.empty())
11291153
extendRegion(E);
11301154

0 commit comments

Comments
 (0)