[llvm] 3d9f968 - llvm-cov: Split out `sumRegions()` from `FunctionCoverageSummary::get()`. NFC.

NAKAMURA Takumi via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 26 21:39:07 PST 2024


Author: NAKAMURA Takumi
Date: 2024-12-27T14:37:01+09:00
New Revision: 3d9f9684a56ff049b5d5454bdb73f406c5af3959

URL: https://github.com/llvm/llvm-project/commit/3d9f9684a56ff049b5d5454bdb73f406c5af3959
DIFF: https://github.com/llvm/llvm-project/commit/3d9f9684a56ff049b5d5454bdb73f406c5af3959.diff

LOG: llvm-cov: Split out `sumRegions()` from `FunctionCoverageSummary::get()`. NFC.

Added: 
    

Modified: 
    llvm/tools/llvm-cov/CoverageSummaryInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp b/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp
index 58e7918d392709..ad7561d3dc62c0 100644
--- a/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp
+++ b/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp
@@ -59,12 +59,11 @@ sumMCDCPairs(const ArrayRef<MCDCRecord> &Records) {
   return {NumPairs, CoveredPairs};
 }
 
-FunctionCoverageSummary
-FunctionCoverageSummary::get(const CoverageMapping &CM,
-                             const coverage::FunctionRecord &Function) {
+static std::pair<RegionCoverageInfo, LineCoverageInfo>
+sumRegions(ArrayRef<CountedRegion> CodeRegions, const CoverageData &CD) {
   // Compute the region coverage.
   size_t NumCodeRegions = 0, CoveredRegions = 0;
-  for (auto &CR : Function.CountedRegions) {
+  for (auto &CR : CodeRegions) {
     if (CR.Kind != CounterMappingRegion::CodeRegion)
       continue;
     ++NumCodeRegions;
@@ -74,7 +73,6 @@ FunctionCoverageSummary::get(const CoverageMapping &CM,
 
   // Compute the line coverage
   size_t NumLines = 0, CoveredLines = 0;
-  CoverageData CD = CM.getCoverageForFunction(Function);
   for (const auto &LCS : getLineCoverageStats(CD)) {
     if (!LCS.isMapped())
       continue;
@@ -83,6 +81,16 @@ FunctionCoverageSummary::get(const CoverageMapping &CM,
       ++CoveredLines;
   }
 
+  return {RegionCoverageInfo(CoveredRegions, NumCodeRegions),
+          LineCoverageInfo(CoveredLines, NumLines)};
+}
+
+FunctionCoverageSummary
+FunctionCoverageSummary::get(const CoverageMapping &CM,
+                             const coverage::FunctionRecord &Function) {
+  CoverageData CD = CM.getCoverageForFunction(Function);
+  auto [RegionCoverage, LineCoverage] = sumRegions(Function.CountedRegions, CD);
+
   // Compute the branch coverage, including branches from expansions.
   size_t NumBranches = 0, CoveredBranches = 0;
   sumBranches(NumBranches, CoveredBranches, CD.getBranches());
@@ -92,9 +100,7 @@ FunctionCoverageSummary::get(const CoverageMapping &CM,
   std::tie(NumPairs, CoveredPairs) = sumMCDCPairs(CD.getMCDCRecords());
 
   return FunctionCoverageSummary(
-      Function.Name, Function.ExecutionCount,
-      RegionCoverageInfo(CoveredRegions, NumCodeRegions),
-      LineCoverageInfo(CoveredLines, NumLines),
+      Function.Name, Function.ExecutionCount, RegionCoverage, LineCoverage,
       BranchCoverageInfo(CoveredBranches, NumBranches),
       MCDCCoverageInfo(CoveredPairs, NumPairs));
 }


        


More information about the llvm-commits mailing list