-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[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
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
178b57c
[Coverage] Move SingleByteCoverage out of CountedRegion
chapuni aacb50d
[Coverage] Make SingleByteCoverage work consistent to merging
chapuni b9bbc7c
Rework. (Also reverts "[Coverage] Move SingleByteCoverage out of Cou…
chapuni 52f072e
clang/test/CoverageMapping/single-byte-counters.cpp: Rewrite counter …
chapuni 97a4a8f
test/llvm-cov: Transform %.c* tests to {%.test, Inputs/%.c*}
chapuni c50c492
Introduce test/llvm-cov/Inputs/yaml.makefile for convenience.
chapuni d7c5b44
Add tests for SingleByteCoverage
chapuni 6675226
Merge branch 'users/chapuni/cov/single/test' into users/chapuni/cov/s…
chapuni 5fc3408
Fix a test to fix linecount=1
chapuni eb7fff9
threads.c: Fixup on the clean testdir
chapuni 7543095
Rename threads.c to threads.test since it is no longer C source file.
chapuni 00ac90d
llvm/test/tools/llvm-cov/Inputs: Avoid wildcards `rm -rf %t*.dir`
chapuni fcb3ee8
Merge branch 'main' into users/chapuni/cov/single/test
chapuni 5fa862a
Use `[[#min(C,n)]]` for tests
chapuni 805e9a9
llvm-cov: Introduce `--binary-counters`
chapuni 68d7b3b
Merge branch 'users/chapuni/cov/single/test' into users/chapuni/cov/s…
chapuni 24457a7
Update tests
chapuni 805dbd9
Merge branches 'users/chapuni/cov/single/merge' and 'users/chapuni/co…
chapuni f96b435
New SingleByteCoverage
chapuni 47550d1
threads.c => threads.test (following #113114)
chapuni f4dc4eb
s/Count1/BinaryCount/
chapuni 822620b
Update desc
chapuni 658bd48
Merge branch 'main' into users/chapuni/cov/binary
chapuni 0780993
Merge branch 'users/chapuni/cov/binary' into users/chapuni/cov/single…
chapuni dfc99ba
Fix wrong merge resolutions
chapuni f3c9593
Reorganize CoverageMapping::SingleByteCoverage
chapuni 3780e07
Prune commented-out line
chapuni 894c383
Merge branch 'main' into users/chapuni/cov/single/refactor
chapuni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -808,6 +808,7 @@ Error CoverageMapping::loadFunctionRecord( | |
else | ||
OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]); | ||
|
||
bool SingleByteCoverage = ProfileReader.hasSingleByteCoverage(); | ||
CounterMappingContext Ctx(Record.Expressions); | ||
|
||
std::vector<uint64_t> Counts; | ||
|
@@ -855,7 +856,7 @@ Error CoverageMapping::loadFunctionRecord( | |
return Error::success(); | ||
|
||
MCDCDecisionRecorder MCDCDecisions; | ||
FunctionRecord Function(OrigFuncName, Record.Filenames); | ||
FunctionRecord Function(OrigFuncName, Record.Filenames, SingleByteCoverage); | ||
for (const auto &Region : Record.MappingRegions) { | ||
// MCDCDecisionRegion should be handled first since it overlaps with | ||
// others inside. | ||
|
@@ -873,8 +874,7 @@ Error CoverageMapping::loadFunctionRecord( | |
consumeError(std::move(E)); | ||
return Error::success(); | ||
} | ||
Function.pushRegion(Region, *ExecutionCount, *AltExecutionCount, | ||
ProfileReader.hasSingleByteCoverage()); | ||
Function.pushRegion(Region, *ExecutionCount, *AltExecutionCount); | ||
|
||
// Record ExpansionRegion. | ||
if (Region.Kind == CounterMappingRegion::ExpansionRegion) { | ||
|
@@ -1270,7 +1270,8 @@ class SegmentBuilder { | |
|
||
/// Combine counts of regions which cover the same area. | ||
static ArrayRef<CountedRegion> | ||
combineRegions(MutableArrayRef<CountedRegion> Regions) { | ||
combineRegions(MutableArrayRef<CountedRegion> Regions, | ||
bool SingleByteCoverage) { | ||
if (Regions.empty()) | ||
return Regions; | ||
auto Active = Regions.begin(); | ||
|
@@ -1297,9 +1298,7 @@ class SegmentBuilder { | |
// 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) | ||
if (SingleByteCoverage) | ||
Active->ExecutionCount = Active->ExecutionCount || I->ExecutionCount; | ||
else | ||
Active->ExecutionCount += I->ExecutionCount; | ||
|
@@ -1311,12 +1310,14 @@ class SegmentBuilder { | |
public: | ||
/// Build a sorted list of CoverageSegments from a list of Regions. | ||
static std::vector<CoverageSegment> | ||
buildSegments(MutableArrayRef<CountedRegion> Regions) { | ||
buildSegments(MutableArrayRef<CountedRegion> Regions, | ||
bool SingleByteCoverage) { | ||
std::vector<CoverageSegment> Segments; | ||
SegmentBuilder Builder(Segments); | ||
|
||
sortNestedRegions(Regions); | ||
ArrayRef<CountedRegion> CombinedRegions = combineRegions(Regions); | ||
ArrayRef<CountedRegion> CombinedRegions = | ||
combineRegions(Regions, SingleByteCoverage); | ||
|
||
LLVM_DEBUG({ | ||
dbgs() << "Combined regions:\n"; | ||
|
@@ -1403,10 +1404,14 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const { | |
// the filename, we may get back some records that are not in the file. | ||
ArrayRef<unsigned> RecordIndices = | ||
getImpreciseRecordIndicesForFilename(Filename); | ||
std::optional<bool> SingleByteCoverage; | ||
for (unsigned RecordIndex : RecordIndices) { | ||
const FunctionRecord &Function = Functions[RecordIndex]; | ||
auto MainFileID = findMainViewFileID(Filename, Function); | ||
auto FileIDs = gatherFileIDs(Filename, Function); | ||
assert(!SingleByteCoverage || | ||
*SingleByteCoverage == Function.SingleByteCoverage); | ||
SingleByteCoverage = Function.SingleByteCoverage; | ||
for (const auto &CR : Function.CountedRegions) | ||
if (FileIDs.test(CR.FileID)) { | ||
Regions.push_back(CR); | ||
|
@@ -1424,7 +1429,8 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const { | |
} | ||
|
||
LLVM_DEBUG(dbgs() << "Emitting segments for file: " << Filename << "\n"); | ||
FileCoverage.Segments = SegmentBuilder::buildSegments(Regions); | ||
FileCoverage.Segments = | ||
SegmentBuilder::buildSegments(Regions, *SingleByteCoverage); | ||
|
||
return FileCoverage; | ||
} | ||
|
@@ -1480,7 +1486,8 @@ CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) const { | |
|
||
LLVM_DEBUG(dbgs() << "Emitting segments for function: " << Function.Name | ||
<< "\n"); | ||
FunctionCoverage.Segments = SegmentBuilder::buildSegments(Regions); | ||
FunctionCoverage.Segments = | ||
SegmentBuilder::buildSegments(Regions, Function.SingleByteCoverage); | ||
|
||
return FunctionCoverage; | ||
} | ||
|
@@ -1490,8 +1497,12 @@ CoverageData CoverageMapping::getCoverageForExpansion( | |
CoverageData ExpansionCoverage( | ||
Expansion.Function.Filenames[Expansion.FileID]); | ||
std::vector<CountedRegion> Regions; | ||
std::optional<bool> SingleByteCoverage; | ||
for (const auto &CR : Expansion.Function.CountedRegions) | ||
if (CR.FileID == Expansion.FileID) { | ||
assert(!SingleByteCoverage || | ||
*SingleByteCoverage == Expansion.Function.SingleByteCoverage); | ||
SingleByteCoverage = Expansion.Function.SingleByteCoverage; | ||
Regions.push_back(CR); | ||
if (isExpansion(CR, Expansion.FileID)) | ||
ExpansionCoverage.Expansions.emplace_back(CR, Expansion.Function); | ||
|
@@ -1503,7 +1514,8 @@ CoverageData CoverageMapping::getCoverageForExpansion( | |
|
||
LLVM_DEBUG(dbgs() << "Emitting segments for expansion of file " | ||
<< Expansion.FileID << "\n"); | ||
ExpansionCoverage.Segments = SegmentBuilder::buildSegments(Regions); | ||
ExpansionCoverage.Segments = | ||
SegmentBuilder::buildSegments(Regions, *SingleByteCoverage); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this will crash if |
||
|
||
return ExpansionCoverage; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will crash if
RecordIndices
is empty. Is that possible? If not, can we add an assert?