[llvm] r217417 - llvm-cov: Combine two types that were nearly identical (NFC)
Justin Bogner
mail at justinbogner.com
Mon Sep 8 22:32:18 PDT 2014
Author: bogner
Date: Tue Sep 9 00:32:18 2014
New Revision: 217417
URL: http://llvm.org/viewvc/llvm-project?rev=217417&view=rev
Log:
llvm-cov: Combine two types that were nearly identical (NFC)
llvm-cov had a SourceRange type that was nearly identical to a
CountedRegion except that it shaved off a couple of fields. There
aren't likely to be enough of these for the minor memory savings to be
worth the extra complexity here.
Modified:
llvm/trunk/include/llvm/ProfileData/CoverageMapping.h
llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.cpp
llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.h
llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
Modified: llvm/trunk/include/llvm/ProfileData/CoverageMapping.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/CoverageMapping.h?rev=217417&r1=217416&r2=217417&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/CoverageMapping.h (original)
+++ llvm/trunk/include/llvm/ProfileData/CoverageMapping.h Tue Sep 9 00:32:18 2014
@@ -171,6 +171,26 @@ struct CounterMappingRegion {
return ColumnStart < Other.ColumnStart;
return LineStart < Other.LineStart;
}
+
+ bool coversSameSource(const CounterMappingRegion &Other) const {
+ return FileID == Other.FileID &&
+ LineStart == Other.LineStart &&
+ ColumnStart == Other.ColumnStart &&
+ LineEnd == Other.LineEnd &&
+ ColumnEnd == Other.ColumnEnd;
+ }
+
+ bool contains(const CounterMappingRegion &Other) const {
+ if (FileID != Other.FileID)
+ return false;
+ if (LineStart > Other.LineStart ||
+ (LineStart == Other.LineStart && ColumnStart > Other.ColumnStart))
+ return false;
+ if (LineEnd < Other.LineEnd ||
+ (LineEnd == Other.LineEnd && ColumnEnd < Other.ColumnEnd))
+ return false;
+ return true;
+ }
};
/// \brief Associates a source range with an execution count.
Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=217417&r1=217416&r2=217417&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Tue Sep 9 00:32:18 2014
@@ -36,8 +36,9 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/PrettyStackTrace.h"
-#include <system_error>
#include <functional>
+#include <system_error>
+#include <unordered_map>
using namespace llvm;
using namespace coverage;
Modified: llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.cpp?rev=217417&r1=217416&r2=217417&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.cpp Tue Sep 9 00:32:18 2014
@@ -18,31 +18,22 @@ using namespace llvm;
using namespace coverage;
void SourceCoverageDataManager::insert(const CountedRegion &CR) {
- SourceRange Range(CR.LineStart, CR.ColumnStart, CR.LineEnd, CR.ColumnEnd);
- if (CR.Kind == CounterMappingRegion::SkippedRegion) {
- SkippedRegions.push_back(Range);
- return;
- }
- Regions.push_back(std::make_pair(Range, CR.ExecutionCount));
+ Regions.push_back(CR);
+ Uniqued = false;
}
-ArrayRef<std::pair<SourceCoverageDataManager::SourceRange, uint64_t>>
-SourceCoverageDataManager::getSourceRegions() {
+ArrayRef<CountedRegion> SourceCoverageDataManager::getSourceRegions() {
if (Uniqued || Regions.size() <= 1)
return Regions;
// Sort.
- std::sort(Regions.begin(), Regions.end(),
- [](const std::pair<SourceRange, uint64_t> &LHS,
- const std::pair<SourceRange, uint64_t> &RHS) {
- return LHS.first < RHS.first;
- });
+ std::sort(Regions.begin(), Regions.end());
// Merge duplicate source ranges and sum their execution counts.
auto Prev = Regions.begin();
for (auto I = Prev + 1, E = Regions.end(); I != E; ++I) {
- if (I->first == Prev->first) {
- Prev->second += I->second;
+ if (I->coversSameSource(*Prev)) {
+ Prev->ExecutionCount += I->ExecutionCount;
continue;
}
++Prev;
Modified: llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.h?rev=217417&r1=217416&r2=217417&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.h Tue Sep 9 00:32:18 2014
@@ -16,49 +16,14 @@
#include "FunctionCoverageMapping.h"
#include "llvm/ProfileData/CoverageMapping.h"
-#include "llvm/ADT/Hashing.h"
#include <vector>
-#include <unordered_map>
namespace llvm {
/// \brief Partions mapping regions by their kind and sums
/// the execution counts of the regions that start at the same location.
class SourceCoverageDataManager {
-public:
- struct SourceRange {
- unsigned LineStart, ColumnStart, LineEnd, ColumnEnd;
-
- SourceRange(unsigned LineStart, unsigned ColumnStart, unsigned LineEnd,
- unsigned ColumnEnd)
- : LineStart(LineStart), ColumnStart(ColumnStart), LineEnd(LineEnd),
- ColumnEnd(ColumnEnd) {}
-
- bool operator==(const SourceRange &Other) const {
- return LineStart == Other.LineStart && ColumnStart == Other.ColumnStart &&
- LineEnd == Other.LineEnd && ColumnEnd == Other.ColumnEnd;
- }
-
- bool operator<(const SourceRange &Other) const {
- if (LineStart == Other.LineStart)
- return ColumnStart < Other.ColumnStart;
- return LineStart < Other.LineStart;
- }
-
- bool contains(const SourceRange &Other) {
- if (LineStart > Other.LineStart ||
- (LineStart == Other.LineStart && ColumnStart > Other.ColumnStart))
- return false;
- if (LineEnd < Other.LineEnd ||
- (LineEnd == Other.LineEnd && ColumnEnd < Other.ColumnEnd))
- return false;
- return true;
- }
- };
-
-protected:
- std::vector<std::pair<SourceRange, uint64_t>> Regions;
- std::vector<SourceRange> SkippedRegions;
+ std::vector<coverage::CountedRegion> Regions;
bool Uniqued;
public:
@@ -66,12 +31,8 @@ public:
void insert(const coverage::CountedRegion &CR);
- /// \brief Return the source ranges and execution counts
- /// obtained from the non-skipped mapping regions.
- ArrayRef<std::pair<SourceRange, uint64_t>> getSourceRegions();
-
- /// \brief Return the source ranges obtained from the skipped mapping regions.
- ArrayRef<SourceRange> getSkippedRegions() const { return SkippedRegions; }
+ /// \brief Return the source regions in order of first to last occurring.
+ ArrayRef<coverage::CountedRegion> getSourceRegions();
};
} // namespace llvm
Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp?rev=217417&r1=217416&r2=217417&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp Tue Sep 9 00:32:18 2014
@@ -320,51 +320,49 @@ void SourceCoverageView::render(raw_ostr
void
SourceCoverageView::createLineCoverageInfo(SourceCoverageDataManager &Data) {
LineStats.resize(LineCount);
- for (const auto &Region : Data.getSourceRegions()) {
- auto Value = Region.second;
- LineStats[Region.first.LineStart - LineStart].addRegionStartCount(Value);
- for (unsigned Line = Region.first.LineStart + 1;
- Line <= Region.first.LineEnd; ++Line)
- LineStats[Line - LineStart].addRegionCount(Value);
- }
-
- // Reset the line stats for skipped regions.
- for (const auto &Region : Data.getSkippedRegions()) {
- for (unsigned Line = Region.LineStart; Line <= Region.LineEnd; ++Line)
- LineStats[Line - LineStart] = LineCoverageInfo();
+ for (const auto &CR : Data.getSourceRegions()) {
+ if (CR.Kind == coverage::CounterMappingRegion::SkippedRegion) {
+ // Reset the line stats for skipped regions.
+ for (unsigned Line = CR.LineStart; Line <= CR.LineEnd;
+ ++Line)
+ LineStats[Line - LineStart] = LineCoverageInfo();
+ continue;
+ }
+ LineStats[CR.LineStart - LineStart].addRegionStartCount(CR.ExecutionCount);
+ for (unsigned Line = CR.LineStart + 1; Line <= CR.LineEnd; ++Line)
+ LineStats[Line - LineStart].addRegionCount(CR.ExecutionCount);
}
}
void
SourceCoverageView::createHighlightRanges(SourceCoverageDataManager &Data) {
- auto Regions = Data.getSourceRegions();
+ auto CountedRegions = Data.getSourceRegions();
std::vector<bool> AlreadyHighlighted;
- AlreadyHighlighted.resize(Regions.size(), false);
+ AlreadyHighlighted.resize(CountedRegions.size(), false);
- for (size_t I = 0, S = Regions.size(); I < S; ++I) {
- const auto &Region = Regions[I];
- auto Value = Region.second;
- auto SrcRange = Region.first;
- if (Value != 0)
+ for (size_t I = 0, S = CountedRegions.size(); I < S; ++I) {
+ const auto &CR = CountedRegions[I];
+ if (CR.Kind == coverage::CounterMappingRegion::SkippedRegion ||
+ CR.ExecutionCount != 0)
continue;
if (AlreadyHighlighted[I])
continue;
for (size_t J = 0; J < S; ++J) {
- if (SrcRange.contains(Regions[J].first)) {
+ if (CR.contains(CountedRegions[J])) {
AlreadyHighlighted[J] = true;
}
}
- if (SrcRange.LineStart == SrcRange.LineEnd) {
+ if (CR.LineStart == CR.LineEnd) {
HighlightRanges.push_back(HighlightRange(
- SrcRange.LineStart, SrcRange.ColumnStart, SrcRange.ColumnEnd));
+ CR.LineStart, CR.ColumnStart, CR.ColumnEnd));
continue;
}
HighlightRanges.push_back(
- HighlightRange(SrcRange.LineStart, SrcRange.ColumnStart,
+ HighlightRange(CR.LineStart, CR.ColumnStart,
std::numeric_limits<unsigned>::max()));
HighlightRanges.push_back(
- HighlightRange(SrcRange.LineEnd, 1, SrcRange.ColumnEnd));
- for (unsigned Line = SrcRange.LineStart + 1; Line < SrcRange.LineEnd;
+ HighlightRange(CR.LineEnd, 1, CR.ColumnEnd));
+ for (unsigned Line = CR.LineStart + 1; Line < CR.LineEnd;
++Line) {
HighlightRanges.push_back(
HighlightRange(Line, 1, std::numeric_limits<unsigned>::max()));
@@ -387,10 +385,12 @@ SourceCoverageView::createHighlightRange
}
void SourceCoverageView::createRegionMarkers(SourceCoverageDataManager &Data) {
- for (const auto &Region : Data.getSourceRegions()) {
- if (Region.first.LineStart >= LineStart)
- Markers.push_back(RegionMarker(Region.first.LineStart,
- Region.first.ColumnStart, Region.second));
+ for (const auto &CR : Data.getSourceRegions()) {
+ if (CR.Kind == coverage::CounterMappingRegion::SkippedRegion)
+ continue;
+ if (CR.LineStart >= LineStart)
+ Markers.push_back(
+ RegionMarker(CR.LineStart, CR.ColumnStart, CR.ExecutionCount));
}
if (Options.Debug) {
More information about the llvm-commits
mailing list