@@ -43,6 +43,10 @@ using namespace CodeGen;
43
43
// Statement Emission
44
44
// ===----------------------------------------------------------------------===//
45
45
46
+ namespace llvm {
47
+ extern cl::opt<bool > EnableSingleByteCoverage;
48
+ } // namespace llvm
49
+
46
50
void CodeGenFunction::EmitStopPoint (const Stmt *S) {
47
51
if (CGDebugInfo *DI = getDebugInfo ()) {
48
52
SourceLocation Loc;
@@ -856,7 +860,10 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
856
860
857
861
// Emit the 'then' code.
858
862
EmitBlock (ThenBlock);
859
- incrementProfileCounter (&S);
863
+ if (llvm::EnableSingleByteCoverage)
864
+ incrementProfileCounter (S.getThen ());
865
+ else
866
+ incrementProfileCounter (&S);
860
867
{
861
868
RunCleanupsScope ThenScope (*this );
862
869
EmitStmt (S.getThen ());
@@ -870,6 +877,9 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
870
877
auto NL = ApplyDebugLocation::CreateEmpty (*this );
871
878
EmitBlock (ElseBlock);
872
879
}
880
+ // When single byte coverage mode is enabled, add a counter to else block.
881
+ if (llvm::EnableSingleByteCoverage)
882
+ incrementProfileCounter (Else);
873
883
{
874
884
RunCleanupsScope ElseScope (*this );
875
885
EmitStmt (Else);
@@ -883,6 +893,11 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
883
893
884
894
// Emit the continuation block for code after the if.
885
895
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);
886
901
}
887
902
888
903
void CodeGenFunction::EmitWhileStmt (const WhileStmt &S,
@@ -927,6 +942,10 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
927
942
SourceLocToDebugLoc (R.getEnd ()),
928
943
checkIfLoopMustProgress (CondIsConstInt));
929
944
945
+ // When single byte coverage mode is enabled, add a counter to loop condition.
946
+ if (llvm::EnableSingleByteCoverage)
947
+ incrementProfileCounter (S.getCond ());
948
+
930
949
// As long as the condition is true, go to the loop body.
931
950
llvm::BasicBlock *LoopBody = createBasicBlock (" while.body" );
932
951
if (EmitBoolCondBranch) {
@@ -959,7 +978,11 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
959
978
{
960
979
RunCleanupsScope BodyScope (*this );
961
980
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);
963
986
EmitStmt (S.getBody ());
964
987
}
965
988
@@ -981,6 +1004,11 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
981
1004
// a branch, try to erase it.
982
1005
if (!EmitBoolCondBranch)
983
1006
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);
984
1012
}
985
1013
986
1014
void CodeGenFunction::EmitDoStmt (const DoStmt &S,
@@ -996,13 +1024,19 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S,
996
1024
// Emit the body of the loop.
997
1025
llvm::BasicBlock *LoopBody = createBasicBlock (" do.body" );
998
1026
999
- EmitBlockWithFallThrough (LoopBody, &S);
1027
+ if (llvm::EnableSingleByteCoverage)
1028
+ EmitBlockWithFallThrough (LoopBody, S.getBody ());
1029
+ else
1030
+ EmitBlockWithFallThrough (LoopBody, &S);
1000
1031
{
1001
1032
RunCleanupsScope BodyScope (*this );
1002
1033
EmitStmt (S.getBody ());
1003
1034
}
1004
1035
1005
1036
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 ());
1006
1040
1007
1041
// C99 6.8.5.2: "The evaluation of the controlling expression takes place
1008
1042
// after each execution of the loop body."
@@ -1043,6 +1077,11 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S,
1043
1077
// emitting a branch, try to erase it.
1044
1078
if (!EmitBoolCondBranch)
1045
1079
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);
1046
1085
}
1047
1086
1048
1087
void CodeGenFunction::EmitForStmt (const ForStmt &S,
@@ -1101,6 +1140,11 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
1101
1140
BreakContinueStack.back ().ContinueBlock = Continue;
1102
1141
}
1103
1142
1143
+ // When single byte coverage mode is enabled, add a counter to loop
1144
+ // condition.
1145
+ if (llvm::EnableSingleByteCoverage)
1146
+ incrementProfileCounter (S.getCond ());
1147
+
1104
1148
llvm::BasicBlock *ExitBlock = LoopExit.getBlock ();
1105
1149
// If there are any cleanups between here and the loop-exit scope,
1106
1150
// create a block to stage a loop exit along.
@@ -1131,8 +1175,12 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
1131
1175
// Treat it as a non-zero constant. Don't even create a new block for the
1132
1176
// body, just fall into it.
1133
1177
}
1134
- incrementProfileCounter (&S);
1135
1178
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);
1136
1184
{
1137
1185
// Create a separate cleanup scope for the body, in case it is not
1138
1186
// a compound statement.
@@ -1144,6 +1192,8 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
1144
1192
if (S.getInc ()) {
1145
1193
EmitBlock (Continue.getBlock ());
1146
1194
EmitStmt (S.getInc ());
1195
+ if (llvm::EnableSingleByteCoverage)
1196
+ incrementProfileCounter (S.getInc ());
1147
1197
}
1148
1198
1149
1199
BreakContinueStack.pop_back ();
@@ -1159,6 +1209,11 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
1159
1209
1160
1210
// Emit the fall-through block.
1161
1211
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);
1162
1217
}
1163
1218
1164
1219
void
@@ -1211,7 +1266,10 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S,
1211
1266
}
1212
1267
1213
1268
EmitBlock (ForBody);
1214
- incrementProfileCounter (&S);
1269
+ if (llvm::EnableSingleByteCoverage)
1270
+ incrementProfileCounter (S.getBody ());
1271
+ else
1272
+ incrementProfileCounter (&S);
1215
1273
1216
1274
// Create a block for the increment. In case of a 'continue', we jump there.
1217
1275
JumpDest Continue = getJumpDestInCurrentScope (" for.inc" );
@@ -1241,6 +1299,11 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S,
1241
1299
1242
1300
// Emit the fall-through block.
1243
1301
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);
1244
1307
}
1245
1308
1246
1309
void CodeGenFunction::EmitReturnOfRValue (RValue RV, QualType Ty) {
0 commit comments