https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/125408

>From d414f29ed8732c77fdcd05cc3b066e9ee0d9de07 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4ci...@gmail.com>
Date: Sun, 2 Feb 2025 21:59:33 +0900
Subject: [PATCH 1/2] [MC/DC] Refactor MCDC::State::Decision. NFC.

Introduce `ID` and `InvalidID`. Then `DecisionByStmt` can have three
states.

* Not assigned if the Stmt(Expr) doesn't exist.
* When `DecisionByStmt[Expr]` exists:
  * Invalid and should be ignored if `ID == Invalid`.
  * Valid if `ID != Invalid`. Other member will be filled in the
    Mapper.
---
 clang/lib/CodeGen/CodeGenPGO.cpp         |  2 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp |  6 ++----
 clang/lib/CodeGen/MCDCState.h            | 16 +++++++++++++++-
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 792373839107f..0331ff83e633f 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -310,7 +310,7 @@ struct MapRegionCounters : public 
RecursiveASTVisitor<MapRegionCounters> {
           }
 
           // Otherwise, allocate the Decision.
-          MCDCState.DecisionByStmt[BinOp].BitmapIdx = 0;
+          MCDCState.DecisionByStmt[BinOp].ID = MCDCState.DecisionByStmt.size();
         }
         return true;
       }
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index f09157771d2b5..4dbc0c70e34d6 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2197,10 +2197,8 @@ struct CounterCoverageMappingBuilder
 
     // Update the state for CodeGenPGO
     assert(MCDCState.DecisionByStmt.contains(E));
-    MCDCState.DecisionByStmt[E] = {
-        MCDCState.BitmapBits, // Top
-        std::move(Builder.Indices),
-    };
+    MCDCState.DecisionByStmt[E].update(MCDCState.BitmapBits, // Top
+                                       std::move(Builder.Indices));
 
     auto DecisionParams = mcdc::DecisionParameters{
         MCDCState.BitmapBits += NumTVs, // Tail
diff --git a/clang/lib/CodeGen/MCDCState.h b/clang/lib/CodeGen/MCDCState.h
index e0dd28ff90ed1..0b6f5f28235f4 100644
--- a/clang/lib/CodeGen/MCDCState.h
+++ b/clang/lib/CodeGen/MCDCState.h
@@ -16,6 +16,8 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ProfileData/Coverage/MCDCTypes.h"
+#include <cassert>
+#include <limits>
 
 namespace clang {
 class Stmt;
@@ -30,8 +32,20 @@ struct State {
   unsigned BitmapBits = 0;
 
   struct Decision {
+    using IndicesTy = llvm::SmallVector<std::array<int, 2>>;
+    static constexpr auto InvalidID = std::numeric_limits<unsigned>::max();
+
     unsigned BitmapIdx;
-    llvm::SmallVector<std::array<int, 2>> Indices;
+    IndicesTy Indices;
+    unsigned ID = InvalidID;
+
+    bool isValid() const { return ID != InvalidID; }
+
+    void update(unsigned I, IndicesTy &&X) {
+      assert(ID != InvalidID);
+      BitmapIdx = I;
+      Indices = std::move(X);
+    }
   };
 
   llvm::DenseMap<const Stmt *, Decision> DecisionByStmt;

>From 079bf69ee66b3cda8206f790185a8bb325ec7064 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4ci...@gmail.com>
Date: Sat, 1 Mar 2025 15:37:35 +0900
Subject: [PATCH 2/2] isValid()

---
 clang/lib/CodeGen/MCDCState.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/MCDCState.h b/clang/lib/CodeGen/MCDCState.h
index 0b6f5f28235f4..4b89ddd12d672 100644
--- a/clang/lib/CodeGen/MCDCState.h
+++ b/clang/lib/CodeGen/MCDCState.h
@@ -42,7 +42,7 @@ struct State {
     bool isValid() const { return ID != InvalidID; }
 
     void update(unsigned I, IndicesTy &&X) {
-      assert(ID != InvalidID);
+      assert(isValid());
       BitmapIdx = I;
       Indices = std::move(X);
     }

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to