summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cov/SourceCoverageDataManager.cpp
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-09-20 15:31:56 +0000
committerJustin Bogner <mail@justinbogner.com>2014-09-20 15:31:56 +0000
commit953e2407edb956eb846a79fc0dce08d032ea0d66 (patch)
tree617f3d06bf359ec67e4b312f2755e0453ce6cf9b /llvm/tools/llvm-cov/SourceCoverageDataManager.cpp
parentf584649ae397396016b1fbfc6fe8d8ea29e2ebf5 (diff)
downloadbcm5719-llvm-953e2407edb956eb846a79fc0dce08d032ea0d66.tar.gz
bcm5719-llvm-953e2407edb956eb846a79fc0dce08d032ea0d66.zip
llvm-cov: Disentangle the coverage data logic from the display (NFC)
This splits the logic for actually looking up coverage information from the logic that displays it. These were tangled rather thoroughly so this change is a bit large, but it mostly consists of moving things around. The coverage lookup logic itself now lives in the library, rather than being spread between the library and the tool. llvm-svn: 218184
Diffstat (limited to 'llvm/tools/llvm-cov/SourceCoverageDataManager.cpp')
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageDataManager.cpp104
1 files changed, 0 insertions, 104 deletions
diff --git a/llvm/tools/llvm-cov/SourceCoverageDataManager.cpp b/llvm/tools/llvm-cov/SourceCoverageDataManager.cpp
deleted file mode 100644
index a60ea6e2586..00000000000
--- a/llvm/tools/llvm-cov/SourceCoverageDataManager.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-//===- SourceCoverageDataManager.cpp - Manager for source file coverage
-// data-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This class separates and merges mapping regions for a specific source file.
-//
-//===----------------------------------------------------------------------===//
-
-#include "SourceCoverageDataManager.h"
-
-using namespace llvm;
-using namespace coverage;
-
-void SourceCoverageDataManager::insert(const CountedRegion &CR) {
- Regions.push_back(CR);
- Segments.clear();
-}
-
-namespace {
-class SegmentBuilder {
- std::vector<CoverageSegment> Segments;
- SmallVector<const CountedRegion *, 8> ActiveRegions;
-
- /// Start a segment with no count specified.
- void startSegment(unsigned Line, unsigned Col, bool IsRegionEntry) {
- Segments.emplace_back(Line, Col, IsRegionEntry);
- }
-
- /// Start a segment with the given Region's count.
- void startSegment(unsigned Line, unsigned Col, bool IsRegionEntry,
- const CountedRegion &Region) {
- if (Segments.empty())
- Segments.emplace_back(Line, Col, IsRegionEntry);
- CoverageSegment S = Segments.back();
- // Avoid creating empty regions.
- if (S.Line != Line || S.Col != Col) {
- Segments.emplace_back(Line, Col, IsRegionEntry);
- S = Segments.back();
- }
- // Set this region's count.
- if (Region.Kind != coverage::CounterMappingRegion::SkippedRegion)
- Segments.back().setCount(Region.ExecutionCount);
- }
-
- /// Start a segment for the given region.
- void startSegment(const CountedRegion &Region) {
- startSegment(Region.LineStart, Region.ColumnStart, true, Region);
- }
-
- /// Pop the top region off of the active stack, starting a new segment with
- /// the containing Region's count.
- void popRegion() {
- const CountedRegion *Active = ActiveRegions.back();
- unsigned Line = Active->LineEnd, Col = Active->ColumnEnd;
- ActiveRegions.pop_back();
- if (ActiveRegions.empty())
- startSegment(Line, Col, /*IsRegionEntry=*/false);
- else
- startSegment(Line, Col, /*IsRegionEntry=*/false, *ActiveRegions.back());
- }
-
-public:
- /// Build a list of CoverageSegments from a sorted list of Regions.
- std::vector<CoverageSegment>
- buildSegments(ArrayRef<CountedRegion> Regions) {
- for (const auto &Region : Regions) {
- // Pop any regions that end before this one starts.
- while (!ActiveRegions.empty() &&
- ActiveRegions.back()->endLoc() <= Region.startLoc())
- popRegion();
- // Add this region to the stack.
- ActiveRegions.push_back(&Region);
- startSegment(Region);
- }
- // Pop any regions that are left in the stack.
- while (!ActiveRegions.empty())
- popRegion();
- return Segments;
- }
-};
-}
-
-ArrayRef<CoverageSegment> SourceCoverageDataManager::getCoverageSegments() {
- if (Segments.empty()) {
- // Sort the regions given that they're all in the same file at this point.
- std::sort(Regions.begin(), Regions.end(),
- [](const CountedRegion &LHS, const CountedRegion &RHS) {
- if (LHS.startLoc() == RHS.startLoc())
- // When LHS completely contains RHS, we sort LHS first.
- return RHS.endLoc() < LHS.endLoc();
- return LHS.startLoc() < RHS.startLoc();
- });
-
- Segments = SegmentBuilder().buildSegments(Regions);
- }
-
- return Segments;
-}
OpenPOWER on IntegriCloud