[llvm] [Coverage] MCDCRecordProcessor: Find `ExecVectors` directly (PR #80816)
NAKAMURA Takumi via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 6 02:12:43 PST 2024
https://github.com/chapuni created https://github.com/llvm/llvm-project/pull/80816
Deprecate `TestVectors`, since no one uses it.
This affects the output order of ExecVectors.
The current impl emits sorted by binary value of ExecVector. This impl emits along the traversal of `buildTestVector()`.
>From 8c777ebbea6f5d005de2112b88eceec9b5eeeadd Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Tue, 6 Feb 2024 17:06:11 +0900
Subject: [PATCH] [Coverage] MCDCRecordProcessor: Find `ExecVectors` directly
Deprecate `TestVectors`, since no one uses it.
This affects the output order of ExecVectors.
The current impl emits sorted by binary value of ExecVector.
This impl emits along the traversal of `buildTestVector()`.
---
.../ProfileData/Coverage/CoverageMapping.cpp | 31 +++++++------------
llvm/test/tools/llvm-cov/mcdc-const.test | 28 ++++++++---------
llvm/test/tools/llvm-cov/mcdc-general.test | 16 +++++-----
3 files changed, 33 insertions(+), 42 deletions(-)
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index 6b189c3146328..eb0996e33b70d 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -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;
@@ -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
@@ -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:
@@ -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();
diff --git a/llvm/test/tools/llvm-cov/mcdc-const.test b/llvm/test/tools/llvm-cov/mcdc-const.test
index 0b2c9c98d5355..5424625cf6a6b 100644
--- a/llvm/test/tools/llvm-cov/mcdc-const.test
+++ b/llvm/test/tools/llvm-cov/mcdc-const.test
@@ -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%
@@ -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
@@ -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
@@ -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
diff --git a/llvm/test/tools/llvm-cov/mcdc-general.test b/llvm/test/tools/llvm-cov/mcdc-general.test
index 753036bedaf17..4b59ce59d638e 100644
--- a/llvm/test/tools/llvm-cov/mcdc-general.test
+++ b/llvm/test/tools/llvm-cov/mcdc-general.test
@@ -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: ------------------
More information about the llvm-commits
mailing list