@@ -165,8 +165,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
165
165
llvm::DenseMap<const Stmt *, unsigned > &CounterMap;
166
166
// / The next bitmap byte index to assign.
167
167
unsigned NextMCDCBitmapIdx;
168
- // / The map of statements to MC/DC bitmap coverage objects.
169
- llvm::DenseMap<const Stmt *, unsigned > &MCDCBitmapMap;
168
+ MCDC::State &MCDCState;
170
169
// / Maximum number of supported MC/DC conditions in a boolean expression.
171
170
unsigned MCDCMaxCond;
172
171
// / The profile version.
@@ -176,11 +175,11 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
176
175
177
176
MapRegionCounters (PGOHashVersion HashVersion, uint64_t ProfileVersion,
178
177
llvm::DenseMap<const Stmt *, unsigned > &CounterMap,
179
- llvm::DenseMap< const Stmt * , unsigned > &MCDCBitmapMap ,
180
- unsigned MCDCMaxCond, DiagnosticsEngine &Diag)
178
+ MCDC::State &MCDCState , unsigned MCDCMaxCond ,
179
+ DiagnosticsEngine &Diag)
181
180
: NextCounter(0 ), Hash(HashVersion), CounterMap(CounterMap),
182
- NextMCDCBitmapIdx (0 ), MCDCBitmapMap(MCDCBitmapMap ),
183
- MCDCMaxCond(MCDCMaxCond), ProfileVersion(ProfileVersion), Diag(Diag) {}
181
+ NextMCDCBitmapIdx (0 ), MCDCState(MCDCState), MCDCMaxCond(MCDCMaxCond ),
182
+ ProfileVersion(ProfileVersion), Diag(Diag) {}
184
183
185
184
// Blocks and lambdas are handled as separate functions, so we need not
186
185
// traverse them in the parent context.
@@ -309,7 +308,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
309
308
310
309
// Otherwise, allocate the number of bytes required for the bitmap
311
310
// based on the number of conditions. Must be at least 1-byte long.
312
- MCDCBitmapMap [BinOp] = NextMCDCBitmapIdx;
311
+ MCDCState. BitmapMap [BinOp] = NextMCDCBitmapIdx;
313
312
unsigned SizeInBits = std::max<unsigned >(1L << NumCond, CHAR_BIT);
314
313
NextMCDCBitmapIdx += SizeInBits / CHAR_BIT;
315
314
}
@@ -987,10 +986,9 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) {
987
986
unsigned MCDCMaxConditions = (CGM.getCodeGenOpts ().MCDCCoverage ) ? 6 : 0 ;
988
987
989
988
RegionCounterMap.reset (new llvm::DenseMap<const Stmt *, unsigned >);
990
- RegionMCDCBitmapMap .reset (new llvm::DenseMap< const Stmt *, unsigned > );
989
+ RegionMCDCState .reset (new MCDC::State );
991
990
MapRegionCounters Walker (HashVersion, ProfileVersion, *RegionCounterMap,
992
- *RegionMCDCBitmapMap, MCDCMaxConditions,
993
- CGM.getDiags ());
991
+ *RegionMCDCState, MCDCMaxConditions, CGM.getDiags ());
994
992
if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
995
993
Walker.TraverseDecl (const_cast <FunctionDecl *>(FD));
996
994
else if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
@@ -1001,7 +999,7 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) {
1001
999
Walker.TraverseDecl (const_cast <CapturedDecl *>(CD));
1002
1000
assert (Walker.NextCounter > 0 && " no entry counter mapped for decl" );
1003
1001
NumRegionCounters = Walker.NextCounter ;
1004
- MCDCBitmapBytes = Walker.NextMCDCBitmapIdx ;
1002
+ RegionMCDCState-> BitmapBytes = Walker.NextMCDCBitmapIdx ;
1005
1003
FunctionHash = Walker.Hash .finalize ();
1006
1004
}
1007
1005
@@ -1033,11 +1031,10 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl *D) {
1033
1031
1034
1032
std::string CoverageMapping;
1035
1033
llvm::raw_string_ostream OS (CoverageMapping);
1036
- RegionCondIDMap. reset ( new llvm::DenseMap< const Stmt *, unsigned > );
1034
+ RegionMCDCState-> CondIDMap . clear ( );
1037
1035
CoverageMappingGen MappingGen (
1038
1036
*CGM.getCoverageMapping (), CGM.getContext ().getSourceManager (),
1039
- CGM.getLangOpts (), RegionCounterMap.get (), RegionMCDCBitmapMap.get (),
1040
- RegionCondIDMap.get ());
1037
+ CGM.getLangOpts (), RegionCounterMap.get (), RegionMCDCState.get ());
1041
1038
MappingGen.emitCounterMapping (D, OS);
1042
1039
OS.flush ();
1043
1040
@@ -1119,7 +1116,7 @@ bool CodeGenPGO::canEmitMCDCCoverage(const CGBuilderTy &Builder) {
1119
1116
}
1120
1117
1121
1118
void CodeGenPGO::emitMCDCParameters (CGBuilderTy &Builder) {
1122
- if (!canEmitMCDCCoverage (Builder) || !RegionMCDCBitmapMap )
1119
+ if (!canEmitMCDCCoverage (Builder) || !RegionMCDCState )
1123
1120
return ;
1124
1121
1125
1122
auto *I8PtrTy = llvm::PointerType::getUnqual (CGM.getLLVMContext ());
@@ -1129,21 +1126,21 @@ void CodeGenPGO::emitMCDCParameters(CGBuilderTy &Builder) {
1129
1126
// anything.
1130
1127
llvm::Value *Args[3 ] = {llvm::ConstantExpr::getBitCast (FuncNameVar, I8PtrTy),
1131
1128
Builder.getInt64 (FunctionHash),
1132
- Builder.getInt32 (MCDCBitmapBytes )};
1129
+ Builder.getInt32 (RegionMCDCState-> BitmapBytes )};
1133
1130
Builder.CreateCall (
1134
1131
CGM.getIntrinsic (llvm::Intrinsic::instrprof_mcdc_parameters), Args);
1135
1132
}
1136
1133
1137
1134
void CodeGenPGO::emitMCDCTestVectorBitmapUpdate (CGBuilderTy &Builder,
1138
1135
const Expr *S,
1139
1136
Address MCDCCondBitmapAddr) {
1140
- if (!canEmitMCDCCoverage (Builder) || !RegionMCDCBitmapMap )
1137
+ if (!canEmitMCDCCoverage (Builder) || !RegionMCDCState )
1141
1138
return ;
1142
1139
1143
1140
S = S->IgnoreParens ();
1144
1141
1145
- auto ExprMCDCBitmapMapIterator = RegionMCDCBitmapMap-> find (S);
1146
- if (ExprMCDCBitmapMapIterator == RegionMCDCBitmapMap-> end ())
1142
+ auto ExprMCDCBitmapMapIterator = RegionMCDCState-> BitmapMap . find (S);
1143
+ if (ExprMCDCBitmapMapIterator == RegionMCDCState-> BitmapMap . end ())
1147
1144
return ;
1148
1145
1149
1146
// Extract the ID of the global bitmap associated with this expression.
@@ -1157,7 +1154,7 @@ void CodeGenPGO::emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder,
1157
1154
// index represents an executed test vector.
1158
1155
llvm::Value *Args[5 ] = {llvm::ConstantExpr::getBitCast (FuncNameVar, I8PtrTy),
1159
1156
Builder.getInt64 (FunctionHash),
1160
- Builder.getInt32 (MCDCBitmapBytes ),
1157
+ Builder.getInt32 (RegionMCDCState-> BitmapBytes ),
1161
1158
Builder.getInt32 (MCDCTestVectorBitmapID),
1162
1159
MCDCCondBitmapAddr.getPointer ()};
1163
1160
Builder.CreateCall (
@@ -1166,12 +1163,12 @@ void CodeGenPGO::emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder,
1166
1163
1167
1164
void CodeGenPGO::emitMCDCCondBitmapReset (CGBuilderTy &Builder, const Expr *S,
1168
1165
Address MCDCCondBitmapAddr) {
1169
- if (!canEmitMCDCCoverage (Builder) || !RegionMCDCBitmapMap )
1166
+ if (!canEmitMCDCCoverage (Builder) || !RegionMCDCState )
1170
1167
return ;
1171
1168
1172
1169
S = S->IgnoreParens ();
1173
1170
1174
- if (RegionMCDCBitmapMap-> find (S) == RegionMCDCBitmapMap-> end ( ))
1171
+ if (!RegionMCDCState-> BitmapMap . contains (S ))
1175
1172
return ;
1176
1173
1177
1174
// Emit intrinsic that resets a dedicated temporary value on the stack to 0.
@@ -1181,7 +1178,7 @@ void CodeGenPGO::emitMCDCCondBitmapReset(CGBuilderTy &Builder, const Expr *S,
1181
1178
void CodeGenPGO::emitMCDCCondBitmapUpdate (CGBuilderTy &Builder, const Expr *S,
1182
1179
Address MCDCCondBitmapAddr,
1183
1180
llvm::Value *Val) {
1184
- if (!canEmitMCDCCoverage (Builder) || !RegionCondIDMap )
1181
+ if (!canEmitMCDCCoverage (Builder) || !RegionMCDCState )
1185
1182
return ;
1186
1183
1187
1184
// Even though, for simplicity, parentheses and unary logical-NOT operators
@@ -1193,8 +1190,8 @@ void CodeGenPGO::emitMCDCCondBitmapUpdate(CGBuilderTy &Builder, const Expr *S,
1193
1190
// also make debugging a bit easier.
1194
1191
S = CodeGenFunction::stripCond (S);
1195
1192
1196
- auto ExprMCDCConditionIDMapIterator = RegionCondIDMap-> find (S);
1197
- if (ExprMCDCConditionIDMapIterator == RegionCondIDMap-> end ())
1193
+ auto ExprMCDCConditionIDMapIterator = RegionMCDCState-> CondIDMap . find (S);
1194
+ if (ExprMCDCConditionIDMapIterator == RegionMCDCState-> CondIDMap . end ())
1198
1195
return ;
1199
1196
1200
1197
// Extract the ID of the condition we are setting in the bitmap.
0 commit comments