#ifndef LLVM_COV_COVERAGESUMMARYINFO_H
#define LLVM_COV_COVERAGESUMMARYINFO_H
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
class RegionCoverageInfo {
size_t Covered;
size_t NumRegions;
public:
RegionCoverageInfo() : Covered(0), NumRegions(0) {}
RegionCoverageInfo(size_t Covered, size_t NumRegions)
: Covered(Covered), NumRegions(NumRegions) {
assert(Covered <= NumRegions && "Covered regions over-counted");
}
RegionCoverageInfo &operator+=(const RegionCoverageInfo &RHS) {
Covered += RHS.Covered;
NumRegions += RHS.NumRegions;
return *this;
}
void merge(const RegionCoverageInfo &RHS) {
Covered = std::max(Covered, RHS.Covered);
NumRegions = std::max(NumRegions, RHS.NumRegions);
}
size_t getCovered() const { return Covered; }
size_t getNumRegions() const { return NumRegions; }
bool isFullyCovered() const { return Covered == NumRegions; }
double getPercentCovered() const {
assert(Covered <= NumRegions && "Covered regions over-counted");
if (NumRegions == 0)
return 0.0;
return double(Covered) / double(NumRegions) * 100.0;
}
};
class LineCoverageInfo {
size_t Covered;
size_t NumLines;
public:
LineCoverageInfo() : Covered(0), NumLines(0) {}
LineCoverageInfo(size_t Covered, size_t NumLines)
: Covered(Covered), NumLines(NumLines) {
assert(Covered <= NumLines && "Covered lines over-counted");
}
LineCoverageInfo &operator+=(const LineCoverageInfo &RHS) {
Covered += RHS.Covered;
NumLines += RHS.NumLines;
return *this;
}
void merge(const LineCoverageInfo &RHS) {
Covered = std::max(Covered, RHS.Covered);
NumLines = std::max(NumLines, RHS.NumLines);
}
size_t getCovered() const { return Covered; }
size_t getNumLines() const { return NumLines; }
bool isFullyCovered() const { return Covered == NumLines; }
double getPercentCovered() const {
assert(Covered <= NumLines && "Covered lines over-counted");
if (NumLines == 0)
return 0.0;
return double(Covered) / double(NumLines) * 100.0;
}
};
class BranchCoverageInfo {
size_t Covered;
size_t NumBranches;
public:
BranchCoverageInfo() : Covered(0), NumBranches(0) {}
BranchCoverageInfo(size_t Covered, size_t NumBranches)
: Covered(Covered), NumBranches(NumBranches) {
assert(Covered <= NumBranches && "Covered branches over-counted");
}
BranchCoverageInfo &operator+=(const BranchCoverageInfo &RHS) {
Covered += RHS.Covered;
NumBranches += RHS.NumBranches;
return *this;
}
void merge(const BranchCoverageInfo &RHS) {
Covered = std::max(Covered, RHS.Covered);
NumBranches = std::max(NumBranches, RHS.NumBranches);
}
size_t getCovered() const { return Covered; }
size_t getNumBranches() const { return NumBranches; }
bool isFullyCovered() const { return Covered == NumBranches; }
double getPercentCovered() const {
assert(Covered <= NumBranches && "Covered branches over-counted");
if (NumBranches == 0)
return 0.0;
return double(Covered) / double(NumBranches) * 100.0;
}
};
class FunctionCoverageInfo {
size_t Executed;
size_t NumFunctions;
public:
FunctionCoverageInfo() : Executed(0), NumFunctions(0) {}
FunctionCoverageInfo(size_t Executed, size_t NumFunctions)
: Executed(Executed), NumFunctions(NumFunctions) {}
FunctionCoverageInfo &operator+=(const FunctionCoverageInfo &RHS) {
Executed += RHS.Executed;
NumFunctions += RHS.NumFunctions;
return *this;
}
void addFunction(bool Covered) {
if (Covered)
++Executed;
++NumFunctions;
}
size_t getExecuted() const { return Executed; }
size_t getNumFunctions() const { return NumFunctions; }
bool isFullyCovered() const { return Executed == NumFunctions; }
double getPercentCovered() const {
assert(Executed <= NumFunctions && "Covered functions over-counted");
if (NumFunctions == 0)
return 0.0;
return double(Executed) / double(NumFunctions) * 100.0;
}
};
struct FunctionCoverageSummary {
std::string Name;
uint64_t ExecutionCount;
RegionCoverageInfo RegionCoverage;
LineCoverageInfo LineCoverage;
BranchCoverageInfo BranchCoverage;
FunctionCoverageSummary(const std::string &Name)
: Name(Name), ExecutionCount(0) {}
FunctionCoverageSummary(const std::string &Name, uint64_t ExecutionCount,
const RegionCoverageInfo &RegionCoverage,
const LineCoverageInfo &LineCoverage,
const BranchCoverageInfo &BranchCoverage)
: Name(Name), ExecutionCount(ExecutionCount),
RegionCoverage(RegionCoverage), LineCoverage(LineCoverage),
BranchCoverage(BranchCoverage) {}
static FunctionCoverageSummary get(const coverage::CoverageMapping &CM,
const coverage::FunctionRecord &Function);
static FunctionCoverageSummary
get(const coverage::InstantiationGroup &Group,
ArrayRef<FunctionCoverageSummary> Summaries);
};
struct FileCoverageSummary {
StringRef Name;
RegionCoverageInfo RegionCoverage;
LineCoverageInfo LineCoverage;
BranchCoverageInfo BranchCoverage;
FunctionCoverageInfo FunctionCoverage;
FunctionCoverageInfo InstantiationCoverage;
FileCoverageSummary(StringRef Name) : Name(Name) {}
FileCoverageSummary &operator+=(const FileCoverageSummary &RHS) {
RegionCoverage += RHS.RegionCoverage;
LineCoverage += RHS.LineCoverage;
FunctionCoverage += RHS.FunctionCoverage;
BranchCoverage += RHS.BranchCoverage;
InstantiationCoverage += RHS.InstantiationCoverage;
return *this;
}
void addFunction(const FunctionCoverageSummary &Function) {
RegionCoverage += Function.RegionCoverage;
LineCoverage += Function.LineCoverage;
BranchCoverage += Function.BranchCoverage;
FunctionCoverage.addFunction(Function.ExecutionCount > 0);
}
void addInstantiation(const FunctionCoverageSummary &Function) {
InstantiationCoverage.addFunction(Function.ExecutionCount > 0);
}
};
struct DemangleCache {
StringMap<std::string> DemangledNames;
StringRef demangle(StringRef Sym) const {
const auto DemangledName = DemangledNames.find(Sym);
if (DemangledName == DemangledNames.end())
return Sym;
return DemangledName->getValue();
}
};
}
#endif