Skip to content

Commit b9bbc7c

Browse files
committed
Rework. (Also reverts "[Coverage] Move SingleByteCoverage out of CountedRegion")
1 parent aacb50d commit b9bbc7c

File tree

7 files changed

+33
-46
lines changed

7 files changed

+33
-46
lines changed

compiler-rt/test/profile/instrprof-block-coverage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ int main(int argc, char *argv[]) {
4949

5050
// CHECK-ERROR-NOT: warning: {{.*}}: Found inconsistent block coverage
5151

52-
// COUNTS: Maximum function count: 1
52+
// COUNTS: Maximum function count: 4

compiler-rt/test/profile/instrprof-entry-coverage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ int main(int argc, char *argv[]) {
3636
// CHECK-DAG: foo
3737
// CHECK-DAG: bar
3838

39-
// COUNTS: Maximum function count: 1
39+
// COUNTS: Maximum function count: 2

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

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

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

367370
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount,
368-
uint64_t FalseExecutionCount)
371+
uint64_t FalseExecutionCount, bool HasSingleByteCoverage)
369372
: CounterMappingRegion(R), ExecutionCount(ExecutionCount),
370-
FalseExecutionCount(FalseExecutionCount), Folded(false) {}
373+
FalseExecutionCount(FalseExecutionCount), Folded(false),
374+
HasSingleByteCoverage(HasSingleByteCoverage) {}
371375
};
372376

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

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

708709
FunctionRecord(FunctionRecord &&FR) = default;
709710
FunctionRecord &operator=(FunctionRecord &&) = default;
@@ -713,10 +714,11 @@ struct FunctionRecord {
713714
}
714715

715716
void pushRegion(CounterMappingRegion Region, uint64_t Count,
716-
uint64_t FalseCount) {
717+
uint64_t FalseCount, bool HasSingleByteCoverage) {
717718
if (Region.Kind == CounterMappingRegion::BranchRegion ||
718719
Region.Kind == CounterMappingRegion::MCDCBranchRegion) {
719-
CountedBranchRegions.emplace_back(Region, Count, FalseCount);
720+
CountedBranchRegions.emplace_back(Region, Count, FalseCount,
721+
HasSingleByteCoverage);
720722
// If both counters are hard-coded to zero, then this region represents a
721723
// constant-folded branch.
722724
if (Region.Count.isZero() && Region.FalseCount.isZero())
@@ -725,7 +727,8 @@ struct FunctionRecord {
725727
}
726728
if (CountedRegions.empty())
727729
ExecutionCount = Count;
728-
CountedRegions.emplace_back(Region, Count, FalseCount);
730+
CountedRegions.emplace_back(Region, Count, FalseCount,
731+
HasSingleByteCoverage);
729732
}
730733
};
731734

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,6 @@ struct InstrProfValueSiteRecord {
830830
/// Profiling information for a single function.
831831
struct InstrProfRecord {
832832
std::vector<uint64_t> Counts;
833-
bool SingleByteCoverage = false;
834833
std::vector<uint8_t> BitmapBytes;
835834

836835
InstrProfRecord() = default;
@@ -840,15 +839,13 @@ struct InstrProfRecord {
840839
: Counts(std::move(Counts)), BitmapBytes(std::move(BitmapBytes)) {}
841840
InstrProfRecord(InstrProfRecord &&) = default;
842841
InstrProfRecord(const InstrProfRecord &RHS)
843-
: Counts(RHS.Counts), SingleByteCoverage(RHS.SingleByteCoverage),
844-
BitmapBytes(RHS.BitmapBytes),
842+
: Counts(RHS.Counts), BitmapBytes(RHS.BitmapBytes),
845843
ValueData(RHS.ValueData
846844
? std::make_unique<ValueProfData>(*RHS.ValueData)
847845
: nullptr) {}
848846
InstrProfRecord &operator=(InstrProfRecord &&) = default;
849847
InstrProfRecord &operator=(const InstrProfRecord &RHS) {
850848
Counts = RHS.Counts;
851-
SingleByteCoverage = RHS.SingleByteCoverage;
852849
BitmapBytes = RHS.BitmapBytes;
853850
if (!RHS.ValueData) {
854851
ValueData = nullptr;

llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ Error CoverageMapping::loadFunctionRecord(
856856
return Error::success();
857857

858858
MCDCDecisionRecorder MCDCDecisions;
859-
FunctionRecord Function(OrigFuncName, Record.Filenames, SingleByteCoverage);
859+
FunctionRecord Function(OrigFuncName, Record.Filenames);
860860
for (const auto &Region : Record.MappingRegions) {
861861
// MCDCDecisionRegion should be handled first since it overlaps with
862862
// others inside.
@@ -874,10 +874,10 @@ Error CoverageMapping::loadFunctionRecord(
874874
consumeError(std::move(E));
875875
return Error::success();
876876
}
877-
assert(!SingleByteCoverage ||
878-
(0 <= *ExecutionCount && *ExecutionCount <= 1 &&
879-
0 <= *AltExecutionCount && *AltExecutionCount <= 1));
880-
Function.pushRegion(Region, *ExecutionCount, *AltExecutionCount);
877+
Function.pushRegion(
878+
Region, (SingleByteCoverage && *ExecutionCount ? 1 : *ExecutionCount),
879+
(SingleByteCoverage && *AltExecutionCount ? 1 : *AltExecutionCount),
880+
SingleByteCoverage);
881881

882882
// Record ExpansionRegion.
883883
if (Region.Kind == CounterMappingRegion::ExpansionRegion) {
@@ -1273,8 +1273,7 @@ class SegmentBuilder {
12731273

12741274
/// Combine counts of regions which cover the same area.
12751275
static ArrayRef<CountedRegion>
1276-
combineRegions(MutableArrayRef<CountedRegion> Regions,
1277-
bool SingleByteCoverage) {
1276+
combineRegions(MutableArrayRef<CountedRegion> Regions) {
12781277
if (Regions.empty())
12791278
return Regions;
12801279
auto Active = Regions.begin();
@@ -1301,7 +1300,9 @@ class SegmentBuilder {
13011300
// We add counts of the regions of the same kind as the active region
13021301
// to handle the both situations.
13031302
if (I->Kind == Active->Kind) {
1304-
if (SingleByteCoverage)
1303+
assert(I->HasSingleByteCoverage == Active->HasSingleByteCoverage &&
1304+
"Regions are generated in different coverage modes");
1305+
if (I->HasSingleByteCoverage)
13051306
Active->ExecutionCount = Active->ExecutionCount || I->ExecutionCount;
13061307
else
13071308
Active->ExecutionCount += I->ExecutionCount;
@@ -1313,14 +1314,12 @@ class SegmentBuilder {
13131314
public:
13141315
/// Build a sorted list of CoverageSegments from a list of Regions.
13151316
static std::vector<CoverageSegment>
1316-
buildSegments(MutableArrayRef<CountedRegion> Regions,
1317-
bool SingleByteCoverage) {
1317+
buildSegments(MutableArrayRef<CountedRegion> Regions) {
13181318
std::vector<CoverageSegment> Segments;
13191319
SegmentBuilder Builder(Segments);
13201320

13211321
sortNestedRegions(Regions);
1322-
ArrayRef<CountedRegion> CombinedRegions =
1323-
combineRegions(Regions, SingleByteCoverage);
1322+
ArrayRef<CountedRegion> CombinedRegions = combineRegions(Regions);
13241323

13251324
LLVM_DEBUG({
13261325
dbgs() << "Combined regions:\n";
@@ -1407,14 +1406,10 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
14071406
// the filename, we may get back some records that are not in the file.
14081407
ArrayRef<unsigned> RecordIndices =
14091408
getImpreciseRecordIndicesForFilename(Filename);
1410-
std::optional<bool> SingleByteCoverage;
14111409
for (unsigned RecordIndex : RecordIndices) {
14121410
const FunctionRecord &Function = Functions[RecordIndex];
14131411
auto MainFileID = findMainViewFileID(Filename, Function);
14141412
auto FileIDs = gatherFileIDs(Filename, Function);
1415-
assert(!SingleByteCoverage ||
1416-
*SingleByteCoverage == Function.SingleByteCoverage);
1417-
SingleByteCoverage = Function.SingleByteCoverage;
14181413
for (const auto &CR : Function.CountedRegions)
14191414
if (FileIDs.test(CR.FileID)) {
14201415
Regions.push_back(CR);
@@ -1432,8 +1427,7 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
14321427
}
14331428

14341429
LLVM_DEBUG(dbgs() << "Emitting segments for file: " << Filename << "\n");
1435-
FileCoverage.Segments =
1436-
SegmentBuilder::buildSegments(Regions, *SingleByteCoverage);
1430+
FileCoverage.Segments = SegmentBuilder::buildSegments(Regions);
14371431

14381432
return FileCoverage;
14391433
}
@@ -1489,8 +1483,7 @@ CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) const {
14891483

14901484
LLVM_DEBUG(dbgs() << "Emitting segments for function: " << Function.Name
14911485
<< "\n");
1492-
FunctionCoverage.Segments =
1493-
SegmentBuilder::buildSegments(Regions, Function.SingleByteCoverage);
1486+
FunctionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
14941487

14951488
return FunctionCoverage;
14961489
}
@@ -1500,12 +1493,8 @@ CoverageData CoverageMapping::getCoverageForExpansion(
15001493
CoverageData ExpansionCoverage(
15011494
Expansion.Function.Filenames[Expansion.FileID]);
15021495
std::vector<CountedRegion> Regions;
1503-
std::optional<bool> SingleByteCoverage;
15041496
for (const auto &CR : Expansion.Function.CountedRegions)
15051497
if (CR.FileID == Expansion.FileID) {
1506-
assert(!SingleByteCoverage ||
1507-
*SingleByteCoverage == Expansion.Function.SingleByteCoverage);
1508-
SingleByteCoverage = Expansion.Function.SingleByteCoverage;
15091498
Regions.push_back(CR);
15101499
if (isExpansion(CR, Expansion.FileID))
15111500
ExpansionCoverage.Expansions.emplace_back(CR, Expansion.Function);
@@ -1517,8 +1506,7 @@ CoverageData CoverageMapping::getCoverageForExpansion(
15171506

15181507
LLVM_DEBUG(dbgs() << "Emitting segments for expansion of file "
15191508
<< Expansion.FileID << "\n");
1520-
ExpansionCoverage.Segments =
1521-
SegmentBuilder::buildSegments(Regions, *SingleByteCoverage);
1509+
ExpansionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
15221510

15231511
return ExpansionCoverage;
15241512
}

llvm/lib/ProfileData/InstrProf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ void InstrProfRecord::merge(InstrProfRecord &Other, uint64_t Weight,
952952
Value = getInstrMaxCountValue();
953953
Overflowed = true;
954954
}
955-
Counts[I] = (SingleByteCoverage && Value != 0 ? 1 : Value);
955+
Counts[I] = Value;
956956
if (Overflowed)
957957
Warn(instrprof_error::counter_overflow);
958958
}

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,6 @@ Error RawInstrProfReader<IntPtrT>::readRawCounts(
743743

744744
Record.Counts.clear();
745745
Record.Counts.reserve(NumCounters);
746-
Record.SingleByteCoverage = hasSingleByteCoverage();
747746
for (uint32_t I = 0; I < NumCounters; I++) {
748747
const char *Ptr =
749748
CountersStart + CounterBaseOffset + I * getCounterTypeSize();

0 commit comments

Comments
 (0)