@@ -36,6 +36,30 @@ static bool isUnmappedDecl(Decl *D) {
36
36
return D->isImplicit () || isa<EnumCaseDecl>(D);
37
37
}
38
38
39
+ // / Walk the non-static initializers in \p PBD.
40
+ static void walkForProfiling (PatternBindingDecl *PBD, ASTWalker &Walker) {
41
+ if (PBD && !PBD->isStatic ())
42
+ for (auto E : PBD->getPatternList ())
43
+ if (E.getInit ())
44
+ E.getInit ()->walk (Walker);
45
+ }
46
+
47
+ // / Walk the AST of \c Root and related nodes that are relevant for profiling.
48
+ static void walkForProfiling (AbstractFunctionDecl *Root, ASTWalker &Walker) {
49
+ Root->walk (Walker);
50
+
51
+ // We treat class initializers as part of the constructor for profiling.
52
+ if (auto *CD = dyn_cast<ConstructorDecl>(Root)) {
53
+ Type DT = CD->getDeclContext ()->getDeclaredTypeInContext ();
54
+ auto *NominalType = DT->getNominalOrBoundGenericNominal ();
55
+ for (auto *Member : NominalType->getMembers ()) {
56
+ // Find pattern binding declarations that have initializers.
57
+ if (auto *PBD = dyn_cast<PatternBindingDecl>(Member))
58
+ walkForProfiling (PBD, Walker);
59
+ }
60
+ }
61
+ }
62
+
39
63
ProfilerRAII::ProfilerRAII (SILGenModule &SGM, AbstractFunctionDecl *D)
40
64
: SGM(SGM), PreviousProfiler(std::move(SGM.Profiler)) {
41
65
const auto &Opts = SGM.M .getOptions ();
@@ -82,6 +106,7 @@ struct MapRegionCounters : public ASTWalker {
82
106
CounterMap[FS->getBody ()] = NextCounter++;
83
107
} else if (auto *FES = dyn_cast<ForEachStmt>(S)) {
84
108
CounterMap[FES->getBody ()] = NextCounter++;
109
+ walkForProfiling (FES->getIterator (), *this );
85
110
} else if (auto *SS = dyn_cast<SwitchStmt>(S)) {
86
111
CounterMap[SS] = NextCounter++;
87
112
} else if (auto *CS = dyn_cast<CaseStmt>(S)) {
@@ -494,6 +519,7 @@ struct CoverageMapping : public ASTWalker {
494
519
} else if (auto *FES = dyn_cast<ForEachStmt>(S)) {
495
520
assignCounter (FES, CounterExpr::Zero ());
496
521
assignCounter (FES->getBody ());
522
+ walkForProfiling (FES->getIterator (), *this );
497
523
498
524
} else if (auto *SS = dyn_cast<SwitchStmt>(S)) {
499
525
assignCounter (SS);
@@ -625,25 +651,6 @@ struct CoverageMapping : public ASTWalker {
625
651
626
652
} // end anonymous namespace
627
653
628
- // / Walk the AST of \c Root and related nodes that are relevant for profiling.
629
- static void walkForProfiling (AbstractFunctionDecl *Root, ASTWalker &Walker) {
630
- Root->walk (Walker);
631
-
632
- // We treat class initializers as part of the constructor for profiling.
633
- if (auto *CD = dyn_cast<ConstructorDecl>(Root)) {
634
- Type DT = CD->getDeclContext ()->getDeclaredTypeInContext ();
635
- auto *NominalType = DT->getNominalOrBoundGenericNominal ();
636
- for (auto *Member : NominalType->getMembers ()) {
637
- // Find pattern binding declarations that have initializers.
638
- if (auto *PBD = dyn_cast<PatternBindingDecl>(Member))
639
- if (!PBD->isStatic ())
640
- for (auto E : PBD->getPatternList ())
641
- if (E.getInit ())
642
- E.getInit ()->walk (Walker);
643
- }
644
- }
645
- }
646
-
647
654
static llvm::GlobalValue::LinkageTypes
648
655
getEquivalentPGOLinkage (FormalLinkage Linkage) {
649
656
switch (Linkage) {
0 commit comments