@@ -221,6 +221,40 @@ Expected<int64_t> CounterMappingContext::evaluate(const Counter &C) const {
221221 return LastPoppedValue;
222222}
223223
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+
224258mcdc::TVIdxBuilder::TVIdxBuilder (const SmallVectorImpl<ConditionIDs> &NextIDs,
225259 int Offset)
226260 : Indices(NextIDs.size()) {
@@ -375,9 +409,6 @@ class MCDCRecordProcessor : NextIDsBuilder, mcdc::TVIdxBuilder {
375409 // / ExecutedTestVectorBitmap.
376410 MCDCRecord::TestVectors &ExecVectors;
377411
378- // / Number of False items in ExecVectors
379- unsigned NumExecVectorsF;
380-
381412#ifndef NDEBUG
382413 DenseSet<unsigned > TVIdxs;
383414#endif
@@ -447,34 +478,11 @@ class MCDCRecordProcessor : NextIDsBuilder, mcdc::TVIdxBuilder {
447478 // Fill ExecVectors order by False items and True items.
448479 // ExecVectors is the alias of ExecVectorsByCond[false], so
449480 // Append ExecVectorsByCond[true] on it.
450- NumExecVectorsF = ExecVectors.size ();
451481 auto &ExecVectorsT = ExecVectorsByCond[true ];
452482 ExecVectors.append (std::make_move_iterator (ExecVectorsT.begin ()),
453483 std::make_move_iterator (ExecVectorsT.end ()));
454484 }
455485
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-
478486public:
479487 // / Process the MC/DC Record in order to produce a result for a boolean
480488 // / expression. This process includes tracking the conditions that comprise
@@ -510,13 +518,8 @@ class MCDCRecordProcessor : NextIDsBuilder, mcdc::TVIdxBuilder {
510518 // Using Profile Bitmap from runtime, mark the executed test vectors.
511519 findExecutedTestVectors ();
512520
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-
517521 // 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),
520523 std::move (PosToID), std::move (CondLoc));
521524 }
522525};
0 commit comments