2014-08-23 00:56:03 +02:00
|
|
|
//===- CoverageSummaryInfo.cpp - Coverage summary for function/file -------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// These structures are used to represent code coverage metrics
|
|
|
|
// for functions/files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CoverageSummaryInfo.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace coverage;
|
|
|
|
|
|
|
|
FunctionCoverageSummary
|
2014-09-20 17:31:56 +02:00
|
|
|
FunctionCoverageSummary::get(const coverage::FunctionRecord &Function) {
|
2014-08-23 00:56:03 +02:00
|
|
|
// Compute the region coverage
|
|
|
|
size_t NumCodeRegions = 0, CoveredRegions = 0;
|
2014-09-09 07:32:14 +02:00
|
|
|
for (auto &CR : Function.CountedRegions) {
|
|
|
|
if (CR.Kind != CounterMappingRegion::CodeRegion)
|
2014-08-23 00:56:03 +02:00
|
|
|
continue;
|
|
|
|
++NumCodeRegions;
|
2014-09-09 07:32:14 +02:00
|
|
|
if (CR.ExecutionCount != 0)
|
2014-08-23 00:56:03 +02:00
|
|
|
++CoveredRegions;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the line coverage
|
|
|
|
size_t NumLines = 0, CoveredLines = 0;
|
|
|
|
for (unsigned FileID = 0, E = Function.Filenames.size(); FileID < E;
|
|
|
|
++FileID) {
|
|
|
|
// Find the line start and end of the function's source code
|
|
|
|
// in that particular file
|
|
|
|
unsigned LineStart = std::numeric_limits<unsigned>::max();
|
|
|
|
unsigned LineEnd = 0;
|
2014-09-09 07:32:14 +02:00
|
|
|
for (auto &CR : Function.CountedRegions) {
|
|
|
|
if (CR.FileID != FileID)
|
2014-08-23 00:56:03 +02:00
|
|
|
continue;
|
2014-09-09 07:32:14 +02:00
|
|
|
LineStart = std::min(LineStart, CR.LineStart);
|
|
|
|
LineEnd = std::max(LineEnd, CR.LineEnd);
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
|
|
|
unsigned LineCount = LineEnd - LineStart + 1;
|
|
|
|
|
|
|
|
// Get counters
|
|
|
|
llvm::SmallVector<uint64_t, 16> ExecutionCounts;
|
|
|
|
ExecutionCounts.resize(LineCount, 0);
|
2014-09-09 07:32:14 +02:00
|
|
|
for (auto &CR : Function.CountedRegions) {
|
|
|
|
if (CR.FileID != FileID)
|
2014-08-23 00:56:03 +02:00
|
|
|
continue;
|
|
|
|
// Ignore the lines that were skipped by the preprocessor.
|
2014-09-09 07:32:14 +02:00
|
|
|
auto ExecutionCount = CR.ExecutionCount;
|
|
|
|
if (CR.Kind == CounterMappingRegion::SkippedRegion) {
|
|
|
|
LineCount -= CR.LineEnd - CR.LineStart + 1;
|
2014-08-23 00:56:03 +02:00
|
|
|
ExecutionCount = 1;
|
|
|
|
}
|
2014-09-09 07:32:14 +02:00
|
|
|
for (unsigned I = CR.LineStart; I <= CR.LineEnd; ++I)
|
2014-08-23 00:56:03 +02:00
|
|
|
ExecutionCounts[I - LineStart] = ExecutionCount;
|
|
|
|
}
|
|
|
|
CoveredLines += LineCount - std::count(ExecutionCounts.begin(),
|
|
|
|
ExecutionCounts.end(), 0);
|
|
|
|
NumLines += LineCount;
|
|
|
|
}
|
|
|
|
return FunctionCoverageSummary(
|
2014-09-30 14:45:13 +02:00
|
|
|
Function.Name, Function.ExecutionCount,
|
|
|
|
RegionCoverageInfo(CoveredRegions, NumCodeRegions),
|
2014-08-23 00:56:03 +02:00
|
|
|
LineCoverageInfo(CoveredLines, 0, NumLines));
|
|
|
|
}
|