summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cov/CoverageReport.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2017-08-02 23:35:25 +0000
committerVedant Kumar <vsk@apple.com>2017-08-02 23:35:25 +0000
commitdde19c5a7362a08d0dcb8b692dae89ac6999ff2d (patch)
tree5a673f7b60f71ec5df44e08c4fa8032daab3e63c /llvm/tools/llvm-cov/CoverageReport.cpp
parent79554e450e184160084c9abe90fe865735890477 (diff)
downloadbcm5719-llvm-dde19c5a7362a08d0dcb8b692dae89ac6999ff2d.tar.gz
bcm5719-llvm-dde19c5a7362a08d0dcb8b692dae89ac6999ff2d.zip
[Coverage] Add an API to retrive all instantiations of a function (NFC)
The CoverageMapping::getInstantiations() API retrieved all function records corresponding to functions with more than one instantiation (e.g template functions with multiple specializations). However, there was no simple way to determine *which* function a given record was an instantiation of. This was an oversight, since it's useful to aggregate coverage information over all instantiations of a function. llvm-cov works around this by building a mapping of source locations to instantiation sets, but this duplicates logic that libCoverage already has (see FunctionInstantiationSetCollector). This change adds a new API, CoverageMapping::getInstantiationGroups(), which returns a list of InstantiationGroups. A group contains records for each instantiation of some particular function, and also provides utilities to get the total execution count within the group, the source location of the common definition, etc. This lets removes some hacky logic in llvm-cov by reusing FunctionInstantiationSetCollector and makes the CoverageMapping API friendlier for other clients. llvm-svn: 309904
Diffstat (limited to 'llvm/tools/llvm-cov/CoverageReport.cpp')
-rw-r--r--llvm/tools/llvm-cov/CoverageReport.cpp30
1 files changed, 12 insertions, 18 deletions
diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp
index c68bb9048df..7c273a2430c 100644
--- a/llvm/tools/llvm-cov/CoverageReport.cpp
+++ b/llvm/tools/llvm-cov/CoverageReport.cpp
@@ -317,25 +317,19 @@ CoverageReport::prepareFileReports(const coverage::CoverageMapping &Coverage,
for (StringRef Filename : Files) {
FileCoverageSummary Summary(Filename.drop_front(LCP));
- // Map source locations to aggregate function coverage summaries.
- DenseMap<std::pair<unsigned, unsigned>, FunctionCoverageSummary> Summaries;
-
- for (const auto &F : Coverage.getCoveredFunctions(Filename)) {
- FunctionCoverageSummary Function = FunctionCoverageSummary::get(F);
- auto StartLoc = F.CountedRegions[0].startLoc();
-
- auto UniquedSummary = Summaries.insert({StartLoc, Function});
- if (!UniquedSummary.second)
- UniquedSummary.first->second.update(Function);
-
- Summary.addInstantiation(Function);
- Totals.addInstantiation(Function);
- }
+ for (const auto &Group : Coverage.getInstantiationGroups(Filename)) {
+ std::vector<FunctionCoverageSummary> InstantiationSummaries;
+ for (const coverage::FunctionRecord *F : Group.getInstantiations()) {
+ auto InstantiationSummary = FunctionCoverageSummary::get(*F);
+ Summary.addInstantiation(InstantiationSummary);
+ Totals.addInstantiation(InstantiationSummary);
+ InstantiationSummaries.push_back(InstantiationSummary);
+ }
- for (const auto &UniquedSummary : Summaries) {
- const FunctionCoverageSummary &FCS = UniquedSummary.second;
- Summary.addFunction(FCS);
- Totals.addFunction(FCS);
+ auto GroupSummary =
+ FunctionCoverageSummary::get(Group, InstantiationSummaries);
+ Summary.addFunction(GroupSummary);
+ Totals.addFunction(GroupSummary);
}
FileReports.push_back(Summary);
OpenPOWER on IntegriCloud