@@ -223,33 +223,12 @@ Expected<int64_t> CounterMappingContext::evaluate(const Counter &C) const {
223
223
return LastPoppedValue;
224
224
}
225
225
226
- Expected<BitVector> CounterMappingContext::evaluateBitmap (
227
- const CounterMappingRegion *MCDCDecision) const {
228
- unsigned ID = MCDCDecision->MCDCParams .BitmapIdx ;
229
- unsigned NC = MCDCDecision->MCDCParams .NumConditions ;
230
- unsigned SizeInBits = llvm::alignTo (uint64_t (1 ) << NC, CHAR_BIT);
231
- unsigned SizeInBytes = SizeInBits / CHAR_BIT;
232
-
233
- assert (ID + SizeInBytes <= BitmapBytes.size () && " BitmapBytes overrun" );
234
- ArrayRef<uint8_t > Bytes (&BitmapBytes[ID], SizeInBytes);
235
-
236
- // Mask each bitmap byte into the BitVector. Go in reverse so that the
237
- // bitvector can just be shifted over by one byte on each iteration.
238
- BitVector Result (SizeInBits, false );
239
- for (auto Byte = std::rbegin (Bytes); Byte != std::rend (Bytes); ++Byte) {
240
- uint32_t Data = *Byte;
241
- Result <<= CHAR_BIT;
242
- Result.setBitsInMask (&Data, 1 );
243
- }
244
- return Result;
245
- }
246
-
247
226
class MCDCRecordProcessor {
248
227
// / A bitmap representing the executed test vectors for a boolean expression.
249
228
// / Each index of the bitmap corresponds to a possible test vector. An index
250
229
// / with a bit value of '1' indicates that the corresponding Test Vector
251
230
// / identified by that index was executed.
252
- const BitVector &ExecutedTestVectorBitmap ;
231
+ const BitVector &Bitmap ;
253
232
254
233
// / Decision Region to which the ExecutedTestVectorBitmap applies.
255
234
const CounterMappingRegion &Region;
@@ -261,6 +240,8 @@ class MCDCRecordProcessor {
261
240
// / Total number of conditions in the boolean expression.
262
241
unsigned NumConditions;
263
242
243
+ unsigned BitmapIdx;
244
+
264
245
// / Mapping of a condition ID to its corresponding branch region.
265
246
llvm::DenseMap<unsigned , const CounterMappingRegion *> Map;
266
247
@@ -281,8 +262,9 @@ class MCDCRecordProcessor {
281
262
MCDCRecordProcessor (const BitVector &Bitmap,
282
263
const CounterMappingRegion &Region,
283
264
ArrayRef<const CounterMappingRegion *> Branches)
284
- : ExecutedTestVectorBitmap (Bitmap), Region(Region), Branches(Branches),
265
+ : Bitmap (Bitmap), Region(Region), Branches(Branches),
285
266
NumConditions (Region.MCDCParams.NumConditions),
267
+ BitmapIdx(Region.MCDCParams.BitmapIdx * CHAR_BIT),
286
268
Folded(NumConditions, false ), IndependencePairs(NumConditions),
287
269
TestVectors((size_t )1 << NumConditions) {}
288
270
@@ -323,9 +305,10 @@ class MCDCRecordProcessor {
323
305
324
306
// / Walk the bits in the bitmap. A bit set to '1' indicates that the test
325
307
// / vector at the corresponding index was executed during a test run.
326
- void findExecutedTestVectors (const BitVector &ExecutedTestVectorBitmap) {
327
- for (unsigned Idx = 0 ; Idx < ExecutedTestVectorBitmap.size (); ++Idx) {
328
- if (ExecutedTestVectorBitmap[Idx] == 0 )
308
+ void findExecutedTestVectors () {
309
+ for (unsigned Idx = 0 ; Idx < (1u << NumConditions); ++Idx) {
310
+ assert (BitmapIdx + Idx < Bitmap.size () && " Bitmap overrun" );
311
+ if (Bitmap[BitmapIdx + Idx] == 0 )
329
312
continue ;
330
313
assert (!TestVectors[Idx].empty () && " Test Vector doesn't exist." );
331
314
ExecVectors.push_back (TestVectors[Idx]);
@@ -402,7 +385,7 @@ class MCDCRecordProcessor {
402
385
buildTestVector (TV, 1 , 0 );
403
386
404
387
// Using Profile Bitmap from runtime, mark the executed test vectors.
405
- findExecutedTestVectors (ExecutedTestVectorBitmap );
388
+ findExecutedTestVectors ();
406
389
407
390
// Compare executed test vectors against each other to find an independence
408
391
// pairs for each condition. This processing takes the most time.
@@ -417,10 +400,9 @@ class MCDCRecordProcessor {
417
400
418
401
Expected<MCDCRecord> CounterMappingContext::evaluateMCDCRegion (
419
402
const CounterMappingRegion &Region,
420
- const BitVector &ExecutedTestVectorBitmap,
421
403
ArrayRef<const CounterMappingRegion *> Branches) {
422
404
423
- MCDCRecordProcessor MCDCProcessor (ExecutedTestVectorBitmap , Region, Branches);
405
+ MCDCRecordProcessor MCDCProcessor (Bitmap , Region, Branches);
424
406
return MCDCProcessor.processMCDCRecord ();
425
407
}
426
408
@@ -506,6 +488,7 @@ static unsigned getMaxCounterID(const CounterMappingContext &Ctx,
506
488
return MaxCounterID;
507
489
}
508
490
491
+ // / Returns the bit count
509
492
static unsigned getMaxBitmapSize (const CounterMappingContext &Ctx,
510
493
const CoverageMappingRecord &Record) {
511
494
unsigned MaxBitmapID = 0 ;
@@ -521,7 +504,7 @@ static unsigned getMaxBitmapSize(const CounterMappingContext &Ctx,
521
504
}
522
505
}
523
506
unsigned SizeInBits = llvm::alignTo (uint64_t (1 ) << NumConditions, CHAR_BIT);
524
- return MaxBitmapID + (SizeInBits / CHAR_BIT) ;
507
+ return MaxBitmapID * CHAR_BIT + SizeInBits ;
525
508
}
526
509
527
510
namespace {
@@ -708,9 +691,9 @@ Error CoverageMapping::loadFunctionRecord(
708
691
}
709
692
Ctx.setCounts (Counts);
710
693
711
- std::vector< uint8_t > BitmapBytes ;
712
- if (Error E = ProfileReader.getFunctionBitmapBytes (
713
- Record. FunctionName , Record.FunctionHash , BitmapBytes )) {
694
+ BitVector Bitmap ;
695
+ if (Error E = ProfileReader.getFunctionBitmap (Record. FunctionName ,
696
+ Record.FunctionHash , Bitmap )) {
714
697
instrprof_error IPE = std::get<0 >(InstrProfError::take (std::move (E)));
715
698
if (IPE == instrprof_error::hash_mismatch) {
716
699
FuncHashMismatches.emplace_back (std::string (Record.FunctionName ),
@@ -719,9 +702,9 @@ Error CoverageMapping::loadFunctionRecord(
719
702
}
720
703
if (IPE != instrprof_error::unknown_function)
721
704
return make_error<InstrProfError>(IPE);
722
- BitmapBytes. assign (getMaxBitmapSize (Ctx, Record) + 1 , 0 );
705
+ Bitmap = BitVector (getMaxBitmapSize (Ctx, Record));
723
706
}
724
- Ctx.setBitmapBytes (BitmapBytes );
707
+ Ctx.setBitmap ( std::move (Bitmap) );
725
708
726
709
assert (!Record.MappingRegions .empty () && " Function has no regions" );
727
710
@@ -772,23 +755,11 @@ Error CoverageMapping::loadFunctionRecord(
772
755
auto MCDCDecision = Result->first ;
773
756
auto &MCDCBranches = Result->second ;
774
757
775
- // Evaluating the test vector bitmap for the decision region entails
776
- // calculating precisely what bits are pertinent to this region alone.
777
- // This is calculated based on the recorded offset into the global
778
- // profile bitmap; the length is calculated based on the recorded
779
- // number of conditions.
780
- Expected<BitVector> ExecutedTestVectorBitmap =
781
- Ctx.evaluateBitmap (MCDCDecision);
782
- if (auto E = ExecutedTestVectorBitmap.takeError ()) {
783
- consumeError (std::move (E));
784
- return Error::success ();
785
- }
786
-
787
758
// Since the bitmap identifies the executed test vectors for an MC/DC
788
759
// DecisionRegion, all of the information is now available to process.
789
760
// This is where the bulk of the MC/DC progressing takes place.
790
- Expected<MCDCRecord> Record = Ctx. evaluateMCDCRegion (
791
- *MCDCDecision, *ExecutedTestVectorBitmap , MCDCBranches);
761
+ Expected<MCDCRecord> Record =
762
+ Ctx. evaluateMCDCRegion ( *MCDCDecision, MCDCBranches);
792
763
if (auto E = Record.takeError ()) {
793
764
consumeError (std::move (E));
794
765
return Error::success ();
0 commit comments