@@ -43,6 +43,10 @@ using namespace CodeGen;
4343// Statement Emission
4444// ===----------------------------------------------------------------------===//
4545
46+ namespace llvm {
47+ extern cl::opt<bool > EnableSingleByteCoverage;
48+ } // namespace llvm
49+
4650void CodeGenFunction::EmitStopPoint (const Stmt *S) {
4751 if (CGDebugInfo *DI = getDebugInfo ()) {
4852 SourceLocation Loc;
@@ -856,7 +860,10 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
856860
857861 // Emit the 'then' code.
858862 EmitBlock (ThenBlock);
859- incrementProfileCounter (&S);
863+ if (llvm::EnableSingleByteCoverage)
864+ incrementProfileCounter (S.getThen ());
865+ else
866+ incrementProfileCounter (&S);
860867 {
861868 RunCleanupsScope ThenScope (*this );
862869 EmitStmt (S.getThen ());
@@ -870,6 +877,9 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
870877 auto NL = ApplyDebugLocation::CreateEmpty (*this );
871878 EmitBlock (ElseBlock);
872879 }
880+ // When single byte coverage mode is enabled, add a counter to else block.
881+ if (llvm::EnableSingleByteCoverage)
882+ incrementProfileCounter (Else);
873883 {
874884 RunCleanupsScope ElseScope (*this );
875885 EmitStmt (Else);
@@ -883,6 +893,11 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
883893
884894 // Emit the continuation block for code after the if.
885895 EmitBlock (ContBlock, true );
896+
897+ // When single byte coverage mode is enabled, add a counter to continuation
898+ // block.
899+ if (llvm::EnableSingleByteCoverage)
900+ incrementProfileCounter (&S);
886901}
887902
888903void CodeGenFunction::EmitWhileStmt (const WhileStmt &S,
@@ -927,6 +942,10 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
927942 SourceLocToDebugLoc (R.getEnd ()),
928943 checkIfLoopMustProgress (CondIsConstInt));
929944
945+ // When single byte coverage mode is enabled, add a counter to loop condition.
946+ if (llvm::EnableSingleByteCoverage)
947+ incrementProfileCounter (S.getCond ());
948+
930949 // As long as the condition is true, go to the loop body.
931950 llvm::BasicBlock *LoopBody = createBasicBlock (" while.body" );
932951 if (EmitBoolCondBranch) {
@@ -959,7 +978,11 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
959978 {
960979 RunCleanupsScope BodyScope (*this );
961980 EmitBlock (LoopBody);
962- incrementProfileCounter (&S);
981+ // When single byte coverage mode is enabled, add a counter to the body.
982+ if (llvm::EnableSingleByteCoverage)
983+ incrementProfileCounter (S.getBody ());
984+ else
985+ incrementProfileCounter (&S);
963986 EmitStmt (S.getBody ());
964987 }
965988
@@ -981,6 +1004,11 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
9811004 // a branch, try to erase it.
9821005 if (!EmitBoolCondBranch)
9831006 SimplifyForwardingBlocks (LoopHeader.getBlock ());
1007+
1008+ // When single byte coverage mode is enabled, add a counter to continuation
1009+ // block.
1010+ if (llvm::EnableSingleByteCoverage)
1011+ incrementProfileCounter (&S);
9841012}
9851013
9861014void CodeGenFunction::EmitDoStmt (const DoStmt &S,
@@ -996,13 +1024,19 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S,
9961024 // Emit the body of the loop.
9971025 llvm::BasicBlock *LoopBody = createBasicBlock (" do.body" );
9981026
999- EmitBlockWithFallThrough (LoopBody, &S);
1027+ if (llvm::EnableSingleByteCoverage)
1028+ EmitBlockWithFallThrough (LoopBody, S.getBody ());
1029+ else
1030+ EmitBlockWithFallThrough (LoopBody, &S);
10001031 {
10011032 RunCleanupsScope BodyScope (*this );
10021033 EmitStmt (S.getBody ());
10031034 }
10041035
10051036 EmitBlock (LoopCond.getBlock ());
1037+ // When single byte coverage mode is enabled, add a counter to loop condition.
1038+ if (llvm::EnableSingleByteCoverage)
1039+ incrementProfileCounter (S.getCond ());
10061040
10071041 // C99 6.8.5.2: "The evaluation of the controlling expression takes place
10081042 // after each execution of the loop body."
@@ -1043,6 +1077,11 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S,
10431077 // emitting a branch, try to erase it.
10441078 if (!EmitBoolCondBranch)
10451079 SimplifyForwardingBlocks (LoopCond.getBlock ());
1080+
1081+ // When single byte coverage mode is enabled, add a counter to continuation
1082+ // block.
1083+ if (llvm::EnableSingleByteCoverage)
1084+ incrementProfileCounter (&S);
10461085}
10471086
10481087void CodeGenFunction::EmitForStmt (const ForStmt &S,
@@ -1101,6 +1140,11 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
11011140 BreakContinueStack.back ().ContinueBlock = Continue;
11021141 }
11031142
1143+ // When single byte coverage mode is enabled, add a counter to loop
1144+ // condition.
1145+ if (llvm::EnableSingleByteCoverage)
1146+ incrementProfileCounter (S.getCond ());
1147+
11041148 llvm::BasicBlock *ExitBlock = LoopExit.getBlock ();
11051149 // If there are any cleanups between here and the loop-exit scope,
11061150 // create a block to stage a loop exit along.
@@ -1131,8 +1175,12 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
11311175 // Treat it as a non-zero constant. Don't even create a new block for the
11321176 // body, just fall into it.
11331177 }
1134- incrementProfileCounter (&S);
11351178
1179+ // When single byte coverage mode is enabled, add a counter to the body.
1180+ if (llvm::EnableSingleByteCoverage)
1181+ incrementProfileCounter (S.getBody ());
1182+ else
1183+ incrementProfileCounter (&S);
11361184 {
11371185 // Create a separate cleanup scope for the body, in case it is not
11381186 // a compound statement.
@@ -1144,6 +1192,8 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
11441192 if (S.getInc ()) {
11451193 EmitBlock (Continue.getBlock ());
11461194 EmitStmt (S.getInc ());
1195+ if (llvm::EnableSingleByteCoverage)
1196+ incrementProfileCounter (S.getInc ());
11471197 }
11481198
11491199 BreakContinueStack.pop_back ();
@@ -1159,6 +1209,11 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
11591209
11601210 // Emit the fall-through block.
11611211 EmitBlock (LoopExit.getBlock (), true );
1212+
1213+ // When single byte coverage mode is enabled, add a counter to continuation
1214+ // block.
1215+ if (llvm::EnableSingleByteCoverage)
1216+ incrementProfileCounter (&S);
11621217}
11631218
11641219void
@@ -1211,7 +1266,10 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S,
12111266 }
12121267
12131268 EmitBlock (ForBody);
1214- incrementProfileCounter (&S);
1269+ if (llvm::EnableSingleByteCoverage)
1270+ incrementProfileCounter (S.getBody ());
1271+ else
1272+ incrementProfileCounter (&S);
12151273
12161274 // Create a block for the increment. In case of a 'continue', we jump there.
12171275 JumpDest Continue = getJumpDestInCurrentScope (" for.inc" );
@@ -1241,6 +1299,11 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S,
12411299
12421300 // Emit the fall-through block.
12431301 EmitBlock (LoopExit.getBlock (), true );
1302+
1303+ // When single byte coverage mode is enabled, add a counter to continuation
1304+ // block.
1305+ if (llvm::EnableSingleByteCoverage)
1306+ incrementProfileCounter (&S);
12441307}
12451308
12461309void CodeGenFunction::EmitReturnOfRValue (RValue RV, QualType Ty) {
0 commit comments