Skip to content

[Coverage] MCDCRecordProcessor: Find ExecVectors directly #80816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ class MCDCRecordProcessor {
/// Mapping of calculated MC/DC Independence Pairs for each condition.
MCDCRecord::TVPairMap IndependencePairs;

/// Total number of possible Test Vectors for the boolean expression.
MCDCRecord::TestVectors TestVectors;

/// Actual executed Test Vectors for the boolean expression, based on
/// ExecutedTestVectorBitmap.
MCDCRecord::TestVectors ExecVectors;
Expand All @@ -267,18 +264,20 @@ class MCDCRecordProcessor {
: Bitmap(Bitmap), Region(Region), Branches(Branches),
NumConditions(Region.MCDCParams.NumConditions),
BitmapIdx(Region.MCDCParams.BitmapIdx * CHAR_BIT),
Folded(NumConditions, false), IndependencePairs(NumConditions),
TestVectors((size_t)1 << NumConditions) {}
Folded(NumConditions, false), IndependencePairs(NumConditions) {}

private:
void recordTestVector(MCDCRecord::TestVector &TV, unsigned Index,
MCDCRecord::CondState Result) {
if (!Bitmap[BitmapIdx + Index])
return;

// Copy the completed test vector to the vector of testvectors.
TestVectors[Index] = TV;
ExecVectors.push_back(TV);

// The final value (T,F) is equal to the last non-dontcare state on the
// path (in a short-circuiting system).
TestVectors[Index].push_back(Result);
ExecVectors.back().push_back(Result);
}

// Walk the binary decision diagram and try assigning both false and true to
Expand Down Expand Up @@ -308,13 +307,11 @@ class MCDCRecordProcessor {
/// Walk the bits in the bitmap. A bit set to '1' indicates that the test
/// vector at the corresponding index was executed during a test run.
void findExecutedTestVectors() {
for (unsigned Idx = 0; Idx < (1u << NumConditions); ++Idx) {
assert(BitmapIdx + Idx < Bitmap.size() && "Bitmap overrun");
if (Bitmap[BitmapIdx + Idx] == 0)
continue;
assert(!TestVectors[Idx].empty() && "Test Vector doesn't exist.");
ExecVectors.push_back(TestVectors[Idx]);
}
// Walk the binary decision diagram to enumerate all possible test vectors.
// We start at the root node (ID == 1) with all values being DontCare.
// `Index` encodes the bitmask of true values and is initially 0.
MCDCRecord::TestVector TV(NumConditions, MCDCRecord::MCDC_DontCare);
buildTestVector(TV, 1, 0);
}

// Find an independence pair for each condition:
Expand Down Expand Up @@ -380,12 +377,6 @@ class MCDCRecordProcessor {
Folded[I++] = (B->Count.isZero() && B->FalseCount.isZero());
}

// Walk the binary decision diagram to enumerate all possible test vectors.
// We start at the root node (ID == 1) with all values being DontCare.
// `Index` encodes the bitmask of true values and is initially 0.
MCDCRecord::TestVector TV(NumConditions, MCDCRecord::MCDC_DontCare);
buildTestVector(TV, 1, 0);

// Using Profile Bitmap from runtime, mark the executed test vectors.
findExecutedTestVectors();

Expand Down
28 changes: 14 additions & 14 deletions llvm/test/tools/llvm-cov/mcdc-const.test
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
// CHECKFULLCASE: | C1-Pair: constant folded
// CHECKFULLCASE-NEXT: | C2-Pair: not covered
// CHECKFULLCASE: | MC/DC Coverage for Decision: 0.00%
// CHECKFULLCASE: | 1 { T, C = T }
// CHECKFULLCASE-NEXT: | 2 { F, C = T }
// CHECKFULLCASE: | 1 { F, C = T }
// CHECKFULLCASE-NEXT: | 2 { T, C = T }
// CHECKFULLCASE: | C1-Pair: not covered
// CHECKFULLCASE-NEXT: | C2-Pair: constant folded
// CHECKFULLCASE: | MC/DC Coverage for Decision: 0.00%
Expand Down Expand Up @@ -106,8 +106,8 @@
// CHECKFULLCASE-NEXT: | C2-Pair: not covered
// CHECKFULLCASE-NEXT: | C3-Pair: not covered
// CHECKFULLCASE: | MC/DC Coverage for Decision: 0.00%
// CHECKFULLCASE: | 1 { T, C, - = T }
// CHECKFULLCASE-NEXT: | 2 { F, C, - = T }
// CHECKFULLCASE: | 1 { F, C, - = T }
// CHECKFULLCASE-NEXT: | 2 { T, C, - = T }
// CHECKFULLCASE: | C1-Pair: not covered
// CHECKFULLCASE-NEXT: | C2-Pair: constant folded
// CHECKFULLCASE-NEXT: | C3-Pair: not covered
Expand All @@ -118,8 +118,8 @@
// CHECKFULLCASE-NEXT: | C2-Pair: not covered
// CHECKFULLCASE-NEXT: | C3-Pair: not covered
// CHECKFULLCASE: | MC/DC Coverage for Decision: 0.00%
// CHECKFULLCASE: | 1 { T, C, - = T }
// CHECKFULLCASE-NEXT: | 2 { F, C, T = T }
// CHECKFULLCASE: | 1 { F, C, T = T }
// CHECKFULLCASE-NEXT: | 2 { T, C, - = T }
// CHECKFULLCASE: | C1-Pair: not covered
// CHECKFULLCASE-NEXT: | C2-Pair: constant folded
// CHECKFULLCASE-NEXT: | C3-Pair: not covered
Expand Down Expand Up @@ -151,26 +151,26 @@
// CHECKFULLCASE-NEXT: | C2-Pair: constant folded
// CHECKFULLCASE-NEXT: | C3-Pair: covered: (2,3)
// CHECKFULLCASE: | MC/DC Coverage for Decision: 100.00%
// CHECKFULLCASE: | 1 { T, -, C = T }
// CHECKFULLCASE-NEXT: | 2 { F, T, C = T }
// CHECKFULLCASE: | 1 { F, T, C = T }
// CHECKFULLCASE-NEXT: | 2 { T, -, C = T }
// CHECKFULLCASE: | C1-Pair: not covered
// CHECKFULLCASE-NEXT: | C2-Pair: not covered
// CHECKFULLCASE-NEXT: | C3-Pair: constant folded
// CHECKFULLCASE: | MC/DC Coverage for Decision: 0.00%
// CHECKFULLCASE: | 1 { T, C, - = T }
// CHECKFULLCASE-NEXT: | 2 { F, C, - = T }
// CHECKFULLCASE: | 1 { F, C, - = T }
// CHECKFULLCASE-NEXT: | 2 { T, C, - = T }
// CHECKFULLCASE: | C1-Pair: not covered
// CHECKFULLCASE-NEXT: | C2-Pair: constant folded
// CHECKFULLCASE-NEXT: | C3-Pair: not covered
// CHECKFULLCASE: | MC/DC Coverage for Decision: 0.00%
// CHECKFULLCASE: | 1 { T, -, C = T }
// CHECKFULLCASE-NEXT: | 2 { F, T, C = T }
// CHECKFULLCASE: | 1 { F, T, C = T }
// CHECKFULLCASE-NEXT: | 2 { T, -, C = T }
// CHECKFULLCASE: | C1-Pair: not covered
// CHECKFULLCASE-NEXT: | C2-Pair: not covered
// CHECKFULLCASE-NEXT: | C3-Pair: constant folded
// CHECKFULLCASE: | MC/DC Coverage for Decision: 0.00%
// CHECKFULLCASE: | 1 { T, C, - = T }
// CHECKFULLCASE-NEXT: | 2 { F, C, T = T }
// CHECKFULLCASE: | 1 { F, C, T = T }
// CHECKFULLCASE-NEXT: | 2 { T, C, - = T }
// CHECKFULLCASE: | C1-Pair: not covered
// CHECKFULLCASE-NEXT: | C2-Pair: constant folded
// CHECKFULLCASE-NEXT: | C3-Pair: not covered
Expand Down
16 changes: 8 additions & 8 deletions llvm/test/tools/llvm-cov/mcdc-general.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
// CHECK-NEXT: |
// CHECK-NEXT: | C1, C2, C3, C4 Result
// CHECK-NEXT: | 1 { F, -, F, - = F }
// CHECK-NEXT: | 2 { T, F, F, - = F }
// CHECK-NEXT: | 3 { F, -, T, F = F }
// CHECK-NEXT: | 2 { F, -, T, F = F }
// CHECK-NEXT: | 3 { T, F, F, - = F }
// CHECK-NEXT: | 4 { T, F, T, F = F }
// CHECK-NEXT: | 5 { T, T, -, - = T }
// CHECK-NEXT: | 6 { T, F, T, T = T }
// CHECK-NEXT: | 5 { T, F, T, T = T }
// CHECK-NEXT: | 6 { T, T, -, - = T }
// CHECK-NEXT: |
// CHECK-NEXT: | C1-Pair: covered: (1,5)
// CHECK-NEXT: | C2-Pair: covered: (2,5)
// CHECK-NEXT: | C3-Pair: covered: (2,6)
// CHECK-NEXT: | C4-Pair: covered: (4,6)
// CHECK-NEXT: | C1-Pair: covered: (1,6)
// CHECK-NEXT: | C2-Pair: covered: (3,6)
// CHECK-NEXT: | C3-Pair: covered: (3,5)
// CHECK-NEXT: | C4-Pair: covered: (4,5)
// CHECK-NEXT: | MC/DC Coverage for Decision: 100.00%
// CHECK-NEXT: |
// CHECK-NEXT: ------------------
Expand Down