Skip to content

Commit d414f29

Browse files
committed
[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.
1 parent fffa68a commit d414f29

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

clang/lib/CodeGen/CodeGenPGO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
310310
}
311311

312312
// Otherwise, allocate the Decision.
313-
MCDCState.DecisionByStmt[BinOp].BitmapIdx = 0;
313+
MCDCState.DecisionByStmt[BinOp].ID = MCDCState.DecisionByStmt.size();
314314
}
315315
return true;
316316
}

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,10 +2197,8 @@ struct CounterCoverageMappingBuilder
21972197

21982198
// Update the state for CodeGenPGO
21992199
assert(MCDCState.DecisionByStmt.contains(E));
2200-
MCDCState.DecisionByStmt[E] = {
2201-
MCDCState.BitmapBits, // Top
2202-
std::move(Builder.Indices),
2203-
};
2200+
MCDCState.DecisionByStmt[E].update(MCDCState.BitmapBits, // Top
2201+
std::move(Builder.Indices));
22042202

22052203
auto DecisionParams = mcdc::DecisionParameters{
22062204
MCDCState.BitmapBits += NumTVs, // Tail

clang/lib/CodeGen/MCDCState.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "llvm/ADT/DenseMap.h"
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/ProfileData/Coverage/MCDCTypes.h"
19+
#include <cassert>
20+
#include <limits>
1921

2022
namespace clang {
2123
class Stmt;
@@ -30,8 +32,20 @@ struct State {
3032
unsigned BitmapBits = 0;
3133

3234
struct Decision {
35+
using IndicesTy = llvm::SmallVector<std::array<int, 2>>;
36+
static constexpr auto InvalidID = std::numeric_limits<unsigned>::max();
37+
3338
unsigned BitmapIdx;
34-
llvm::SmallVector<std::array<int, 2>> Indices;
39+
IndicesTy Indices;
40+
unsigned ID = InvalidID;
41+
42+
bool isValid() const { return ID != InvalidID; }
43+
44+
void update(unsigned I, IndicesTy &&X) {
45+
assert(ID != InvalidID);
46+
BitmapIdx = I;
47+
Indices = std::move(X);
48+
}
3549
};
3650

3751
llvm::DenseMap<const Stmt *, Decision> DecisionByStmt;

0 commit comments

Comments
 (0)