Skip to content

[Coverage] Move SingleByteCoverage out of CountedRegion #110966

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

Merged
merged 28 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
178b57c
[Coverage] Move SingleByteCoverage out of CountedRegion
chapuni Oct 2, 2024
aacb50d
[Coverage] Make SingleByteCoverage work consistent to merging
chapuni Oct 2, 2024
b9bbc7c
Rework. (Also reverts "[Coverage] Move SingleByteCoverage out of Cou…
chapuni Oct 5, 2024
52f072e
clang/test/CoverageMapping/single-byte-counters.cpp: Rewrite counter …
chapuni Oct 17, 2024
97a4a8f
test/llvm-cov: Transform %.c* tests to {%.test, Inputs/%.c*}
chapuni Nov 20, 2024
c50c492
Introduce test/llvm-cov/Inputs/yaml.makefile for convenience.
chapuni Nov 20, 2024
d7c5b44
Add tests for SingleByteCoverage
chapuni Nov 20, 2024
6675226
Merge branch 'users/chapuni/cov/single/test' into users/chapuni/cov/s…
chapuni Nov 20, 2024
5fc3408
Fix a test to fix linecount=1
chapuni Nov 20, 2024
eb7fff9
threads.c: Fixup on the clean testdir
chapuni Nov 20, 2024
7543095
Rename threads.c to threads.test since it is no longer C source file.
chapuni Nov 21, 2024
00ac90d
llvm/test/tools/llvm-cov/Inputs: Avoid wildcards `rm -rf %t*.dir`
chapuni Nov 21, 2024
fcb3ee8
Merge branch 'main' into users/chapuni/cov/single/test
chapuni Dec 21, 2024
5fa862a
Use `[[#min(C,n)]]` for tests
chapuni Dec 21, 2024
805e9a9
llvm-cov: Introduce `--binary-counters`
chapuni Dec 21, 2024
68d7b3b
Merge branch 'users/chapuni/cov/single/test' into users/chapuni/cov/s…
chapuni Dec 21, 2024
24457a7
Update tests
chapuni Dec 21, 2024
805dbd9
Merge branches 'users/chapuni/cov/single/merge' and 'users/chapuni/co…
chapuni Dec 21, 2024
f96b435
New SingleByteCoverage
chapuni Dec 21, 2024
47550d1
threads.c => threads.test (following #113114)
chapuni Dec 22, 2024
f4dc4eb
s/Count1/BinaryCount/
chapuni Dec 23, 2024
822620b
Update desc
chapuni Dec 23, 2024
658bd48
Merge branch 'main' into users/chapuni/cov/binary
chapuni Dec 24, 2024
0780993
Merge branch 'users/chapuni/cov/binary' into users/chapuni/cov/single…
chapuni Dec 24, 2024
dfc99ba
Fix wrong merge resolutions
chapuni Dec 24, 2024
f3c9593
Reorganize CoverageMapping::SingleByteCoverage
chapuni Dec 24, 2024
3780e07
Prune commented-out line
chapuni Dec 24, 2024
894c383
Merge branch 'main' into users/chapuni/cov/single/refactor
chapuni Dec 27, 2024
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
28 changes: 15 additions & 13 deletions llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand All @@ -731,8 +727,7 @@ struct FunctionRecord {
}
if (CountedRegions.empty())
ExecutionCount = Count;
CountedRegions.emplace_back(Region, Count, FalseCount,
HasSingleByteCoverage);
CountedRegions.emplace_back(Region, Count, FalseCount);
}
};

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
29 changes: 13 additions & 16 deletions llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion llvm/tools/llvm-cov/SourceCoverageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ class SourceCoverageView {
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>
Expand Down
Loading