Skip to content

LLVMCoverage: Unify getCoverageForFile and getCoverageForFunction. NFC #120842

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

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 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
5b6c0b0
LLVMCoverage: Unify getCoverageForFile and getCoverageForFunction
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
978070d
[Coverage] MCDC: Move `findIndependencePairs` into `MCDCRecord`
chapuni Dec 27, 2024
2293b8d
Merge remote-tracking branches 'origin/users/chapuni/cov/single/refac…
chapuni Dec 27, 2024
894c383
Merge branch 'main' into users/chapuni/cov/single/refactor
chapuni Dec 27, 2024
7c26a2a
Merge branch 'main' into users/chapuni/cov/single/refactor
chapuni Dec 27, 2024
184dc0c
Merge branch 'users/chapuni/cov/single/refactor' into users/chapuni/c…
chapuni Dec 27, 2024
273a655
Merge branch 'main' into users/chapuni/cov/merge/mov_ind
chapuni Jan 7, 2025
10517c4
Merge branch 'main' into users/chapuni/cov/single/unify
chapuni Jan 7, 2025
9e57346
Merge branch 'users/chapuni/cov/merge/mov_ind' into users/chapuni/cov…
chapuni Jan 7, 2025
63f5dc1
Merge branch 'main' into users/chapuni/cov/single/unify
chapuni Jan 10, 2025
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
3 changes: 3 additions & 0 deletions llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ class InstantiationGroup {
class CoverageData {
friend class CoverageMapping;

protected:
std::string Filename;
std::vector<CoverageSegment> Segments;
std::vector<ExpansionRecord> Expansions;
Expand All @@ -914,6 +915,8 @@ class CoverageData {
CoverageData(bool Single, StringRef Filename)
: Filename(Filename), SingleByteCoverage(Single) {}

CoverageData(CoverageData &&RHS) = default;

/// Get the name of the file this data covers.
StringRef getFilename() const { return Filename; }

Expand Down
80 changes: 42 additions & 38 deletions llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,37 @@ class SegmentBuilder {
}
};

struct MergeableCoverageData : public CoverageData {
std::vector<CountedRegion> CodeRegions;

MergeableCoverageData(bool Single, StringRef Filename)
: CoverageData(Single, Filename) {}

void addFunctionRegions(
const FunctionRecord &Function,
std::function<bool(const CounterMappingRegion &CR)> shouldProcess,
std::function<bool(const CountedRegion &CR)> shouldExpand) {
for (const auto &CR : Function.CountedRegions)
if (shouldProcess(CR)) {
CodeRegions.push_back(CR);
if (shouldExpand(CR))
Expansions.emplace_back(CR, Function);
}
// Capture branch regions specific to the function (excluding expansions).
for (const auto &CR : Function.CountedBranchRegions)
if (shouldProcess(CR))
BranchRegions.push_back(CR);
// Capture MCDC records specific to the function.
for (const auto &MR : Function.MCDCRecords)
if (shouldProcess(MR.getDecisionRegion()))
MCDCRecords.push_back(MR);
}

CoverageData buildSegments() {
Segments = SegmentBuilder::buildSegments(CodeRegions);
return CoverageData(std::move(*this));
}
};
} // end anonymous namespace

std::vector<StringRef> CoverageMapping::getUniqueSourceFiles() const {
Expand Down Expand Up @@ -1419,8 +1450,7 @@ static bool isExpansion(const CountedRegion &R, unsigned FileID) {

CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
assert(SingleByteCoverage);
CoverageData FileCoverage(*SingleByteCoverage, Filename);
std::vector<CountedRegion> Regions;
MergeableCoverageData FileCoverage(*SingleByteCoverage, Filename);

// Look up the function records in the given file. Due to hash collisions on
// the filename, we may get back some records that are not in the file.
Expand All @@ -1430,26 +1460,14 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
const FunctionRecord &Function = Functions[RecordIndex];
auto MainFileID = findMainViewFileID(Filename, Function);
auto FileIDs = gatherFileIDs(Filename, Function);
for (const auto &CR : Function.CountedRegions)
if (FileIDs.test(CR.FileID)) {
Regions.push_back(CR);
if (MainFileID && isExpansion(CR, *MainFileID))
FileCoverage.Expansions.emplace_back(CR, Function);
}
// Capture branch regions specific to the function (excluding expansions).
for (const auto &CR : Function.CountedBranchRegions)
if (FileIDs.test(CR.FileID))
FileCoverage.BranchRegions.push_back(CR);
// Capture MCDC records specific to the function.
for (const auto &MR : Function.MCDCRecords)
if (FileIDs.test(MR.getDecisionRegion().FileID))
FileCoverage.MCDCRecords.push_back(MR);
FileCoverage.addFunctionRegions(
Function, [&](auto &CR) { return FileIDs.test(CR.FileID); },
[&](auto &CR) { return (MainFileID && isExpansion(CR, *MainFileID)); });
}

LLVM_DEBUG(dbgs() << "Emitting segments for file: " << Filename << "\n");
FileCoverage.Segments = SegmentBuilder::buildSegments(Regions);

return FileCoverage;
return FileCoverage.buildSegments();
}

std::vector<InstantiationGroup>
Expand Down Expand Up @@ -1484,30 +1502,16 @@ CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) const {
return CoverageData();

assert(SingleByteCoverage);
CoverageData FunctionCoverage(*SingleByteCoverage,
Function.Filenames[*MainFileID]);
std::vector<CountedRegion> Regions;
for (const auto &CR : Function.CountedRegions)
if (CR.FileID == *MainFileID) {
Regions.push_back(CR);
if (isExpansion(CR, *MainFileID))
FunctionCoverage.Expansions.emplace_back(CR, Function);
}
// Capture branch regions specific to the function (excluding expansions).
for (const auto &CR : Function.CountedBranchRegions)
if (CR.FileID == *MainFileID)
FunctionCoverage.BranchRegions.push_back(CR);

// Capture MCDC records specific to the function.
for (const auto &MR : Function.MCDCRecords)
if (MR.getDecisionRegion().FileID == *MainFileID)
FunctionCoverage.MCDCRecords.push_back(MR);
MergeableCoverageData FunctionCoverage(*SingleByteCoverage,
Function.Filenames[*MainFileID]);
FunctionCoverage.addFunctionRegions(
Function, [&](auto &CR) { return (CR.FileID == *MainFileID); },
[&](auto &CR) { return isExpansion(CR, *MainFileID); });

LLVM_DEBUG(dbgs() << "Emitting segments for function: " << Function.Name
<< "\n");
FunctionCoverage.Segments = SegmentBuilder::buildSegments(Regions);

return FunctionCoverage;
return FunctionCoverage.buildSegments();
}

CoverageData CoverageMapping::getCoverageForExpansion(
Expand Down
Loading