@@ -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;
@@ -853,7 +857,10 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
853
857
854
858
// Emit the 'then' code.
855
859
EmitBlock (ThenBlock);
856
- incrementProfileCounter (&S);
860
+ if (llvm::EnableSingleByteCoverage)
861
+ incrementProfileCounter (S.getThen ());
862
+ else
863
+ incrementProfileCounter (&S);
857
864
{
858
865
RunCleanupsScope ThenScope (*this );
859
866
EmitStmt (S.getThen ());
@@ -867,6 +874,9 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
867
874
auto NL = ApplyDebugLocation::CreateEmpty (*this );
868
875
EmitBlock (ElseBlock);
869
876
}
877
+ // When single byte coverage mode is enabled, add a counter to else block.
878
+ if (llvm::EnableSingleByteCoverage)
879
+ incrementProfileCounter (Else);
870
880
{
871
881
RunCleanupsScope ElseScope (*this );
872
882
EmitStmt (Else);
@@ -880,6 +890,11 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
880
890
881
891
// Emit the continuation block for code after the if.
882
892
EmitBlock (ContBlock, true );
893
+
894
+ // When single byte coverage mode is enabled, add a counter to continuation
895
+ // block.
896
+ if (llvm::EnableSingleByteCoverage)
897
+ incrementProfileCounter (&S);
883
898
}
884
899
885
900
void CodeGenFunction::EmitWhileStmt (const WhileStmt &S,
@@ -924,6 +939,10 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
924
939
SourceLocToDebugLoc (R.getEnd ()),
925
940
checkIfLoopMustProgress (CondIsConstInt));
926
941
942
+ // When single byte coverage mode is enabled, add a counter to loop condition.
943
+ if (llvm::EnableSingleByteCoverage)
944
+ incrementProfileCounter (S.getCond ());
945
+
927
946
// As long as the condition is true, go to the loop body.
928
947
llvm::BasicBlock *LoopBody = createBasicBlock (" while.body" );
929
948
if (EmitBoolCondBranch) {
@@ -956,7 +975,11 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
956
975
{
957
976
RunCleanupsScope BodyScope (*this );
958
977
EmitBlock (LoopBody);
959
- incrementProfileCounter (&S);
978
+ // When single byte coverage mode is enabled, add a counter to the body.
979
+ if (llvm::EnableSingleByteCoverage)
980
+ incrementProfileCounter (S.getBody ());
981
+ else
982
+ incrementProfileCounter (&S);
960
983
EmitStmt (S.getBody ());
961
984
}
962
985
@@ -978,6 +1001,11 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
978
1001
// a branch, try to erase it.
979
1002
if (!EmitBoolCondBranch)
980
1003
SimplifyForwardingBlocks (LoopHeader.getBlock ());
1004
+
1005
+ // When single byte coverage mode is enabled, add a counter to continuation
1006
+ // block.
1007
+ if (llvm::EnableSingleByteCoverage)
1008
+ incrementProfileCounter (&S);
981
1009
}
982
1010
983
1011
void CodeGenFunction::EmitDoStmt (const DoStmt &S,
@@ -993,13 +1021,19 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S,
993
1021
// Emit the body of the loop.
994
1022
llvm::BasicBlock *LoopBody = createBasicBlock (" do.body" );
995
1023
996
- EmitBlockWithFallThrough (LoopBody, &S);
1024
+ if (llvm::EnableSingleByteCoverage)
1025
+ EmitBlockWithFallThrough (LoopBody, S.getBody ());
1026
+ else
1027
+ EmitBlockWithFallThrough (LoopBody, &S);
997
1028
{
998
1029
RunCleanupsScope BodyScope (*this );
999
1030
EmitStmt (S.getBody ());
1000
1031
}
1001
1032
1002
1033
EmitBlock (LoopCond.getBlock ());
1034
+ // When single byte coverage mode is enabled, add a counter to loop condition.
1035
+ if (llvm::EnableSingleByteCoverage)
1036
+ incrementProfileCounter (S.getCond ());
1003
1037
1004
1038
// C99 6.8.5.2: "The evaluation of the controlling expression takes place
1005
1039
// after each execution of the loop body."
@@ -1040,6 +1074,11 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S,
1040
1074
// emitting a branch, try to erase it.
1041
1075
if (!EmitBoolCondBranch)
1042
1076
SimplifyForwardingBlocks (LoopCond.getBlock ());
1077
+
1078
+ // When single byte coverage mode is enabled, add a counter to continuation
1079
+ // block.
1080
+ if (llvm::EnableSingleByteCoverage)
1081
+ incrementProfileCounter (&S);
1043
1082
}
1044
1083
1045
1084
void CodeGenFunction::EmitForStmt (const ForStmt &S,
@@ -1098,6 +1137,11 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
1098
1137
BreakContinueStack.back ().ContinueBlock = Continue;
1099
1138
}
1100
1139
1140
+ // When single byte coverage mode is enabled, add a counter to loop
1141
+ // condition.
1142
+ if (llvm::EnableSingleByteCoverage)
1143
+ incrementProfileCounter (S.getCond ());
1144
+
1101
1145
llvm::BasicBlock *ExitBlock = LoopExit.getBlock ();
1102
1146
// If there are any cleanups between here and the loop-exit scope,
1103
1147
// create a block to stage a loop exit along.
@@ -1128,8 +1172,12 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
1128
1172
// Treat it as a non-zero constant. Don't even create a new block for the
1129
1173
// body, just fall into it.
1130
1174
}
1131
- incrementProfileCounter (&S);
1132
1175
1176
+ // When single byte coverage mode is enabled, add a counter to the body.
1177
+ if (llvm::EnableSingleByteCoverage)
1178
+ incrementProfileCounter (S.getBody ());
1179
+ else
1180
+ incrementProfileCounter (&S);
1133
1181
{
1134
1182
// Create a separate cleanup scope for the body, in case it is not
1135
1183
// a compound statement.
@@ -1141,6 +1189,8 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
1141
1189
if (S.getInc ()) {
1142
1190
EmitBlock (Continue.getBlock ());
1143
1191
EmitStmt (S.getInc ());
1192
+ if (llvm::EnableSingleByteCoverage)
1193
+ incrementProfileCounter (S.getInc ());
1144
1194
}
1145
1195
1146
1196
BreakContinueStack.pop_back ();
@@ -1156,6 +1206,11 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
1156
1206
1157
1207
// Emit the fall-through block.
1158
1208
EmitBlock (LoopExit.getBlock (), true );
1209
+
1210
+ // When single byte coverage mode is enabled, add a counter to continuation
1211
+ // block.
1212
+ if (llvm::EnableSingleByteCoverage)
1213
+ incrementProfileCounter (&S);
1159
1214
}
1160
1215
1161
1216
void
@@ -1208,7 +1263,10 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S,
1208
1263
}
1209
1264
1210
1265
EmitBlock (ForBody);
1211
- incrementProfileCounter (&S);
1266
+ if (llvm::EnableSingleByteCoverage)
1267
+ incrementProfileCounter (S.getBody ());
1268
+ else
1269
+ incrementProfileCounter (&S);
1212
1270
1213
1271
// Create a block for the increment. In case of a 'continue', we jump there.
1214
1272
JumpDest Continue = getJumpDestInCurrentScope (" for.inc" );
@@ -1238,6 +1296,11 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S,
1238
1296
1239
1297
// Emit the fall-through block.
1240
1298
EmitBlock (LoopExit.getBlock (), true );
1299
+
1300
+ // When single byte coverage mode is enabled, add a counter to continuation
1301
+ // block.
1302
+ if (llvm::EnableSingleByteCoverage)
1303
+ incrementProfileCounter (&S);
1241
1304
}
1242
1305
1243
1306
void CodeGenFunction::EmitReturnOfRValue (RValue RV, QualType Ty) {
0 commit comments