[clang] a17a3e9 - [MC/DC] Refactor: Make `MCDCParams` as `std::variant` (#81227)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 13 05:43:50 PST 2024
Author: NAKAMURA Takumi
Date: 2024-02-13T22:43:46+09:00
New Revision: a17a3e9d9a6b4baefd96e19ee5e8ce04cead8ab5
URL: https://github.com/llvm/llvm-project/commit/a17a3e9d9a6b4baefd96e19ee5e8ce04cead8ab5
DIFF: https://github.com/llvm/llvm-project/commit/a17a3e9d9a6b4baefd96e19ee5e8ce04cead8ab5.diff
LOG: [MC/DC] Refactor: Make `MCDCParams` as `std::variant` (#81227)
Introduce `mcdc::DecisionParameters` and `mcdc::BranchParameters` and make
sure them not initialized as zero.
FIXME: Could we make `CoverageMappingRegion` as a smart tagged union?
Added:
Modified:
clang/lib/CodeGen/CoverageMappingGen.cpp
llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
llvm/unittests/ProfileData/CoverageMappingTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 5060b5b2860fdb..93fe76eb9903e9 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -182,7 +182,17 @@ class SourceMappingRegion {
bool isBranch() const { return FalseCount.has_value(); }
- bool isMCDCDecision() const { return MCDCParams.NumConditions != 0; }
+ bool isMCDCDecision() const {
+ const auto *DecisionParams =
+ std::get_if<mcdc::DecisionParameters>(&MCDCParams);
+ assert(!DecisionParams || DecisionParams->NumConditions > 0);
+ return DecisionParams;
+ }
+
+ const auto &getMCDCDecisionParams() const {
+ return CounterMappingRegion::getParams<const mcdc::DecisionParameters>(
+ MCDCParams);
+ }
const mcdc::Parameters &getMCDCParams() const { return MCDCParams; }
};
@@ -480,13 +490,13 @@ class CoverageMappingBuilder {
SR.ColumnEnd));
} else if (Region.isBranch()) {
MappingRegions.push_back(CounterMappingRegion::makeBranchRegion(
- Region.getCounter(), Region.getFalseCounter(),
- Region.getMCDCParams(), *CovFileID, SR.LineStart, SR.ColumnStart,
- SR.LineEnd, SR.ColumnEnd));
+ Region.getCounter(), Region.getFalseCounter(), *CovFileID,
+ SR.LineStart, SR.ColumnStart, SR.LineEnd, SR.ColumnEnd,
+ Region.getMCDCParams()));
} else if (Region.isMCDCDecision()) {
MappingRegions.push_back(CounterMappingRegion::makeDecisionRegion(
- Region.getMCDCParams(), *CovFileID, SR.LineStart, SR.ColumnStart,
- SR.LineEnd, SR.ColumnEnd));
+ Region.getMCDCDecisionParams(), *CovFileID, SR.LineStart,
+ SR.ColumnStart, SR.LineEnd, SR.ColumnEnd));
} else {
MappingRegions.push_back(CounterMappingRegion::makeRegion(
Region.getCounter(), *CovFileID, SR.LineStart, SR.ColumnStart,
@@ -863,8 +873,7 @@ struct CounterCoverageMappingBuilder
std::optional<SourceLocation> StartLoc = std::nullopt,
std::optional<SourceLocation> EndLoc = std::nullopt,
std::optional<Counter> FalseCount = std::nullopt,
- mcdc::ConditionID ID = 0, mcdc::ConditionID TrueID = 0,
- mcdc::ConditionID FalseID = 0) {
+ const mcdc::Parameters &BranchParams = std::monostate()) {
if (StartLoc && !FalseCount) {
MostRecentLocation = *StartLoc;
@@ -883,9 +892,7 @@ struct CounterCoverageMappingBuilder
StartLoc = std::nullopt;
if (EndLoc && EndLoc->isInvalid())
EndLoc = std::nullopt;
- RegionStack.emplace_back(Count, FalseCount,
- mcdc::Parameters{0, 0, ID, TrueID, FalseID},
- StartLoc, EndLoc);
+ RegionStack.emplace_back(Count, FalseCount, BranchParams, StartLoc, EndLoc);
return RegionStack.size() - 1;
}
@@ -894,8 +901,8 @@ struct CounterCoverageMappingBuilder
std::optional<SourceLocation> StartLoc = std::nullopt,
std::optional<SourceLocation> EndLoc = std::nullopt) {
- RegionStack.emplace_back(mcdc::Parameters{BitmapIdx, Conditions}, StartLoc,
- EndLoc);
+ RegionStack.emplace_back(mcdc::DecisionParameters{BitmapIdx, Conditions},
+ StartLoc, EndLoc);
return RegionStack.size() - 1;
}
@@ -1040,9 +1047,11 @@ struct CounterCoverageMappingBuilder
// function's SourceRegions) because it doesn't apply to any other source
// code other than the Condition.
if (CodeGenFunction::isInstrumentedCondition(C)) {
+ mcdc::Parameters BranchParams;
mcdc::ConditionID ID = MCDCBuilder.getCondID(C);
- mcdc::ConditionID TrueID = IDPair.TrueID;
- mcdc::ConditionID FalseID = IDPair.FalseID;
+ if (ID > 0)
+ BranchParams =
+ mcdc::BranchParameters{ID, IDPair.TrueID, IDPair.FalseID};
// If a condition can fold to true or false, the corresponding branch
// will be removed. Create a region with both counters hard-coded to
@@ -1052,11 +1061,11 @@ struct CounterCoverageMappingBuilder
// CodeGenFunction.c always returns false, but that is very heavy-handed.
if (ConditionFoldsToBool(C))
popRegions(pushRegion(Counter::getZero(), getStart(C), getEnd(C),
- Counter::getZero(), ID, TrueID, FalseID));
+ Counter::getZero(), BranchParams));
else
// Otherwise, create a region with the True counter and False counter.
- popRegions(pushRegion(TrueCnt, getStart(C), getEnd(C), FalseCnt, ID,
- TrueID, FalseID));
+ popRegions(pushRegion(TrueCnt, getStart(C), getEnd(C), FalseCnt,
+ BranchParams));
}
}
@@ -1147,12 +1156,9 @@ struct CounterCoverageMappingBuilder
// we've seen this region.
if (StartLocs.insert(Loc).second) {
if (I.isBranch())
- SourceRegions.emplace_back(
- I.getCounter(), I.getFalseCounter(),
- mcdc::Parameters{0, 0, I.getMCDCParams().ID,
- I.getMCDCParams().TrueID,
- I.getMCDCParams().FalseID},
- Loc, getEndOfFileOrMacro(Loc), I.isBranch());
+ SourceRegions.emplace_back(I.getCounter(), I.getFalseCounter(),
+ I.getMCDCParams(), Loc,
+ getEndOfFileOrMacro(Loc), I.isBranch());
else
SourceRegions.emplace_back(I.getCounter(), Loc,
getEndOfFileOrMacro(Loc));
@@ -2118,9 +2124,10 @@ static void dump(llvm::raw_ostream &OS, StringRef FunctionName,
OS << "File " << R.FileID << ", " << R.LineStart << ":" << R.ColumnStart
<< " -> " << R.LineEnd << ":" << R.ColumnEnd << " = ";
- if (R.Kind == CounterMappingRegion::MCDCDecisionRegion) {
- OS << "M:" << R.MCDCParams.BitmapIdx;
- OS << ", C:" << R.MCDCParams.NumConditions;
+ if (const auto *DecisionParams =
+ std::get_if<mcdc::DecisionParameters>(&R.MCDCParams)) {
+ OS << "M:" << DecisionParams->BitmapIdx;
+ OS << ", C:" << DecisionParams->NumConditions;
} else {
Ctx.dump(R.Count, OS);
@@ -2131,9 +2138,10 @@ static void dump(llvm::raw_ostream &OS, StringRef FunctionName,
}
}
- if (R.Kind == CounterMappingRegion::MCDCBranchRegion) {
- OS << " [" << R.MCDCParams.ID << "," << R.MCDCParams.TrueID;
- OS << "," << R.MCDCParams.FalseID << "] ";
+ if (const auto *BranchParams =
+ std::get_if<mcdc::BranchParameters>(&R.MCDCParams)) {
+ OS << " [" << BranchParams->ID << "," << BranchParams->TrueID;
+ OS << "," << BranchParams->FalseID << "] ";
}
if (R.Kind == CounterMappingRegion::ExpansionRegion)
diff --git a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
index e877571779faf4..c6fbdb512b807e 100644
--- a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
+++ b/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
@@ -259,6 +259,24 @@ struct CounterMappingRegion {
/// Parameters used for Modified Condition/Decision Coverage
mcdc::Parameters MCDCParams;
+ template <class MaybeConstInnerParameters, class MaybeConstMCDCParameters>
+ static auto &getParams(MaybeConstMCDCParameters &MCDCParams) {
+ using InnerParameters =
+ typename std::remove_const<MaybeConstInnerParameters>::type;
+ MaybeConstInnerParameters *Params =
+ std::get_if<InnerParameters>(&MCDCParams);
+ assert(Params && "InnerParameters unavailable");
+ return *Params;
+ }
+
+ const auto &getDecisionParams() const {
+ return getParams<const mcdc::DecisionParameters>(MCDCParams);
+ }
+
+ const auto &getBranchParams() const {
+ return getParams<const mcdc::BranchParameters>(MCDCParams);
+ }
+
unsigned FileID = 0;
unsigned ExpandedFileID = 0;
unsigned LineStart, ColumnStart, LineEnd, ColumnEnd;
@@ -272,19 +290,20 @@ struct CounterMappingRegion {
LineStart(LineStart), ColumnStart(ColumnStart), LineEnd(LineEnd),
ColumnEnd(ColumnEnd), Kind(Kind) {}
- CounterMappingRegion(Counter Count, Counter FalseCount,
- mcdc::Parameters MCDCParams, unsigned FileID,
+ CounterMappingRegion(Counter Count, Counter FalseCount, unsigned FileID,
unsigned ExpandedFileID, unsigned LineStart,
unsigned ColumnStart, unsigned LineEnd,
- unsigned ColumnEnd, RegionKind Kind)
+ unsigned ColumnEnd, RegionKind Kind,
+ const mcdc::Parameters &MCDCParams = std::monostate())
: Count(Count), FalseCount(FalseCount), MCDCParams(MCDCParams),
FileID(FileID), ExpandedFileID(ExpandedFileID), LineStart(LineStart),
ColumnStart(ColumnStart), LineEnd(LineEnd), ColumnEnd(ColumnEnd),
Kind(Kind) {}
- CounterMappingRegion(mcdc::Parameters MCDCParams, unsigned FileID,
- unsigned LineStart, unsigned ColumnStart,
- unsigned LineEnd, unsigned ColumnEnd, RegionKind Kind)
+ CounterMappingRegion(const mcdc::DecisionParameters &MCDCParams,
+ unsigned FileID, unsigned LineStart,
+ unsigned ColumnStart, unsigned LineEnd,
+ unsigned ColumnEnd, RegionKind Kind)
: MCDCParams(MCDCParams), FileID(FileID), LineStart(LineStart),
ColumnStart(ColumnStart), LineEnd(LineEnd), ColumnEnd(ColumnEnd),
Kind(Kind) {}
@@ -321,27 +340,20 @@ struct CounterMappingRegion {
static CounterMappingRegion
makeBranchRegion(Counter Count, Counter FalseCount, unsigned FileID,
unsigned LineStart, unsigned ColumnStart, unsigned LineEnd,
- unsigned ColumnEnd) {
- return CounterMappingRegion(Count, FalseCount, mcdc::Parameters(), FileID,
- 0, LineStart, ColumnStart, LineEnd, ColumnEnd,
- BranchRegion);
- }
-
- static CounterMappingRegion
- makeBranchRegion(Counter Count, Counter FalseCount,
- mcdc::Parameters MCDCParams, unsigned FileID,
- unsigned LineStart, unsigned ColumnStart, unsigned LineEnd,
- unsigned ColumnEnd) {
- return CounterMappingRegion(Count, FalseCount, MCDCParams, FileID, 0,
- LineStart, ColumnStart, LineEnd, ColumnEnd,
- MCDCParams.ID == 0 ? BranchRegion
- : MCDCBranchRegion);
+ unsigned ColumnEnd,
+ const mcdc::Parameters &MCDCParams = std::monostate()) {
+ return CounterMappingRegion(
+ Count, FalseCount, FileID, 0, LineStart, ColumnStart, LineEnd,
+ ColumnEnd,
+ (std::get_if<mcdc::BranchParameters>(&MCDCParams) ? MCDCBranchRegion
+ : BranchRegion),
+ MCDCParams);
}
static CounterMappingRegion
- makeDecisionRegion(mcdc::Parameters MCDCParams, unsigned FileID,
- unsigned LineStart, unsigned ColumnStart, unsigned LineEnd,
- unsigned ColumnEnd) {
+ makeDecisionRegion(const mcdc::DecisionParameters &MCDCParams,
+ unsigned FileID, unsigned LineStart, unsigned ColumnStart,
+ unsigned LineEnd, unsigned ColumnEnd) {
return CounterMappingRegion(MCDCParams, FileID, LineStart, ColumnStart,
LineEnd, ColumnEnd, MCDCDecisionRegion);
}
@@ -406,9 +418,10 @@ struct MCDCRecord {
CounterMappingRegion getDecisionRegion() const { return Region; }
unsigned getNumConditions() const {
- assert(Region.MCDCParams.NumConditions != 0 &&
+ unsigned NumConditions = Region.getDecisionParams().NumConditions;
+ assert(NumConditions != 0 &&
"In MC/DC, NumConditions should never be zero!");
- return Region.MCDCParams.NumConditions;
+ return NumConditions;
}
unsigned getNumTestVectors() const { return TV.size(); }
bool isCondFolded(unsigned Condition) const { return Folded[Condition]; }
diff --git a/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h b/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
index 365c899b6eb520..b4e011c7024729 100644
--- a/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
+++ b/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
@@ -13,24 +13,35 @@
#ifndef LLVM_PROFILEDATA_COVERAGE_MCDCTYPES_H
#define LLVM_PROFILEDATA_COVERAGE_MCDCTYPES_H
+#include <variant>
+
namespace llvm::coverage::mcdc {
/// The ID for MCDCBranch.
using ConditionID = unsigned int;
-/// MC/DC-specifig parameters
-struct Parameters {
+struct DecisionParameters {
/// Byte Index of Bitmap Coverage Object for a Decision Region.
- unsigned BitmapIdx = 0;
+ unsigned BitmapIdx;
/// Number of Conditions used for a Decision Region.
- unsigned NumConditions = 0;
+ unsigned NumConditions;
+
+ DecisionParameters() = delete;
+};
+struct BranchParameters {
/// IDs used to represent a branch region and other branch regions
/// evaluated based on True and False branches.
- ConditionID ID = 0, TrueID = 0, FalseID = 0;
+ ConditionID ID, TrueID, FalseID;
+
+ BranchParameters() = delete;
};
+/// The type of MC/DC-specific parameters.
+using Parameters =
+ std::variant<std::monostate, DecisionParameters, BranchParameters>;
+
} // namespace llvm::coverage::mcdc
#endif // LLVM_PROFILEDATA_COVERAGE_MCDCTYPES_H
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index 0c65ab8ce0dd45..80b80f7a26f454 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -234,6 +234,7 @@ class MCDCRecordProcessor {
/// Decision Region to which the ExecutedTestVectorBitmap applies.
const CounterMappingRegion &Region;
+ const mcdc::DecisionParameters &DecisionParams;
/// Array of branch regions corresponding each conditions in the boolean
/// expression.
@@ -244,8 +245,8 @@ class MCDCRecordProcessor {
unsigned BitmapIdx;
- /// Mapping of a condition ID to its corresponding branch region.
- llvm::DenseMap<unsigned, const CounterMappingRegion *> Map;
+ /// Mapping of a condition ID to its corresponding branch params.
+ llvm::DenseMap<unsigned, const mcdc::BranchParameters *> BranchParamsMap;
/// Vector used to track whether a condition is constant folded.
MCDCRecord::BoolVector Folded;
@@ -261,9 +262,10 @@ class MCDCRecordProcessor {
MCDCRecordProcessor(const BitVector &Bitmap,
const CounterMappingRegion &Region,
ArrayRef<const CounterMappingRegion *> Branches)
- : Bitmap(Bitmap), Region(Region), Branches(Branches),
- NumConditions(Region.MCDCParams.NumConditions),
- BitmapIdx(Region.MCDCParams.BitmapIdx * CHAR_BIT),
+ : Bitmap(Bitmap), Region(Region),
+ DecisionParams(Region.getDecisionParams()), Branches(Branches),
+ NumConditions(DecisionParams.NumConditions),
+ BitmapIdx(DecisionParams.BitmapIdx * CHAR_BIT),
Folded(NumConditions, false), IndependencePairs(NumConditions) {}
private:
@@ -285,18 +287,18 @@ class MCDCRecordProcessor {
// the truth table.
void buildTestVector(MCDCRecord::TestVector &TV, unsigned ID,
unsigned Index) {
- const CounterMappingRegion *Branch = Map[ID];
+ auto [UnusedID, TrueID, FalseID] = *BranchParamsMap[ID];
TV[ID - 1] = MCDCRecord::MCDC_False;
- if (Branch->MCDCParams.FalseID > 0)
- buildTestVector(TV, Branch->MCDCParams.FalseID, Index);
+ if (FalseID > 0)
+ buildTestVector(TV, FalseID, Index);
else
recordTestVector(TV, Index, MCDCRecord::MCDC_False);
Index |= 1 << (ID - 1);
TV[ID - 1] = MCDCRecord::MCDC_True;
- if (Branch->MCDCParams.TrueID > 0)
- buildTestVector(TV, Branch->MCDCParams.TrueID, Index);
+ if (TrueID > 0)
+ buildTestVector(TV, TrueID, Index);
else
recordTestVector(TV, Index, MCDCRecord::MCDC_True);
@@ -371,8 +373,9 @@ class MCDCRecordProcessor {
// - 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;
+ const auto &BranchParams = B->getBranchParams();
+ BranchParamsMap[BranchParams.ID] = &BranchParams;
+ PosToID[I] = BranchParams.ID - 1;
CondLoc[I] = B->startLoc();
Folded[I++] = (B->Count.isZero() && B->FalseCount.isZero());
}
@@ -492,10 +495,12 @@ static unsigned getMaxBitmapSize(const CounterMappingContext &Ctx,
// Note that `<=` is used insted of `<`, because `BitmapIdx == 0` is valid
// and `MaxBitmapIdx is `unsigned`. `BitmapIdx` is unique in the record.
for (const auto &Region : reverse(Record.MappingRegions)) {
- if (Region.Kind == CounterMappingRegion::MCDCDecisionRegion &&
- MaxBitmapIdx <= Region.MCDCParams.BitmapIdx) {
- MaxBitmapIdx = Region.MCDCParams.BitmapIdx;
- NumConditions = Region.MCDCParams.NumConditions;
+ if (Region.Kind != CounterMappingRegion::MCDCDecisionRegion)
+ continue;
+ const auto &DecisionParams = Region.getDecisionParams();
+ if (MaxBitmapIdx <= DecisionParams.BitmapIdx) {
+ MaxBitmapIdx = DecisionParams.BitmapIdx;
+ NumConditions = DecisionParams.NumConditions;
}
}
unsigned SizeInBits = llvm::alignTo(uint64_t(1) << NumConditions, CHAR_BIT);
@@ -515,6 +520,7 @@ class MCDCDecisionRecorder {
const CounterMappingRegion *DecisionRegion;
/// They are reflected from DecisionRegion for convenience.
+ mcdc::DecisionParameters DecisionParams;
LineColPair DecisionStartLoc;
LineColPair DecisionEndLoc;
@@ -533,7 +539,9 @@ class MCDCDecisionRecorder {
DenseSet<unsigned> ExpandedFileIDs;
DecisionRecord(const CounterMappingRegion &Decision)
- : DecisionRegion(&Decision), DecisionStartLoc(Decision.startLoc()),
+ : DecisionRegion(&Decision),
+ DecisionParams(Decision.getDecisionParams()),
+ DecisionStartLoc(Decision.startLoc()),
DecisionEndLoc(Decision.endLoc()) {
assert(Decision.Kind == CounterMappingRegion::MCDCDecisionRegion);
}
@@ -561,17 +569,17 @@ class MCDCDecisionRecorder {
Result addBranch(const CounterMappingRegion &Branch) {
assert(Branch.Kind == CounterMappingRegion::MCDCBranchRegion);
- auto ConditionID = Branch.MCDCParams.ID;
+ auto ConditionID = Branch.getBranchParams().ID;
assert(ConditionID > 0 && "ConditionID should begin with 1");
if (ConditionIDs.contains(ConditionID) ||
- ConditionID > DecisionRegion->MCDCParams.NumConditions)
+ ConditionID > DecisionParams.NumConditions)
return NotProcessed;
if (!this->dominates(Branch))
return NotProcessed;
- assert(MCDCBranches.size() < DecisionRegion->MCDCParams.NumConditions);
+ assert(MCDCBranches.size() < DecisionParams.NumConditions);
// Put `ID=1` in front of `MCDCBranches` for convenience
// even if `MCDCBranches` is not topological.
@@ -584,9 +592,8 @@ class MCDCDecisionRecorder {
ConditionIDs.insert(ConditionID);
// `Completed` when `MCDCBranches` is full
- return (MCDCBranches.size() == DecisionRegion->MCDCParams.NumConditions
- ? Completed
- : Processed);
+ return (MCDCBranches.size() == DecisionParams.NumConditions ? Completed
+ : Processed);
}
/// Record Expansion if it is relevant to this Decision.
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index 061f0f1bdcd3e2..d528d9aa95648f 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -244,7 +244,8 @@ Error RawCoverageMappingReader::readMappingRegionsSubArray(
unsigned LineStart = 0;
for (size_t I = 0; I < NumRegions; ++I) {
Counter C, C2;
- uint64_t BIDX = 0, NC = 0, ID = 0, TID = 0, FID = 0;
+ uint64_t BIDX, NC, ID, TID, FID;
+ mcdc::Parameters Params;
CounterMappingRegion::RegionKind Kind = CounterMappingRegion::CodeRegion;
// Read the combined counter + region kind.
@@ -312,6 +313,9 @@ Error RawCoverageMappingReader::readMappingRegionsSubArray(
return make_error<CoverageMapError>(
coveragemap_error::malformed,
"MCDCConditionID shouldn't be zero");
+ Params = mcdc::BranchParameters{static_cast<unsigned>(ID),
+ static_cast<unsigned>(TID),
+ static_cast<unsigned>(FID)};
break;
case CounterMappingRegion::MCDCDecisionRegion:
Kind = CounterMappingRegion::MCDCDecisionRegion;
@@ -319,6 +323,8 @@ Error RawCoverageMappingReader::readMappingRegionsSubArray(
return Err;
if (auto Err = readIntMax(NC, std::numeric_limits<unsigned>::max()))
return Err;
+ Params = mcdc::DecisionParameters{static_cast<unsigned>(BIDX),
+ static_cast<unsigned>(NC)};
break;
default:
return make_error<CoverageMapError>(coveragemap_error::malformed,
@@ -374,12 +380,8 @@ Error RawCoverageMappingReader::readMappingRegionsSubArray(
});
auto CMR = CounterMappingRegion(
- C, C2,
- mcdc::Parameters{static_cast<unsigned>(BIDX), static_cast<unsigned>(NC),
- static_cast<unsigned>(ID), static_cast<unsigned>(TID),
- static_cast<unsigned>(FID)},
- InferredFileID, ExpandedFileID, LineStart, ColumnStart,
- LineStart + NumLines, ColumnEnd, Kind);
+ C, C2, InferredFileID, ExpandedFileID, LineStart, ColumnStart,
+ LineStart + NumLines, ColumnEnd, Kind, Params);
if (CMR.startLoc() > CMR.endLoc())
return make_error<CoverageMapError>(
coveragemap_error::malformed,
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
index 248a6a79a145fd..3267afdbe15c28 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
@@ -213,6 +213,7 @@ void CoverageMappingWriter::write(raw_ostream &OS) {
}
Counter Count = Minimizer.adjust(I->Count);
Counter FalseCount = Minimizer.adjust(I->FalseCount);
+ bool ParamsShouldBeNull = true;
switch (I->Kind) {
case CounterMappingRegion::CodeRegion:
case CounterMappingRegion::GapRegion:
@@ -251,17 +252,25 @@ void CoverageMappingWriter::write(raw_ostream &OS) {
OS);
writeCounter(MinExpressions, Count, OS);
writeCounter(MinExpressions, FalseCount, OS);
- assert(I->MCDCParams.ID > 0);
- encodeULEB128(unsigned(I->MCDCParams.ID), OS);
- encodeULEB128(unsigned(I->MCDCParams.TrueID), OS);
- encodeULEB128(unsigned(I->MCDCParams.FalseID), OS);
+ {
+ const auto &BranchParams = I->getBranchParams();
+ ParamsShouldBeNull = false;
+ assert(BranchParams.ID > 0);
+ encodeULEB128(static_cast<unsigned>(BranchParams.ID), OS);
+ encodeULEB128(static_cast<unsigned>(BranchParams.TrueID), OS);
+ encodeULEB128(static_cast<unsigned>(BranchParams.FalseID), OS);
+ }
break;
case CounterMappingRegion::MCDCDecisionRegion:
encodeULEB128(unsigned(I->Kind)
<< Counter::EncodingCounterTagAndExpansionRegionTagBits,
OS);
- encodeULEB128(unsigned(I->MCDCParams.BitmapIdx), OS);
- encodeULEB128(unsigned(I->MCDCParams.NumConditions), OS);
+ {
+ const auto &DecisionParams = I->getDecisionParams();
+ ParamsShouldBeNull = false;
+ encodeULEB128(static_cast<unsigned>(DecisionParams.BitmapIdx), OS);
+ encodeULEB128(static_cast<unsigned>(DecisionParams.NumConditions), OS);
+ }
break;
}
assert(I->LineStart >= PrevLineStart);
@@ -271,6 +280,9 @@ void CoverageMappingWriter::write(raw_ostream &OS) {
encodeULEB128(I->LineEnd - I->LineStart, OS);
encodeULEB128(I->ColumnEnd, OS);
PrevLineStart = I->LineStart;
+ assert((!ParamsShouldBeNull || std::get_if<0>(&I->MCDCParams)) &&
+ "MCDCParams should be empty");
+ (void)ParamsShouldBeNull;
}
// Ensure that all file ids have at least one mapping region.
assert(CurrentFileID == (VirtualFileMapping.size() - 1));
diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
index d60312b68237bb..6f6718fbd94591 100644
--- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp
+++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
@@ -197,7 +197,7 @@ struct CoverageMappingTest : ::testing::TestWithParam<std::tuple<bool, bool>> {
auto &Regions = InputFunctions.back().Regions;
unsigned FileID = getFileIndexForFunction(File);
Regions.push_back(CounterMappingRegion::makeDecisionRegion(
- mcdc::Parameters{Mask, NC}, FileID, LS, CS, LE, CE));
+ mcdc::DecisionParameters{Mask, NC}, FileID, LS, CS, LE, CE));
}
void addMCDCBranchCMR(Counter C1, Counter C2, unsigned ID, unsigned TrueID,
@@ -206,8 +206,8 @@ struct CoverageMappingTest : ::testing::TestWithParam<std::tuple<bool, bool>> {
auto &Regions = InputFunctions.back().Regions;
unsigned FileID = getFileIndexForFunction(File);
Regions.push_back(CounterMappingRegion::makeBranchRegion(
- C1, C2, mcdc::Parameters{0, 0, ID, TrueID, FalseID}, FileID, LS, CS, LE,
- CE));
+ C1, C2, FileID, LS, CS, LE, CE,
+ mcdc::BranchParameters{ID, TrueID, FalseID}));
}
void addExpansionCMR(StringRef File, StringRef ExpandedFile, unsigned LS,
More information about the cfe-commits
mailing list