@@ -126,6 +126,9 @@ class PGOHash {
126
126
BinaryOperatorNE,
127
127
// The preceding values are available since PGO_HASH_V2.
128
128
129
+ // Cilk statements. These values are also available with PGO_HASH_V1.
130
+ CilkForStmt,
131
+
129
132
// Keep this last. It's for the static assert that follows.
130
133
LastHashType
131
134
};
@@ -267,6 +270,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
267
270
DEFINE_NESTABLE_TRAVERSAL (ObjCForCollectionStmt)
268
271
DEFINE_NESTABLE_TRAVERSAL (CXXTryStmt)
269
272
DEFINE_NESTABLE_TRAVERSAL (CXXCatchStmt)
273
+ DEFINE_NESTABLE_TRAVERSAL (CilkForStmt)
270
274
271
275
// / Get version \p HashVersion of the PGO hash for \p S.
272
276
PGOHash::HashType getHashType (PGOHashVersion HashVersion, const Stmt *S) {
@@ -327,6 +331,8 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
327
331
}
328
332
break ;
329
333
}
334
+ case Stmt::CilkForStmtClass:
335
+ return PGOHash::CilkForStmt;
330
336
}
331
337
332
338
if (HashVersion >= PGO_HASH_V2) {
@@ -744,6 +750,53 @@ struct ComputeRegionCounts : public ConstStmtVisitor<ComputeRegionCounts> {
744
750
setCount (ParentCount + RHSCount - CurrentCount);
745
751
RecordNextStmtCount = true ;
746
752
}
753
+
754
+ void VisitCilkForStmt (const CilkForStmt *S) {
755
+ RecordStmtCount (S);
756
+ if (S->getInit ())
757
+ Visit (S->getInit ());
758
+ if (S->getLimitStmt ())
759
+ Visit (S->getLimitStmt ());
760
+ if (S->getBeginStmt ())
761
+ Visit (S->getBeginStmt ());
762
+ if (S->getEndStmt ())
763
+ Visit (S->getEndStmt ());
764
+ if (S->getLoopVarDecl ())
765
+ Visit (S->getLoopVarDecl ());
766
+
767
+ uint64_t ParentCount = CurrentCount;
768
+
769
+ BreakContinueStack.push_back (BreakContinue ());
770
+ // Visit the body region first. (This is basically the same as a while
771
+ // loop; see further comments in VisitWhileStmt.)
772
+ uint64_t BodyCount = setCount (PGO.getRegionCount (S));
773
+ CountMap[S->getBody ()] = BodyCount;
774
+ Visit (S->getBody ());
775
+ uint64_t BackedgeCount = CurrentCount;
776
+ BreakContinue BC = BreakContinueStack.pop_back_val ();
777
+
778
+ // The increment is essentially part of the body but it needs to include
779
+ // the count for all the continue statements.
780
+ if (S->getInc ()) {
781
+ uint64_t IncCount = setCount (BackedgeCount + BC.ContinueCount );
782
+ CountMap[S->getInc ()] = IncCount;
783
+ Visit (S->getInc ());
784
+ }
785
+
786
+ // ...then go back and propagate counts through the condition.
787
+ uint64_t CondCount =
788
+ setCount (ParentCount + BackedgeCount + BC.ContinueCount );
789
+ if (S->getInitCond ()) {
790
+ CountMap[S->getInitCond ()] = ParentCount;
791
+ Visit (S->getInitCond ());
792
+ }
793
+ if (S->getCond ()) {
794
+ CountMap[S->getCond ()] = CondCount;
795
+ Visit (S->getCond ());
796
+ }
797
+ setCount (BC.BreakCount + CondCount - BodyCount);
798
+ RecordNextStmtCount = true ;
799
+ }
747
800
};
748
801
} // end anonymous namespace
749
802
0 commit comments