Skip to content

Commit 178b57c

Browse files
committed
[Coverage] Move SingleByteCoverage out of CountedRegion
`SingleByteCoverage` is not per-region attribute at least. At the moment, this change moves it into `FunctionRecord`.
1 parent 4fc08b6 commit 178b57c

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -359,19 +359,15 @@ struct CountedRegion : public CounterMappingRegion {
359359
uint64_t ExecutionCount;
360360
uint64_t FalseExecutionCount;
361361
bool Folded;
362-
bool HasSingleByteCoverage;
363362

364-
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount,
365-
bool HasSingleByteCoverage)
363+
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
366364
: CounterMappingRegion(R), ExecutionCount(ExecutionCount),
367-
FalseExecutionCount(0), Folded(false),
368-
HasSingleByteCoverage(HasSingleByteCoverage) {}
365+
FalseExecutionCount(0), Folded(false) {}
369366

370367
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount,
371-
uint64_t FalseExecutionCount, bool HasSingleByteCoverage)
368+
uint64_t FalseExecutionCount)
372369
: CounterMappingRegion(R), ExecutionCount(ExecutionCount),
373-
FalseExecutionCount(FalseExecutionCount), Folded(false),
374-
HasSingleByteCoverage(HasSingleByteCoverage) {}
370+
FalseExecutionCount(FalseExecutionCount), Folded(false) {}
375371
};
376372

377373
/// MCDC Record grouping all information together.
@@ -702,9 +698,12 @@ struct FunctionRecord {
702698
std::vector<MCDCRecord> MCDCRecords;
703699
/// The number of times this function was executed.
704700
uint64_t ExecutionCount = 0;
701+
bool SingleByteCoverage;
705702

706-
FunctionRecord(StringRef Name, ArrayRef<StringRef> Filenames)
707-
: Name(Name), Filenames(Filenames.begin(), Filenames.end()) {}
703+
FunctionRecord(StringRef Name, ArrayRef<StringRef> Filenames,
704+
bool SingleByteCoverage)
705+
: Name(Name), Filenames(Filenames.begin(), Filenames.end()),
706+
SingleByteCoverage(SingleByteCoverage) {}
708707

709708
FunctionRecord(FunctionRecord &&FR) = default;
710709
FunctionRecord &operator=(FunctionRecord &&) = default;
@@ -714,11 +713,10 @@ struct FunctionRecord {
714713
}
715714

716715
void pushRegion(CounterMappingRegion Region, uint64_t Count,
717-
uint64_t FalseCount, bool HasSingleByteCoverage) {
716+
uint64_t FalseCount) {
718717
if (Region.Kind == CounterMappingRegion::BranchRegion ||
719718
Region.Kind == CounterMappingRegion::MCDCBranchRegion) {
720-
CountedBranchRegions.emplace_back(Region, Count, FalseCount,
721-
HasSingleByteCoverage);
719+
CountedBranchRegions.emplace_back(Region, Count, FalseCount);
722720
// If both counters are hard-coded to zero, then this region represents a
723721
// constant-folded branch.
724722
if (Region.Count.isZero() && Region.FalseCount.isZero())
@@ -727,8 +725,7 @@ struct FunctionRecord {
727725
}
728726
if (CountedRegions.empty())
729727
ExecutionCount = Count;
730-
CountedRegions.emplace_back(Region, Count, FalseCount,
731-
HasSingleByteCoverage);
728+
CountedRegions.emplace_back(Region, Count, FalseCount);
732729
}
733730
};
734731

llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ Error CoverageMapping::loadFunctionRecord(
808808
else
809809
OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
810810

811+
bool SingleByteCoverage = ProfileReader.hasSingleByteCoverage();
811812
CounterMappingContext Ctx(Record.Expressions);
812813

813814
std::vector<uint64_t> Counts;
@@ -855,7 +856,7 @@ Error CoverageMapping::loadFunctionRecord(
855856
return Error::success();
856857

857858
MCDCDecisionRecorder MCDCDecisions;
858-
FunctionRecord Function(OrigFuncName, Record.Filenames);
859+
FunctionRecord Function(OrigFuncName, Record.Filenames, SingleByteCoverage);
859860
for (const auto &Region : Record.MappingRegions) {
860861
// MCDCDecisionRegion should be handled first since it overlaps with
861862
// others inside.
@@ -873,8 +874,7 @@ Error CoverageMapping::loadFunctionRecord(
873874
consumeError(std::move(E));
874875
return Error::success();
875876
}
876-
Function.pushRegion(Region, *ExecutionCount, *AltExecutionCount,
877-
ProfileReader.hasSingleByteCoverage());
877+
Function.pushRegion(Region, *ExecutionCount, *AltExecutionCount);
878878

879879
// Record ExpansionRegion.
880880
if (Region.Kind == CounterMappingRegion::ExpansionRegion) {
@@ -1270,7 +1270,8 @@ class SegmentBuilder {
12701270

12711271
/// Combine counts of regions which cover the same area.
12721272
static ArrayRef<CountedRegion>
1273-
combineRegions(MutableArrayRef<CountedRegion> Regions) {
1273+
combineRegions(MutableArrayRef<CountedRegion> Regions,
1274+
bool SingleByteCoverage) {
12741275
if (Regions.empty())
12751276
return Regions;
12761277
auto Active = Regions.begin();
@@ -1297,9 +1298,7 @@ class SegmentBuilder {
12971298
// We add counts of the regions of the same kind as the active region
12981299
// to handle the both situations.
12991300
if (I->Kind == Active->Kind) {
1300-
assert(I->HasSingleByteCoverage == Active->HasSingleByteCoverage &&
1301-
"Regions are generated in different coverage modes");
1302-
if (I->HasSingleByteCoverage)
1301+
if (SingleByteCoverage)
13031302
Active->ExecutionCount = Active->ExecutionCount || I->ExecutionCount;
13041303
else
13051304
Active->ExecutionCount += I->ExecutionCount;
@@ -1311,12 +1310,14 @@ class SegmentBuilder {
13111310
public:
13121311
/// Build a sorted list of CoverageSegments from a list of Regions.
13131312
static std::vector<CoverageSegment>
1314-
buildSegments(MutableArrayRef<CountedRegion> Regions) {
1313+
buildSegments(MutableArrayRef<CountedRegion> Regions,
1314+
bool SingleByteCoverage) {
13151315
std::vector<CoverageSegment> Segments;
13161316
SegmentBuilder Builder(Segments);
13171317

13181318
sortNestedRegions(Regions);
1319-
ArrayRef<CountedRegion> CombinedRegions = combineRegions(Regions);
1319+
ArrayRef<CountedRegion> CombinedRegions =
1320+
combineRegions(Regions, SingleByteCoverage);
13201321

13211322
LLVM_DEBUG({
13221323
dbgs() << "Combined regions:\n";
@@ -1403,10 +1404,14 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
14031404
// the filename, we may get back some records that are not in the file.
14041405
ArrayRef<unsigned> RecordIndices =
14051406
getImpreciseRecordIndicesForFilename(Filename);
1407+
std::optional<bool> SingleByteCoverage;
14061408
for (unsigned RecordIndex : RecordIndices) {
14071409
const FunctionRecord &Function = Functions[RecordIndex];
14081410
auto MainFileID = findMainViewFileID(Filename, Function);
14091411
auto FileIDs = gatherFileIDs(Filename, Function);
1412+
assert(!SingleByteCoverage ||
1413+
*SingleByteCoverage == Function.SingleByteCoverage);
1414+
SingleByteCoverage = Function.SingleByteCoverage;
14101415
for (const auto &CR : Function.CountedRegions)
14111416
if (FileIDs.test(CR.FileID)) {
14121417
Regions.push_back(CR);
@@ -1424,7 +1429,8 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
14241429
}
14251430

14261431
LLVM_DEBUG(dbgs() << "Emitting segments for file: " << Filename << "\n");
1427-
FileCoverage.Segments = SegmentBuilder::buildSegments(Regions);
1432+
FileCoverage.Segments =
1433+
SegmentBuilder::buildSegments(Regions, *SingleByteCoverage);
14281434

14291435
return FileCoverage;
14301436
}
@@ -1480,7 +1486,8 @@ CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) const {
14801486

14811487
LLVM_DEBUG(dbgs() << "Emitting segments for function: " << Function.Name
14821488
<< "\n");
1483-
FunctionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
1489+
FunctionCoverage.Segments =
1490+
SegmentBuilder::buildSegments(Regions, Function.SingleByteCoverage);
14841491

14851492
return FunctionCoverage;
14861493
}
@@ -1490,8 +1497,12 @@ CoverageData CoverageMapping::getCoverageForExpansion(
14901497
CoverageData ExpansionCoverage(
14911498
Expansion.Function.Filenames[Expansion.FileID]);
14921499
std::vector<CountedRegion> Regions;
1500+
std::optional<bool> SingleByteCoverage;
14931501
for (const auto &CR : Expansion.Function.CountedRegions)
14941502
if (CR.FileID == Expansion.FileID) {
1503+
assert(!SingleByteCoverage ||
1504+
*SingleByteCoverage == Expansion.Function.SingleByteCoverage);
1505+
SingleByteCoverage = Expansion.Function.SingleByteCoverage;
14951506
Regions.push_back(CR);
14961507
if (isExpansion(CR, Expansion.FileID))
14971508
ExpansionCoverage.Expansions.emplace_back(CR, Expansion.Function);
@@ -1503,7 +1514,8 @@ CoverageData CoverageMapping::getCoverageForExpansion(
15031514

15041515
LLVM_DEBUG(dbgs() << "Emitting segments for expansion of file "
15051516
<< Expansion.FileID << "\n");
1506-
ExpansionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
1517+
ExpansionCoverage.Segments =
1518+
SegmentBuilder::buildSegments(Regions, *SingleByteCoverage);
15071519

15081520
return ExpansionCoverage;
15091521
}

0 commit comments

Comments
 (0)