Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Coverage] Const-ize MCDCRecordProcessor stuff #78918

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,9 @@ class CounterMappingContext {
/// Return an MCDC record that indicates executed test vectors and condition
/// pairs.
Expected<MCDCRecord>
evaluateMCDCRegion(CounterMappingRegion Region, BitVector Bitmap,
ArrayRef<CounterMappingRegion> Branches);
evaluateMCDCRegion(const CounterMappingRegion &Region,
const BitVector &Bitmap,
ArrayRef<const CounterMappingRegion *> Branches);

unsigned getMaxCounterID(const Counter &C) const;
};
Expand Down
32 changes: 17 additions & 15 deletions llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ class MCDCRecordProcessor {
/// Each index of the bitmap corresponds to a possible test vector. An index
/// with a bit value of '1' indicates that the corresponding Test Vector
/// identified by that index was executed.
BitVector &ExecutedTestVectorBitmap;
const BitVector &ExecutedTestVectorBitmap;

/// Decision Region to which the ExecutedTestVectorBitmap applies.
CounterMappingRegion &Region;
const CounterMappingRegion &Region;

/// Array of branch regions corresponding each conditions in the boolean
/// expression.
ArrayRef<CounterMappingRegion> Branches;
ArrayRef<const CounterMappingRegion *> Branches;

/// Total number of conditions in the boolean expression.
unsigned NumConditions;
Expand All @@ -276,8 +276,9 @@ class MCDCRecordProcessor {
MCDCRecord::TestVectors ExecVectors;

public:
MCDCRecordProcessor(BitVector &Bitmap, CounterMappingRegion &Region,
ArrayRef<CounterMappingRegion> Branches)
MCDCRecordProcessor(const BitVector &Bitmap,
const CounterMappingRegion &Region,
ArrayRef<const CounterMappingRegion *> Branches)
: ExecutedTestVectorBitmap(Bitmap), Region(Region), Branches(Branches),
NumConditions(Region.MCDCParams.NumConditions),
Folded(NumConditions, false), IndependencePairs(NumConditions),
Expand Down Expand Up @@ -342,7 +343,7 @@ class MCDCRecordProcessor {

/// Walk the bits in the bitmap. A bit set to '1' indicates that the test
/// vector at the corresponding index was executed during a test run.
void findExecutedTestVectors(BitVector &ExecutedTestVectorBitmap) {
void findExecutedTestVectors(const BitVector &ExecutedTestVectorBitmap) {
for (unsigned Idx = 0; Idx < ExecutedTestVectorBitmap.size(); ++Idx) {
if (ExecutedTestVectorBitmap[Idx] == 0)
continue;
Expand Down Expand Up @@ -445,11 +446,11 @@ class MCDCRecordProcessor {
// visualize where the condition is.
// - Record whether the condition is constant folded so that we exclude it
// from being measured.
for (const auto &B : Branches) {
Map[B.MCDCParams.ID] = &B;
PosToID[I] = B.MCDCParams.ID - 1;
CondLoc[I] = B.startLoc();
Folded[I++] = (B.Count.isZero() && B.FalseCount.isZero());
for (const auto *B : Branches) {
Map[B->MCDCParams.ID] = B;
PosToID[I] = B->MCDCParams.ID - 1;
CondLoc[I] = B->startLoc();
Folded[I++] = (B->Count.isZero() && B->FalseCount.isZero());
}

// Initialize a base test vector as 'DontCare'.
Expand All @@ -473,8 +474,9 @@ class MCDCRecordProcessor {
};

Expected<MCDCRecord> CounterMappingContext::evaluateMCDCRegion(
CounterMappingRegion Region, BitVector ExecutedTestVectorBitmap,
ArrayRef<CounterMappingRegion> Branches) {
const CounterMappingRegion &Region,
const BitVector &ExecutedTestVectorBitmap,
ArrayRef<const CounterMappingRegion *> Branches) {

MCDCRecordProcessor MCDCProcessor(ExecutedTestVectorBitmap, Region, Branches);
return MCDCProcessor.processMCDCRecord();
Expand Down Expand Up @@ -638,7 +640,7 @@ Error CoverageMapping::loadFunctionRecord(

unsigned NumConds = 0;
const CounterMappingRegion *MCDCDecision;
std::vector<CounterMappingRegion> MCDCBranches;
std::vector<const CounterMappingRegion *> MCDCBranches;

FunctionRecord Function(OrigFuncName, Record.Filenames);
for (const auto &Region : Record.MappingRegions) {
Expand Down Expand Up @@ -666,7 +668,7 @@ Error CoverageMapping::loadFunctionRecord(
// correspond to it in a vector, according to the number of conditions
// recorded for the region (tracked by NumConds).
if (NumConds > 0 && Region.Kind == CounterMappingRegion::MCDCBranchRegion) {
MCDCBranches.push_back(Region);
MCDCBranches.push_back(&Region);

// As we move through all of the MCDCBranchRegions that follow the
// MCDCDecisionRegion, decrement NumConds to make sure we account for
Expand Down