@@ -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
@@ -446,34 +477,11 @@ class MCDCRecordProcessor : NextIDsBuilder, mcdc::TVIdxBuilder {
446
477
// Fill ExecVectors order by False items and True items.
447
478
// ExecVectors is the alias of ExecVectorsByCond[false], so
448
479
// Append ExecVectorsByCond[true] on it.
449
- NumExecVectorsF = ExecVectors.size ();
450
480
auto &ExecVectorsT = ExecVectorsByCond[true ];
451
481
ExecVectors.append (std::make_move_iterator (ExecVectorsT.begin ()),
452
482
std::make_move_iterator (ExecVectorsT.end ()));
453
483
}
454
484
455
- // Find an independence pair for each condition:
456
- // - The condition is true in one test and false in the other.
457
- // - The decision outcome is true one test and false in the other.
458
- // - All other conditions' values must be equal or marked as "don't care".
459
- void findIndependencePairs () {
460
- unsigned NumTVs = ExecVectors.size ();
461
- for (unsigned I = NumExecVectorsF; I < NumTVs; ++I) {
462
- const auto &[A, ACond] = ExecVectors[I];
463
- assert (ACond == MCDCRecord::MCDC_True);
464
- for (unsigned J = 0 ; J < NumExecVectorsF; ++J) {
465
- const auto &[B, BCond] = ExecVectors[J];
466
- assert (BCond == MCDCRecord::MCDC_False);
467
- // If the two vectors differ in exactly one condition, ignoring DontCare
468
- // conditions, we have found an independence pair.
469
- auto AB = A.getDifferences (B);
470
- if (AB.count () == 1 )
471
- IndependencePairs.insert (
472
- {AB.find_first (), std::make_pair (J + 1 , I + 1 )});
473
- }
474
- }
475
- }
476
-
477
485
public:
478
486
// / Process the MC/DC Record in order to produce a result for a boolean
479
487
// / expression. This process includes tracking the conditions that comprise
@@ -509,13 +517,8 @@ class MCDCRecordProcessor : NextIDsBuilder, mcdc::TVIdxBuilder {
509
517
// Using Profile Bitmap from runtime, mark the executed test vectors.
510
518
findExecutedTestVectors ();
511
519
512
- // Compare executed test vectors against each other to find an independence
513
- // pairs for each condition. This processing takes the most time.
514
- findIndependencePairs ();
515
-
516
520
// Record Test vectors, executed vectors, and independence pairs.
517
- return MCDCRecord (Region, std::move (ExecVectors),
518
- std::move (IndependencePairs), std::move (Folded),
521
+ return MCDCRecord (Region, std::move (ExecVectors), std::move (Folded),
519
522
std::move (PosToID), std::move (CondLoc));
520
523
}
521
524
};
0 commit comments