[Coverage] Move SingleByteCoverage out of CountedRegion (#110966)
`SingleByteCoverage` is not per-region attribute at least. Move it into `CoverageData` since it comes from `profdata`. Depends on: #120841
This commit is contained in:
parent
223521b13e
commit
aa2fdc69d3
@ -364,19 +364,16 @@ struct CountedRegion : public CounterMappingRegion {
|
||||
uint64_t FalseExecutionCount;
|
||||
bool TrueFolded;
|
||||
bool FalseFolded;
|
||||
bool HasSingleByteCoverage;
|
||||
|
||||
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount,
|
||||
bool HasSingleByteCoverage)
|
||||
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
|
||||
: CounterMappingRegion(R), ExecutionCount(ExecutionCount),
|
||||
FalseExecutionCount(0), TrueFolded(false), FalseFolded(true),
|
||||
HasSingleByteCoverage(HasSingleByteCoverage) {}
|
||||
FalseExecutionCount(0), TrueFolded(false), FalseFolded(true) {}
|
||||
|
||||
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount,
|
||||
uint64_t FalseExecutionCount, bool HasSingleByteCoverage)
|
||||
uint64_t FalseExecutionCount)
|
||||
: CounterMappingRegion(R), ExecutionCount(ExecutionCount),
|
||||
FalseExecutionCount(FalseExecutionCount), TrueFolded(false),
|
||||
FalseFolded(false), HasSingleByteCoverage(HasSingleByteCoverage) {}
|
||||
FalseFolded(false) {}
|
||||
};
|
||||
|
||||
/// MCDC Record grouping all information together.
|
||||
@ -719,10 +716,9 @@ struct FunctionRecord {
|
||||
}
|
||||
|
||||
void pushRegion(CounterMappingRegion Region, uint64_t Count,
|
||||
uint64_t FalseCount, bool HasSingleByteCoverage) {
|
||||
uint64_t FalseCount) {
|
||||
if (Region.isBranch()) {
|
||||
CountedBranchRegions.emplace_back(Region, Count, FalseCount,
|
||||
HasSingleByteCoverage);
|
||||
CountedBranchRegions.emplace_back(Region, Count, FalseCount);
|
||||
// If either counter is hard-coded to zero, then this region represents a
|
||||
// constant-folded branch.
|
||||
CountedBranchRegions.back().TrueFolded = Region.Count.isZero();
|
||||
@ -731,8 +727,7 @@ struct FunctionRecord {
|
||||
}
|
||||
if (CountedRegions.empty())
|
||||
ExecutionCount = Count;
|
||||
CountedRegions.emplace_back(Region, Count, FalseCount,
|
||||
HasSingleByteCoverage);
|
||||
CountedRegions.emplace_back(Region, Count, FalseCount);
|
||||
}
|
||||
};
|
||||
|
||||
@ -895,14 +890,19 @@ class CoverageData {
|
||||
std::vector<CountedRegion> BranchRegions;
|
||||
std::vector<MCDCRecord> MCDCRecords;
|
||||
|
||||
bool SingleByteCoverage = false;
|
||||
|
||||
public:
|
||||
CoverageData() = default;
|
||||
|
||||
CoverageData(StringRef Filename) : Filename(Filename) {}
|
||||
CoverageData(bool Single, StringRef Filename)
|
||||
: Filename(Filename), SingleByteCoverage(Single) {}
|
||||
|
||||
/// Get the name of the file this data covers.
|
||||
StringRef getFilename() const { return Filename; }
|
||||
|
||||
bool getSingleByteCoverage() const { return SingleByteCoverage; }
|
||||
|
||||
/// Get an iterator over the coverage segments for this object. The segments
|
||||
/// are guaranteed to be uniqued and sorted by location.
|
||||
std::vector<CoverageSegment>::const_iterator begin() const {
|
||||
@ -935,6 +935,8 @@ class CoverageMapping {
|
||||
DenseMap<size_t, SmallVector<unsigned, 0>> FilenameHash2RecordIndices;
|
||||
std::vector<std::pair<std::string, uint64_t>> FuncHashMismatches;
|
||||
|
||||
std::optional<bool> SingleByteCoverage;
|
||||
|
||||
CoverageMapping() = default;
|
||||
|
||||
// Load coverage records from readers.
|
||||
|
||||
@ -805,7 +805,6 @@ Error CoverageMapping::loadFunctionRecord(
|
||||
else
|
||||
OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
|
||||
|
||||
bool SingleByteCoverage = ProfileReader.hasSingleByteCoverage();
|
||||
CounterMappingContext Ctx(Record.Expressions);
|
||||
|
||||
std::vector<uint64_t> Counts;
|
||||
@ -871,10 +870,7 @@ Error CoverageMapping::loadFunctionRecord(
|
||||
consumeError(std::move(E));
|
||||
return Error::success();
|
||||
}
|
||||
Function.pushRegion(
|
||||
Region, (SingleByteCoverage && *ExecutionCount ? 1 : *ExecutionCount),
|
||||
(SingleByteCoverage && *AltExecutionCount ? 1 : *AltExecutionCount),
|
||||
SingleByteCoverage);
|
||||
Function.pushRegion(Region, *ExecutionCount, *AltExecutionCount);
|
||||
|
||||
// Record ExpansionRegion.
|
||||
if (Region.Kind == CounterMappingRegion::ExpansionRegion) {
|
||||
@ -936,6 +932,9 @@ Error CoverageMapping::loadFunctionRecord(
|
||||
Error CoverageMapping::loadFromReaders(
|
||||
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
|
||||
IndexedInstrProfReader &ProfileReader, CoverageMapping &Coverage) {
|
||||
assert(!Coverage.SingleByteCoverage ||
|
||||
*Coverage.SingleByteCoverage == ProfileReader.hasSingleByteCoverage());
|
||||
Coverage.SingleByteCoverage = ProfileReader.hasSingleByteCoverage();
|
||||
for (const auto &CoverageReader : CoverageReaders) {
|
||||
for (auto RecordOrErr : *CoverageReader) {
|
||||
if (Error E = RecordOrErr.takeError())
|
||||
@ -1296,14 +1295,8 @@ class SegmentBuilder {
|
||||
// value for that area.
|
||||
// We add counts of the regions of the same kind as the active region
|
||||
// to handle the both situations.
|
||||
if (I->Kind == Active->Kind) {
|
||||
assert(I->HasSingleByteCoverage == Active->HasSingleByteCoverage &&
|
||||
"Regions are generated in different coverage modes");
|
||||
if (I->HasSingleByteCoverage)
|
||||
Active->ExecutionCount = Active->ExecutionCount || I->ExecutionCount;
|
||||
else
|
||||
Active->ExecutionCount += I->ExecutionCount;
|
||||
}
|
||||
if (I->Kind == Active->Kind)
|
||||
Active->ExecutionCount += I->ExecutionCount;
|
||||
}
|
||||
return Regions.drop_back(std::distance(++Active, End));
|
||||
}
|
||||
@ -1396,7 +1389,8 @@ static bool isExpansion(const CountedRegion &R, unsigned FileID) {
|
||||
}
|
||||
|
||||
CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
|
||||
CoverageData FileCoverage(Filename);
|
||||
assert(SingleByteCoverage);
|
||||
CoverageData FileCoverage(*SingleByteCoverage, Filename);
|
||||
std::vector<CountedRegion> Regions;
|
||||
|
||||
// Look up the function records in the given file. Due to hash collisions on
|
||||
@ -1460,7 +1454,9 @@ CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) const {
|
||||
if (!MainFileID)
|
||||
return CoverageData();
|
||||
|
||||
CoverageData FunctionCoverage(Function.Filenames[*MainFileID]);
|
||||
assert(SingleByteCoverage);
|
||||
CoverageData FunctionCoverage(*SingleByteCoverage,
|
||||
Function.Filenames[*MainFileID]);
|
||||
std::vector<CountedRegion> Regions;
|
||||
for (const auto &CR : Function.CountedRegions)
|
||||
if (CR.FileID == *MainFileID) {
|
||||
@ -1487,8 +1483,9 @@ CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) const {
|
||||
|
||||
CoverageData CoverageMapping::getCoverageForExpansion(
|
||||
const ExpansionRecord &Expansion) const {
|
||||
assert(SingleByteCoverage);
|
||||
CoverageData ExpansionCoverage(
|
||||
Expansion.Function.Filenames[Expansion.FileID]);
|
||||
*SingleByteCoverage, Expansion.Function.Filenames[Expansion.FileID]);
|
||||
std::vector<CountedRegion> Regions;
|
||||
for (const auto &CR : Expansion.Function.CountedRegions)
|
||||
if (CR.FileID == Expansion.FileID) {
|
||||
|
||||
@ -287,7 +287,8 @@ protected:
|
||||
CoverageData &&CoverageInfo)
|
||||
: SourceName(SourceName), File(File), Options(Options),
|
||||
CoverageInfo(std::move(CoverageInfo)),
|
||||
BinaryCounters(Options.BinaryCounters) {}
|
||||
BinaryCounters(Options.BinaryCounters ||
|
||||
CoverageInfo.getSingleByteCoverage()) {}
|
||||
|
||||
public:
|
||||
static std::unique_ptr<SourceCoverageView>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user