[llvm] [MC/DC] Introduce `class TestVector` with a pair of `BitVector` (PR #82174)

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 18 19:56:19 PST 2024


================
@@ -380,7 +380,70 @@ struct MCDCRecord {
   /// are effectively ignored.
   enum CondState { MCDC_DontCare = -1, MCDC_False = 0, MCDC_True = 1 };
 
-  using TestVector = llvm::SmallVector<CondState>;
+  /// Emulate SmallVector<CondState> with a pair of BitVector.
+  ///
+  ///          True  False DontCare (Impossible)
+  /// Values:  True  False False    True
+  /// Visited: True  True  False    False
+  class TestVector {
+    BitVector Values;  /// True/False (False when DontCare)
+    BitVector Visited; /// ~DontCare
+
+  public:
+    /// Assume filling DontCare.
+    TestVector(unsigned n, CondState Cond = MCDC_DontCare) {
+      assert(Cond == MCDC_DontCare);
+      Values.resize(n);
+      Visited.resize(n);
+    }
+
+    /// Emulate RHS SmallVector::operator[]
+    MCDCRecord::CondState operator[](int I) const {
+      return (Visited[I] ? (Values[I] ? MCDC_True : MCDC_False)
+                         : MCDC_DontCare);
+    }
+
+    /// Equivalent to buildTestVector's Index.
+    auto getIndex() const { return Values.getData()[0]; }
+
+    /// Emulate LHS SmallVector::operator[].
----------------
ornata wrote:

Comment could be like

> Set the condition at position \p I's CondState to \p Val.

https://github.com/llvm/llvm-project/pull/82174


More information about the llvm-commits mailing list