Skip to content

Commit 1adf497

Browse files
committed
Eliminate (rewind) "refactor" changes
1 parent 5dfe3e7 commit 1adf497

File tree

7 files changed

+39
-58
lines changed

7 files changed

+39
-58
lines changed

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,19 @@ struct CountedRegion : public CounterMappingRegion {
370370
uint64_t FalseExecutionCount;
371371
bool TrueFolded;
372372
bool FalseFolded;
373+
bool HasSingleByteCoverage;
373374

374-
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount)
375+
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount,
376+
bool HasSingleByteCoverage)
375377
: CounterMappingRegion(R), ExecutionCount(ExecutionCount),
376-
FalseExecutionCount(0), TrueFolded(false), FalseFolded(true) {}
378+
FalseExecutionCount(0), TrueFolded(false), FalseFolded(true),
379+
HasSingleByteCoverage(HasSingleByteCoverage) {}
377380

378381
CountedRegion(const CounterMappingRegion &R, uint64_t ExecutionCount,
379-
uint64_t FalseExecutionCount)
382+
uint64_t FalseExecutionCount, bool HasSingleByteCoverage)
380383
: CounterMappingRegion(R), ExecutionCount(ExecutionCount),
381384
FalseExecutionCount(FalseExecutionCount), TrueFolded(false),
382-
FalseFolded(false) {}
385+
FalseFolded(false), HasSingleByteCoverage(HasSingleByteCoverage) {}
383386
};
384387

385388
/// MCDC Record grouping all information together.
@@ -722,9 +725,10 @@ struct FunctionRecord {
722725
}
723726

724727
void pushRegion(CounterMappingRegion Region, uint64_t Count,
725-
uint64_t FalseCount) {
728+
uint64_t FalseCount, bool HasSingleByteCoverage) {
726729
if (Region.isBranch()) {
727-
CountedBranchRegions.emplace_back(Region, Count, FalseCount);
730+
CountedBranchRegions.emplace_back(Region, Count, FalseCount,
731+
HasSingleByteCoverage);
728732
// If either counter is hard-coded to zero, then this region represents a
729733
// constant-folded branch.
730734
CountedBranchRegions.back().TrueFolded = Region.Count.isZero();
@@ -733,7 +737,8 @@ struct FunctionRecord {
733737
}
734738
if (CountedRegions.empty())
735739
ExecutionCount = Count;
736-
CountedRegions.emplace_back(Region, Count, FalseCount);
740+
CountedRegions.emplace_back(Region, Count, FalseCount,
741+
HasSingleByteCoverage);
737742
}
738743
};
739744

@@ -896,19 +901,14 @@ class CoverageData {
896901
std::vector<CountedRegion> BranchRegions;
897902
std::vector<MCDCRecord> MCDCRecords;
898903

899-
bool SingleByteCoverage;
900-
901904
public:
902-
CoverageData() = delete;
905+
CoverageData() = default;
903906

904-
CoverageData(bool Single, StringRef Filename = StringRef())
905-
: Filename(Filename), SingleByteCoverage(Single) {}
907+
CoverageData(StringRef Filename) : Filename(Filename) {}
906908

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

910-
bool getSingleByteCoverage() const { return SingleByteCoverage; }
911-
912912
/// Get an iterator over the coverage segments for this object. The segments
913913
/// are guaranteed to be uniqued and sorted by location.
914914
std::vector<CoverageSegment>::const_iterator begin() const {
@@ -941,9 +941,7 @@ class CoverageMapping {
941941
DenseMap<size_t, SmallVector<unsigned, 0>> FilenameHash2RecordIndices;
942942
std::vector<std::pair<std::string, uint64_t>> FuncHashMismatches;
943943

944-
bool SingleByteCoverage;
945-
946-
CoverageMapping(bool Single) : SingleByteCoverage(Single) {}
944+
CoverageMapping() = default;
947945

948946
// Load coverage records from readers.
949947
static Error loadFromReaders(
@@ -987,8 +985,6 @@ class CoverageMapping {
987985
const object::BuildIDFetcher *BIDFetcher = nullptr,
988986
bool CheckBinaryIDs = false);
989987

990-
bool getSingleByteCoverage() const { return SingleByteCoverage; }
991-
992988
/// The number of functions that couldn't have their profiles mapped.
993989
///
994990
/// This is a count of functions whose profile is out of date or otherwise

llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,7 @@ Error CoverageMapping::loadFromReaders(
983983
Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
984984
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
985985
IndexedInstrProfReader &ProfileReader) {
986-
auto Coverage = std::unique_ptr<CoverageMapping>(
987-
new CoverageMapping(ProfileReader.hasSingleByteCoverage()));
986+
auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
988987
if (Error E = loadFromReaders(CoverageReaders, ProfileReader, *Coverage))
989988
return std::move(E);
990989
return std::move(Coverage);
@@ -1046,8 +1045,7 @@ Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
10461045
if (Error E = ProfileReaderOrErr.takeError())
10471046
return createFileError(ProfileFilename, std::move(E));
10481047
auto ProfileReader = std::move(ProfileReaderOrErr.get());
1049-
auto Coverage = std::unique_ptr<CoverageMapping>(
1050-
new CoverageMapping(ProfileReader->hasSingleByteCoverage()));
1048+
auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
10511049
bool DataFound = false;
10521050

10531051
auto GetArch = [&](size_t Idx) {
@@ -1330,8 +1328,14 @@ class SegmentBuilder {
13301328
// value for that area.
13311329
// We add counts of the regions of the same kind as the active region
13321330
// to handle the both situations.
1333-
if (I->Kind == Active->Kind)
1334-
Active->ExecutionCount += I->ExecutionCount;
1331+
if (I->Kind == Active->Kind) {
1332+
assert(I->HasSingleByteCoverage == Active->HasSingleByteCoverage &&
1333+
"Regions are generated in different coverage modes");
1334+
if (I->HasSingleByteCoverage)
1335+
Active->ExecutionCount = Active->ExecutionCount || I->ExecutionCount;
1336+
else
1337+
Active->ExecutionCount += I->ExecutionCount;
1338+
}
13351339
}
13361340
return Regions.drop_back(std::distance(++Active, End));
13371341
}
@@ -1424,7 +1428,7 @@ static bool isExpansion(const CountedRegion &R, unsigned FileID) {
14241428
}
14251429

14261430
CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
1427-
CoverageData FileCoverage(SingleByteCoverage, Filename);
1431+
CoverageData FileCoverage(Filename);
14281432
std::vector<CountedRegion> Regions;
14291433

14301434
// Look up the function records in the given file. Due to hash collisions on
@@ -1486,10 +1490,9 @@ CoverageData
14861490
CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) const {
14871491
auto MainFileID = findMainViewFileID(Function);
14881492
if (!MainFileID)
1489-
return CoverageData(SingleByteCoverage);
1493+
return CoverageData();
14901494

1491-
CoverageData FunctionCoverage(SingleByteCoverage,
1492-
Function.Filenames[*MainFileID]);
1495+
CoverageData FunctionCoverage(Function.Filenames[*MainFileID]);
14931496
std::vector<CountedRegion> Regions;
14941497
for (const auto &CR : Function.CountedRegions)
14951498
if (CR.FileID == *MainFileID) {
@@ -1517,7 +1520,7 @@ CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) const {
15171520
CoverageData CoverageMapping::getCoverageForExpansion(
15181521
const ExpansionRecord &Expansion) const {
15191522
CoverageData ExpansionCoverage(
1520-
SingleByteCoverage, Expansion.Function.Filenames[Expansion.FileID]);
1523+
Expansion.Function.Filenames[Expansion.FileID]);
15211524
std::vector<CountedRegion> Regions;
15221525
for (const auto &CR : Expansion.Function.CountedRegions)
15231526
if (CR.FileID == Expansion.FileID) {

llvm/tools/llvm-cov/CodeCoverage.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,11 +1023,6 @@ int CodeCoverageTool::doShow(int argc, const char **argv,
10231023
cl::alias ShowOutputDirectoryA("o", cl::desc("Alias for --output-dir"),
10241024
cl::aliasopt(ShowOutputDirectory));
10251025

1026-
cl::opt<bool> BinaryCounters(
1027-
"binary-counters", cl::Optional,
1028-
cl::desc("Show 1/0 instead of actual counter values."),
1029-
cl::cat(ViewCategory));
1030-
10311026
cl::opt<uint32_t> TabSize(
10321027
"tab-size", cl::init(2),
10331028
cl::desc(
@@ -1105,7 +1100,6 @@ int CodeCoverageTool::doShow(int argc, const char **argv,
11051100
ViewOpts.ShowFunctionInstantiations = ShowInstantiations;
11061101
ViewOpts.ShowDirectoryCoverage = ShowDirectoryCoverage;
11071102
ViewOpts.ShowOutputDirectory = ShowOutputDirectory;
1108-
ViewOpts.BinaryCounters = BinaryCounters;
11091103
ViewOpts.TabSize = TabSize;
11101104
ViewOpts.ProjectTitle = ProjectTitle;
11111105

llvm/tools/llvm-cov/CoverageViewOptions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ struct CoverageViewOptions {
4545
bool SkipExpansions;
4646
bool SkipFunctions;
4747
bool SkipBranches;
48-
bool BinaryCounters;
4948
OutputFormat Format;
5049
BranchOutputType ShowBranches;
5150
std::string ShowOutputDirectory;

llvm/tools/llvm-cov/SourceCoverageView.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ class SourceCoverageView {
180180
/// on display.
181181
std::vector<InstantiationView> InstantiationSubViews;
182182

183-
bool BinaryCounters;
184-
185183
/// Get the first uncovered line number for the source file.
186184
unsigned getFirstUncoveredLineNo();
187185

@@ -268,10 +266,6 @@ class SourceCoverageView {
268266
/// digits.
269267
static std::string formatCount(uint64_t N);
270268

271-
uint64_t Count1(uint64_t N) const { return (N && BinaryCounters ? 1 : N); }
272-
273-
std::string formatCount1(uint64_t N) const { return formatCount(Count1(N)); }
274-
275269
/// Check if region marker output is expected for a line.
276270
bool shouldRenderRegionMarkers(const LineCoverageStats &LCS) const;
277271

@@ -282,9 +276,7 @@ class SourceCoverageView {
282276
const CoverageViewOptions &Options,
283277
CoverageData &&CoverageInfo)
284278
: SourceName(SourceName), File(File), Options(Options),
285-
CoverageInfo(std::move(CoverageInfo)),
286-
BinaryCounters(Options.BinaryCounters ||
287-
CoverageInfo.getSingleByteCoverage()) {}
279+
CoverageInfo(std::move(CoverageInfo)) {}
288280

289281
public:
290282
static std::unique_ptr<SourceCoverageView>

llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,22 +1019,19 @@ void SourceCoverageViewHTML::renderLine(raw_ostream &OS, LineRef L,
10191019
// Just consider the segments which start *and* end on this line.
10201020
for (unsigned I = 0, E = Segments.size() - 1; I < E; ++I) {
10211021
const auto *CurSeg = Segments[I];
1022-
auto CurSegCount = Count1(CurSeg->Count);
1023-
auto LCSCount = Count1(LCS.getExecutionCount());
10241022
if (!CurSeg->IsRegionEntry)
10251023
continue;
1026-
if (CurSegCount == LCSCount)
1024+
if (CurSeg->Count == LCS.getExecutionCount())
10271025
continue;
10281026

10291027
Snippets[I + 1] =
1030-
tag("div",
1031-
Snippets[I + 1] +
1032-
tag("span", formatCount(CurSegCount), "tooltip-content"),
1028+
tag("div", Snippets[I + 1] + tag("span", formatCount(CurSeg->Count),
1029+
"tooltip-content"),
10331030
"tooltip");
10341031

10351032
if (getOptions().Debug)
10361033
errs() << "Marker at " << CurSeg->Line << ":" << CurSeg->Col << " = "
1037-
<< formatCount(CurSegCount) << "\n";
1034+
<< formatCount(CurSeg->Count) << "\n";
10381035
}
10391036
}
10401037

@@ -1054,7 +1051,7 @@ void SourceCoverageViewHTML::renderLineCoverageColumn(
10541051
raw_ostream &OS, const LineCoverageStats &Line) {
10551052
std::string Count;
10561053
if (Line.isMapped())
1057-
Count = tag("pre", formatCount1(Line.getExecutionCount()));
1054+
Count = tag("pre", formatCount(Line.getExecutionCount()));
10581055
std::string CoverageClass =
10591056
(Line.getExecutionCount() > 0)
10601057
? "covered-line"
@@ -1109,7 +1106,7 @@ void SourceCoverageViewHTML::renderBranchView(raw_ostream &OS, BranchView &BRV,
11091106

11101107
OS << tag("span", Label, (Count ? "None" : "red branch")) << ": ";
11111108
if (getOptions().ShowBranchCounts)
1112-
OS << tag("span", formatCount1(Count),
1109+
OS << tag("span", formatCount(Count),
11131110
(Count ? "covered-line" : "uncovered-line"));
11141111
else
11151112
OS << format("%0.2f", (Total != 0 ? 100.0 * Count / Total : 0.0)) << "%";

llvm/tools/llvm-cov/SourceCoverageViewText.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void SourceCoverageViewText::renderLineCoverageColumn(
216216
OS.indent(LineCoverageColumnWidth) << '|';
217217
return;
218218
}
219-
std::string C = formatCount1(Line.getExecutionCount());
219+
std::string C = formatCount(Line.getExecutionCount());
220220
OS.indent(LineCoverageColumnWidth - C.size());
221221
colored_ostream(OS, raw_ostream::MAGENTA,
222222
Line.hasMultipleRegions() && getOptions().Colors)
@@ -263,7 +263,7 @@ void SourceCoverageViewText::renderRegionMarkers(raw_ostream &OS,
263263

264264
if (getOptions().Debug)
265265
errs() << "Marker at " << S->Line << ":" << S->Col << " = "
266-
<< formatCount1(S->Count) << "\n";
266+
<< formatCount(S->Count) << "\n";
267267
}
268268
OS << '\n';
269269
}
@@ -307,7 +307,7 @@ void SourceCoverageViewText::renderBranchView(raw_ostream &OS, BranchView &BRV,
307307
<< Label;
308308

309309
if (getOptions().ShowBranchCounts)
310-
OS << ": " << formatCount1(Count);
310+
OS << ": " << formatCount(Count);
311311
else
312312
OS << ": " << format("%0.2f", (Total != 0 ? 100.0 * Count / Total : 0.0))
313313
<< "%";

0 commit comments

Comments
 (0)