summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cov
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-09-09 05:32:18 +0000
committerJustin Bogner <mail@justinbogner.com>2014-09-09 05:32:18 +0000
commite53be0662adacb2a98b17d2375d781d0ce819805 (patch)
treeb0224c95482f5e145438c434f8b9d4cb47b1c6b3 /llvm/tools/llvm-cov
parent8e8aa3ff90448eea2a0ad69368062f87c7fd4058 (diff)
downloadbcm5719-llvm-e53be0662adacb2a98b17d2375d781d0ce819805.tar.gz
bcm5719-llvm-e53be0662adacb2a98b17d2375d781d0ce819805.zip
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. llvm-svn: 217417
Diffstat (limited to 'llvm/tools/llvm-cov')
-rw-r--r--llvm/tools/llvm-cov/CodeCoverage.cpp3
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageDataManager.cpp21
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageDataManager.h45
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageView.cpp58
4 files changed, 40 insertions, 87 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index 6abeef39bab..549af92f918 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -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;
diff --git a/llvm/tools/llvm-cov/SourceCoverageDataManager.cpp b/llvm/tools/llvm-cov/SourceCoverageDataManager.cpp
index 4c4d7c038d6..f64162822ab 100644
--- a/llvm/tools/llvm-cov/SourceCoverageDataManager.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageDataManager.cpp
@@ -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;
diff --git a/llvm/tools/llvm-cov/SourceCoverageDataManager.h b/llvm/tools/llvm-cov/SourceCoverageDataManager.h
index 148ff947ff7..1c87266e0c4 100644
--- a/llvm/tools/llvm-cov/SourceCoverageDataManager.h
+++ b/llvm/tools/llvm-cov/SourceCoverageDataManager.h
@@ -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
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp
index 7f33b774ebd..94e963aa6e8 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp
@@ -320,51 +320,49 @@ void SourceCoverageView::render(raw_ostream &OS, unsigned Offset) {
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::createHighlightRanges(SourceCoverageDataManager &Data) {
}
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) {
OpenPOWER on IntegriCloud