[llvm] Implement MCDCTVIdxBuilder (LLVM side) (PR #80676)
Alan Phipps via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 8 16:05:48 PST 2024
================
@@ -283,35 +408,38 @@ class MCDCRecordProcessor {
// Walk the binary decision diagram and try assigning both false and true to
// each node. When a terminal node (ID == 0) is reached, fill in the value in
// the truth table.
- void buildTestVector(MCDCRecord::TestVector &TV, unsigned ID,
+ void buildTestVector(MCDCRecord::TestVector &TV, int ID, int TVIdx,
unsigned Index) {
- const CounterMappingRegion *Branch = Map[ID];
-
- TV[ID - 1] = MCDCRecord::MCDC_False;
- if (Branch->MCDCParams.FalseID > 0)
- buildTestVector(TV, Branch->MCDCParams.FalseID, Index);
- else
- recordTestVector(TV, Index, MCDCRecord::MCDC_False);
-
- Index |= 1 << (ID - 1);
- TV[ID - 1] = MCDCRecord::MCDC_True;
- if (Branch->MCDCParams.TrueID > 0)
- buildTestVector(TV, Branch->MCDCParams.TrueID, Index);
- else
- recordTestVector(TV, Index, MCDCRecord::MCDC_True);
+ const auto &Node = Nodes[ID];
+
+ for (unsigned I = 0; I < 2; ++I) {
+ auto MCDCCond = (I ? MCDCRecord::MCDC_True : MCDCRecord::MCDC_False);
+ const auto &Cond = Node.Conds[I];
+ auto NextID = Cond.ID;
+ Index |= I << ID;
+ TV[ID] = MCDCCond;
+ if (NextID >= 0) {
+ buildTestVector(TV, NextID, TVIdx + Cond.Idx, Index);
+ } else {
+ assert(TVIdx < Node.Width);
+ recordTestVector(TV, Cond.Idx + TVIdx, Index, MCDCCond);
+ }
+ }
// Reset back to DontCare.
- TV[ID - 1] = MCDCRecord::MCDC_DontCare;
+ TV[ID] = MCDCRecord::MCDC_DontCare;
}
/// 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() {
// Walk the binary decision diagram to enumerate all possible test vectors.
- // We start at the root node (ID == 1) with all values being DontCare.
+ // We start at the root node (ID == 0) with all values being DontCare.
+ // `TVIdx` starts with 0 and is in the traversal.
// `Index` encodes the bitmask of true values and is initially 0.
MCDCRecord::TestVector TV(NumConditions, MCDCRecord::MCDC_DontCare);
- buildTestVector(TV, 1, 0);
+ buildTestVector(TV, 0, 0, 0);
+ assert(TVIdxs.size() == NumTestVectors && "TVIdxs wasn't fulfilled");
----------------
evodius96 wrote:
Good assert
https://github.com/llvm/llvm-project/pull/80676
More information about the llvm-commits
mailing list