[llvm] Introduce mcdc::TVIdxBuilder (LLVM side, NFC) (PR #80676)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 26 22:46:12 PDT 2024


================
@@ -223,9 +223,130 @@ Expected<int64_t> CounterMappingContext::evaluate(const Counter &C) const {
   return LastPoppedValue;
 }
 
+mcdc::TVIdxBuilder::TVIdxBuilder(const SmallVectorImpl<ConditionIDs> &NextIDs,
+                                 int Offset)
+    : Indices(NextIDs.size()) {
+  // Construct Nodes and set up each InCount
+  auto N = NextIDs.size();
+  SmallVector<MCDCNode> Nodes(N);
+  for (unsigned ID = 0; ID < N; ++ID) {
+    for (unsigned C = 0; C < 2; ++C) {
+#ifndef NDEBUG
+      Indices[ID][C] = INT_MIN;
+#endif
+      auto NextID = NextIDs[ID][C];
+      Nodes[ID].NextIDs[C] = NextID;
+      if (NextID >= 0)
+        ++Nodes[NextID].InCount;
+    }
+  }
+
+  // Sort key ordered by <-Width, Ord>
----------------
ZhuUx wrote:

:relaxed: Sorry I found I made a mistake. I previously encountered a example with decision tree:
```mermaid
flowchart TD
C0 -- T --> C1
C1 -- F --> F1
C1 -- T --> C3
C0 -- F --> C2
C2 -- T --> C3
C2 -- F --> F2
C3 -- F --> C4
C3 -- T --> T3
C4 -- T --> T4
C4 -- F --> F4
```
Normal boolean expressions can not generate such decision tree, where either true next of a condition is a next (true or false) of its false next, or false next of a condition is a next of its true next. 

I tried to disable the sort and fixed some cases. So I guessed something was broken by the sort. But that's wrong. The real problem is the way to update cond bitmap, which is specified for previous cond bitmap but is inappropriate for current. This implementation still works for pattern matching, thanks to your excellent efforts!

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


More information about the llvm-commits mailing list