summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cov/SourceCoverageDataManager.cpp
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2014-08-22 22:56:03 +0000
committerAlex Lorenz <arphaman@gmail.com>2014-08-22 22:56:03 +0000
commite82d89cc37ceb69bcb35b911e2ca2119aa51a5e5 (patch)
treee00c23666c05940403bf9e156614ec16d3c11815 /llvm/tools/llvm-cov/SourceCoverageDataManager.cpp
parentec33fa9aca4dc1baaeffcd8876fb385e1f8cb86e (diff)
downloadbcm5719-llvm-e82d89cc37ceb69bcb35b911e2ca2119aa51a5e5.tar.gz
bcm5719-llvm-e82d89cc37ceb69bcb35b911e2ca2119aa51a5e5.zip
llvm-cov: add code coverage tool that's based on coverage mapping format and clang's pgo.
This commit expands llvm-cov's functionality by adding support for a new code coverage tool that uses LLVM's coverage mapping format and clang's instrumentation based profiling. The gcov compatible tool can be invoked by supplying the 'gcov' command as the first argument, or by modifying the tool's name to end with 'gcov'. Differential Revision: http://reviews.llvm.org/D4445 llvm-svn: 216300
Diffstat (limited to 'llvm/tools/llvm-cov/SourceCoverageDataManager.cpp')
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageDataManager.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/llvm/tools/llvm-cov/SourceCoverageDataManager.cpp b/llvm/tools/llvm-cov/SourceCoverageDataManager.cpp
new file mode 100644
index 00000000000..03382b266e7
--- /dev/null
+++ b/llvm/tools/llvm-cov/SourceCoverageDataManager.cpp
@@ -0,0 +1,57 @@
+//===- 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 MappingRegion &Region) {
+ SourceRange Range(Region.LineStart, Region.ColumnStart, Region.LineEnd,
+ Region.ColumnEnd);
+ if (Region.Kind == CounterMappingRegion::SkippedRegion) {
+ SkippedRegions.push_back(Range);
+ return;
+ }
+ Regions.push_back(std::make_pair(Range, Region.ExecutionCount));
+}
+
+ArrayRef<std::pair<SourceCoverageDataManager::SourceRange, uint64_t>>
+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;
+ });
+
+ // 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;
+ continue;
+ }
+ ++Prev;
+ *Prev = *I;
+ }
+ ++Prev;
+ Regions.erase(Prev, Regions.end());
+
+ Uniqued = true;
+ return Regions;
+}
OpenPOWER on IntegriCloud