From dde19c5a7362a08d0dcb8b692dae89ac6999ff2d Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Wed, 2 Aug 2017 23:35:25 +0000 Subject: [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 --- llvm/lib/ProfileData/Coverage/CoverageMapping.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'llvm/lib/ProfileData/Coverage') diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp index c435cb6ac84..346ac76a6f7 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp @@ -510,8 +510,8 @@ CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const { return FileCoverage; } -std::vector -CoverageMapping::getInstantiations(StringRef Filename) const { +std::vector +CoverageMapping::getInstantiationGroups(StringRef Filename) const { FunctionInstantiationSetCollector InstantiationSetCollector; for (const auto &Function : Functions) { auto MainFileID = findMainViewFileID(Filename, Function); @@ -520,12 +520,12 @@ CoverageMapping::getInstantiations(StringRef Filename) const { InstantiationSetCollector.insert(Function, *MainFileID); } - std::vector Result; + std::vector Result; for (const auto &InstantiationSet : InstantiationSetCollector) { - if (InstantiationSet.second.size() < 2) - continue; - Result.insert(Result.end(), InstantiationSet.second.begin(), - InstantiationSet.second.end()); + InstantiationGroup IG{InstantiationSet.first.first, + InstantiationSet.first.second, + std::move(InstantiationSet.second)}; + Result.emplace_back(std::move(IG)); } return Result; } -- cgit v1.2.3