diff options
author | Vedant Kumar <vsk@apple.com> | 2017-08-02 23:35:25 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-08-02 23:35:25 +0000 |
commit | a8dfa81a14129ecbed6ed759421ec5936bb684f3 (patch) | |
tree | b4b1f57bb8f11cb425e410be519dfc2a8513e0d4 /tools/llvm-cov/CodeCoverage.cpp | |
parent | f6b53455dfc6d257276e3f088d18fe7edb27c97d (diff) |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309904 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-cov/CodeCoverage.cpp')
-rw-r--r-- | tools/llvm-cov/CodeCoverage.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/tools/llvm-cov/CodeCoverage.cpp b/tools/llvm-cov/CodeCoverage.cpp index c16d7b44ad6..7098b51ce7d 100644 --- a/tools/llvm-cov/CodeCoverage.cpp +++ b/tools/llvm-cov/CodeCoverage.cpp @@ -291,25 +291,31 @@ CodeCoverageTool::createSourceFileView(StringRef SourceFile, if (!ViewOpts.ShowFunctionInstantiations) return View; - for (const auto *Function : Coverage.getInstantiations(SourceFile)) { - std::unique_ptr<SourceCoverageView> SubView{nullptr}; + for (const auto &Group : Coverage.getInstantiationGroups(SourceFile)) { + // Skip functions which have a single instantiation. + if (Group.size() < 2) + continue; - StringRef Funcname = DC.demangle(Function->Name); + for (const FunctionRecord *Function : Group.getInstantiations()) { + std::unique_ptr<SourceCoverageView> SubView{nullptr}; - if (Function->ExecutionCount > 0) { - auto SubViewCoverage = Coverage.getCoverageForFunction(*Function); - auto SubViewExpansions = SubViewCoverage.getExpansions(); - SubView = SourceCoverageView::create( - Funcname, SourceBuffer.get(), ViewOpts, std::move(SubViewCoverage)); - attachExpansionSubViews(*SubView, SubViewExpansions, Coverage); - } + StringRef Funcname = DC.demangle(Function->Name); - unsigned FileID = Function->CountedRegions.front().FileID; - unsigned Line = 0; - for (const auto &CR : Function->CountedRegions) - if (CR.FileID == FileID) - Line = std::max(CR.LineEnd, Line); - View->addInstantiation(Funcname, Line, std::move(SubView)); + if (Function->ExecutionCount > 0) { + auto SubViewCoverage = Coverage.getCoverageForFunction(*Function); + auto SubViewExpansions = SubViewCoverage.getExpansions(); + SubView = SourceCoverageView::create( + Funcname, SourceBuffer.get(), ViewOpts, std::move(SubViewCoverage)); + attachExpansionSubViews(*SubView, SubViewExpansions, Coverage); + } + + unsigned FileID = Function->CountedRegions.front().FileID; + unsigned Line = 0; + for (const auto &CR : Function->CountedRegions) + if (CR.FileID == FileID) + Line = std::max(CR.LineEnd, Line); + View->addInstantiation(Funcname, Line, std::move(SubView)); + } } return View; } |