[llvm] a921d6e - [llvm-cov] Allow branch coverage to be skipped when exporting for LCOV

Alan Phipps via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 14 14:25:00 PDT 2022


Author: Alan Phipps
Date: 2022-10-14T16:24:41-05:00
New Revision: a921d6eb3b517ef6dcefd13cfbb9a017b00a06b1

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

LOG: [llvm-cov] Allow branch coverage to be skipped when exporting for LCOV

This small patch adds a '--skip-branches' option to the llvm-cov export
options. This option allows branch coverage information to be skipped from the
exported LCOV directives if it's not needed. For now, this only works when
exporting LCOV (which is noted in the option description), but it can be
extended for JSON later if it makes sense.

Differential Revision: https://reviews.llvm.org/D135986

Added: 
    

Modified: 
    llvm/test/tools/llvm-cov/branch-export-lcov.test
    llvm/tools/llvm-cov/CodeCoverage.cpp
    llvm/tools/llvm-cov/CoverageExporterLcov.cpp
    llvm/tools/llvm-cov/CoverageViewOptions.h

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-cov/branch-export-lcov.test b/llvm/test/tools/llvm-cov/branch-export-lcov.test
index 1714123ec7be5..fe43dd66de8d0 100644
--- a/llvm/test/tools/llvm-cov/branch-export-lcov.test
+++ b/llvm/test/tools/llvm-cov/branch-export-lcov.test
@@ -1,6 +1,7 @@
 
 // RUN: llvm-profdata merge %S/Inputs/branch-showBranchPercentage.proftext -o %t.profdata
 // RUN: llvm-cov export --format=lcov %S/Inputs/branch-showBranchPercentage.o32l -instr-profile %t.profdata | FileCheck %s
+// RUN: llvm-cov export --format=lcov --skip-branches %S/Inputs/branch-showBranchPercentage.o32l -instr-profile %t.profdata | FileCheck %s --check-prefix=NOBRANCH
 
 // CHECK-DAG: BRDA:14,0,0,1
 // CHECK-DAG: BRDA:14,0,1,5
@@ -39,6 +40,7 @@
 // Check recursive macro-expansions.
 // RUN: llvm-profdata merge %S/Inputs/branch-macros.proftext -o %t.profdata
 // RUN: llvm-cov export --format=lcov %S/Inputs/branch-macros.o32l -instr-profile %t.profdata | FileCheck %s -check-prefix=MACROS
+// RUN: llvm-cov export --format=lcov --skip-branches %S/Inputs/branch-macros.o32l -instr-profile %t.profdata | FileCheck %s -check-prefix=NOBRANCH
 
 // MACROS-COUNT-4: BRDA:17
 // MACROS-NOT: BRDA:17
@@ -71,3 +73,8 @@
 // MACROS-NOT: BRDA
 // MACROS: BRF:40
 // MACROS: BRH:24
+
+// NOBRANCH-NOT: BRDA
+// NOBRANCH-NOT: BRF
+// NOBRANCH-NOT: BRH
+

diff  --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index c963a6052d48e..9f19dd2856592 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -1192,12 +1192,17 @@ int CodeCoverageTool::doExport(int argc, const char **argv,
                               cl::desc("Don't export per-function data"),
                               cl::cat(ExportCategory));
 
+  cl::opt<bool> SkipBranches("skip-branches", cl::Optional,
+                              cl::desc("Don't export branch data (LCOV)"),
+                              cl::cat(ExportCategory));
+
   auto Err = commandLineParser(argc, argv);
   if (Err)
     return Err;
 
   ViewOpts.SkipExpansions = SkipExpansions;
   ViewOpts.SkipFunctions = SkipFunctions;
+  ViewOpts.SkipBranches = SkipBranches;
 
   if (ViewOpts.Format != CoverageViewOptions::OutputFormat::Text &&
       ViewOpts.Format != CoverageViewOptions::OutputFormat::Lcov) {

diff  --git a/llvm/tools/llvm-cov/CoverageExporterLcov.cpp b/llvm/tools/llvm-cov/CoverageExporterLcov.cpp
index 0096a3d44d856..ae8f556edb313 100644
--- a/llvm/tools/llvm-cov/CoverageExporterLcov.cpp
+++ b/llvm/tools/llvm-cov/CoverageExporterLcov.cpp
@@ -173,7 +173,7 @@ void renderBranchSummary(raw_ostream &OS, const FileCoverageSummary &Summary) {
 void renderFile(raw_ostream &OS, const coverage::CoverageMapping &Coverage,
                 const std::string &Filename,
                 const FileCoverageSummary &FileReport, bool ExportSummaryOnly,
-                bool SkipFunctions) {
+                bool SkipFunctions, bool SkipBranches) {
   OS << "SF:" << Filename << '\n';
 
   if (!ExportSummaryOnly && !SkipFunctions) {
@@ -185,9 +185,11 @@ void renderFile(raw_ostream &OS, const coverage::CoverageMapping &Coverage,
     // Calculate and render detailed coverage information for given file.
     auto FileCoverage = Coverage.getCoverageForFile(Filename);
     renderLineExecutionCounts(OS, FileCoverage);
-    renderBranchExecutionCounts(OS, Coverage, FileCoverage);
+    if (!SkipBranches)
+      renderBranchExecutionCounts(OS, Coverage, FileCoverage);
   }
-  renderBranchSummary(OS, FileReport);
+  if (!SkipBranches)
+    renderBranchSummary(OS, FileReport);
   renderLineSummary(OS, FileReport);
 
   OS << "end_of_record\n";
@@ -196,10 +198,11 @@ void renderFile(raw_ostream &OS, const coverage::CoverageMapping &Coverage,
 void renderFiles(raw_ostream &OS, const coverage::CoverageMapping &Coverage,
                  ArrayRef<std::string> SourceFiles,
                  ArrayRef<FileCoverageSummary> FileReports,
-                 bool ExportSummaryOnly, bool SkipFunctions) {
+                 bool ExportSummaryOnly, bool SkipFunctions,
+                 bool SkipBranches) {
   for (unsigned I = 0, E = SourceFiles.size(); I < E; ++I)
     renderFile(OS, Coverage, SourceFiles[I], FileReports[I], ExportSummaryOnly,
-               SkipFunctions);
+               SkipFunctions, SkipBranches);
 }
 
 } // end anonymous namespace
@@ -218,5 +221,5 @@ void CoverageExporterLcov::renderRoot(ArrayRef<std::string> SourceFiles) {
   auto FileReports = CoverageReport::prepareFileReports(Coverage, Totals,
                                                         SourceFiles, Options);
   renderFiles(OS, Coverage, SourceFiles, FileReports, Options.ExportSummaryOnly,
-              Options.SkipFunctions);
+              Options.SkipFunctions, Options.SkipBranches);
 }

diff  --git a/llvm/tools/llvm-cov/CoverageViewOptions.h b/llvm/tools/llvm-cov/CoverageViewOptions.h
index c6e99819f3190..fedf2df9b9bd7 100644
--- a/llvm/tools/llvm-cov/CoverageViewOptions.h
+++ b/llvm/tools/llvm-cov/CoverageViewOptions.h
@@ -41,6 +41,7 @@ struct CoverageViewOptions {
   bool ExportSummaryOnly;
   bool SkipExpansions;
   bool SkipFunctions;
+  bool SkipBranches;
   OutputFormat Format;
   BranchOutputType ShowBranches;
   std::string ShowOutputDirectory;


        


More information about the llvm-commits mailing list