llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-codegen Author: NAKAMURA Takumi (chapuni) <details> <summary>Changes</summary> 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. --- Full diff: https://github.com/llvm/llvm-project/pull/125408.diff 3 Files Affected: - (modified) clang/lib/CodeGen/CodeGenPGO.cpp (+1-1) - (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+2-4) - (modified) clang/lib/CodeGen/MCDCState.h (+15-1) ``````````diff diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 792373839107f0a..0331ff83e633f75 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 f09157771d2b5c0..4dbc0c70e34d60b 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 e0dd28ff90ed124..0b6f5f28235f43a 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; `````````` </details> https://github.com/llvm/llvm-project/pull/125408 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits