Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenPGO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 2 additions & 4 deletions clang/lib/CodeGen/CoverageMappingGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion clang/lib/CodeGen/MCDCState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use isValid()?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, how expensive is this? Would it make sense for this to be a real error in release builds as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be the real error. I suppose it the expectation here.

I can update this. IIRC, I implemented isValid later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

BitmapIdx = I;
Indices = std::move(X);
}
};

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