@@ -221,6 +221,40 @@ Expected<int64_t> CounterMappingContext::evaluate(const Counter &C) const {
221
221
return LastPoppedValue;
222
222
}
223
223
224
+ // Find an independence pair for each condition:
225
+ // - The condition is true in one test and false in the other.
226
+ // - The decision outcome is true one test and false in the other.
227
+ // - All other conditions' values must be equal or marked as "don't care".
228
+ void MCDCRecord::findIndependencePairs () {
229
+ if (IndependencePairs)
230
+ return ;
231
+
232
+ IndependencePairs.emplace ();
233
+
234
+ unsigned NumTVs = TV.size ();
235
+ // Will be replaced to shorter expr.
236
+ unsigned TVTrueIdx = std::distance (
237
+ TV.begin (),
238
+ std::find_if (TV.begin (), TV.end (),
239
+ [&](auto I) { return (I.second == MCDCRecord::MCDC_True); })
240
+
241
+ );
242
+ for (unsigned I = TVTrueIdx; I < NumTVs; ++I) {
243
+ const auto &[A, ACond] = TV[I];
244
+ assert (ACond == MCDCRecord::MCDC_True);
245
+ for (unsigned J = 0 ; J < TVTrueIdx; ++J) {
246
+ const auto &[B, BCond] = TV[J];
247
+ assert (BCond == MCDCRecord::MCDC_False);
248
+ // If the two vectors differ in exactly one condition, ignoring DontCare
249
+ // conditions, we have found an independence pair.
250
+ auto AB = A.getDifferences (B);
251
+ if (AB.count () == 1 )
252
+ IndependencePairs->insert (
253
+ {AB.find_first (), std::make_pair (J + 1 , I + 1 )});
254
+ }
255
+ }
256
+ }
257
+
224
258
mcdc::TVIdxBuilder::TVIdxBuilder (const SmallVectorImpl<ConditionIDs> &NextIDs,
225
259
int Offset)
226
260
: Indices(NextIDs.size()) {
@@ -375,9 +409,6 @@ class MCDCRecordProcessor : NextIDsBuilder, mcdc::TVIdxBuilder {
375
409
// / ExecutedTestVectorBitmap.
376
410
MCDCRecord::TestVectors &ExecVectors;
377
411
378
- // / Number of False items in ExecVectors
379
- unsigned NumExecVectorsF;
380
-
381
412
#ifndef NDEBUG
382
413
DenseSet<unsigned > TVIdxs;
383
414
#endif
@@ -447,34 +478,11 @@ class MCDCRecordProcessor : NextIDsBuilder, mcdc::TVIdxBuilder {
447
478
// Fill ExecVectors order by False items and True items.
448
479
// ExecVectors is the alias of ExecVectorsByCond[false], so
449
480
// Append ExecVectorsByCond[true] on it.
450
- NumExecVectorsF = ExecVectors.size ();
451
481
auto &ExecVectorsT = ExecVectorsByCond[true ];
452
482
ExecVectors.append (std::make_move_iterator (ExecVectorsT.begin ()),
453
483
std::make_move_iterator (ExecVectorsT.end ()));
454
484
}
455
485
456
- // Find an independence pair for each condition:
457
- // - The condition is true in one test and false in the other.
458
- // - The decision outcome is true one test and false in the other.
459
- // - All other conditions' values must be equal or marked as "don't care".
460
- void findIndependencePairs () {
461
- unsigned NumTVs = ExecVectors.size ();
462
- for (unsigned I = NumExecVectorsF; I < NumTVs; ++I) {
463
- const auto &[A, ACond] = ExecVectors[I];
464
- assert (ACond == MCDCRecord::MCDC_True);
465
- for (unsigned J = 0 ; J < NumExecVectorsF; ++J) {
466
- const auto &[B, BCond] = ExecVectors[J];
467
- assert (BCond == MCDCRecord::MCDC_False);
468
- // If the two vectors differ in exactly one condition, ignoring DontCare
469
- // conditions, we have found an independence pair.
470
- auto AB = A.getDifferences (B);
471
- if (AB.count () == 1 )
472
- IndependencePairs.insert (
473
- {AB.find_first (), std::make_pair (J + 1 , I + 1 )});
474
- }
475
- }
476
- }
477
-
478
486
public:
479
487
// / Process the MC/DC Record in order to produce a result for a boolean
480
488
// / expression. This process includes tracking the conditions that comprise
@@ -510,13 +518,8 @@ class MCDCRecordProcessor : NextIDsBuilder, mcdc::TVIdxBuilder {
510
518
// Using Profile Bitmap from runtime, mark the executed test vectors.
511
519
findExecutedTestVectors ();
512
520
513
- // Compare executed test vectors against each other to find an independence
514
- // pairs for each condition. This processing takes the most time.
515
- findIndependencePairs ();
516
-
517
521
// Record Test vectors, executed vectors, and independence pairs.
518
- return MCDCRecord (Region, std::move (ExecVectors),
519
- std::move (IndependencePairs), std::move (Folded),
522
+ return MCDCRecord (Region, std::move (ExecVectors), std::move (Folded),
520
523
std::move (PosToID), std::move (CondLoc));
521
524
}
522
525
};
0 commit comments