Author: Alan Phipps Date: 2024-12-02T15:44:05-06:00 New Revision: c4ab7f0140cfab754b27468be2fc7143479c83f3
URL: https://github.com/llvm/llvm-project/commit/c4ab7f0140cfab754b27468be2fc7143479c83f3 DIFF: https://github.com/llvm/llvm-project/commit/c4ab7f0140cfab754b27468be2fc7143479c83f3.diff LOG: Revert "[llvm-cov] Fix branch counts of template functions (#111743) (#113925)" This reverts commit 0fe1f8524e02a2d28946e8356615f16166670474. 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: llvm/test/tools/llvm-cov/branch-export-lcov-unify-instances.test ################################################################################ diff --git a/llvm/test/tools/llvm-cov/branch-export-lcov-unify-instances.test b/llvm/test/tools/llvm-cov/branch-export-lcov-unify-instances.test deleted file mode 100644 index 368024fbe83b84..00000000000000 --- a/llvm/test/tools/llvm-cov/branch-export-lcov-unify-instances.test +++ /dev/null @@ -1,38 +0,0 @@ - -// RUN: llvm-profdata merge %S/Inputs/branch-templates.proftext -o %t.profdata -// RUN: llvm-cov export --format=lcov --unify-instantiations=true %S/Inputs/branch-templates.o32l -instr-profile %t.profdata | FileCheck %s -check-prefix=UNIFY - -// UNIFY-DAG: BRDA:14,0,0,1 -// UNIFY-DAG: BRDA:14,0,1,2 -// UNIFY-DAG: BRDA:30,0,0,1 -// UNIFY-DAG: BRDA:30,0,1,0 -// UNIFY-DAG: BRDA:32,0,0,0 -// UNIFY-DAG: BRDA:32,0,1,1 -// UNIFY-DAG: BRDA:34,0,0,1 -// UNIFY-DAG: BRDA:34,0,1,0 -// UNIFY-NOT: BRDA -// UNIFY: BRF:8 -// UNIFY: BRH:4 -// UNIFY: LF:17 -// UNIFY: LH:13 - -// RUN: llvm-profdata merge %S/Inputs/branch-templates.proftext -o %t.profdata -// RUN: llvm-cov export --format=lcov --unify-instantiations=false %S/Inputs/branch-templates.o32l -instr-profile %t.profdata | FileCheck %s - -// CHECK-DAG: BRDA:14,0,0,0 -// CHECK-DAG: BRDA:14,0,1,1 -// CHECK-DAG: BRDA:14,1,2,1 -// CHECK-DAG: BRDA:14,1,3,0 -// CHECK-DAG: BRDA:14,2,4,0 -// CHECK-DAG: BRDA:14,2,5,1 -// CHECK-DAG: BRDA:30,0,0,1 -// CHECK-DAG: BRDA:30,0,1,0 -// CHECK-DAG: BRDA:32,0,0,0 -// CHECK-DAG: BRDA:32,0,1,1 -// CHECK-DAG: BRDA:34,0,0,1 -// CHECK-DAG: BRDA:34,0,1,0 -// CHECK-NOT: BRDA -// CHECK: BRF:8 -// CHECK: BRH:4 -// CHECK: LF:17 -// CHECK: LH:13 diff --git a/llvm/test/tools/llvm-cov/branch-export-lcov.test b/llvm/test/tools/llvm-cov/branch-export-lcov.test index 936ba2576121b7..fe43dd66de8d04 100644 --- a/llvm/test/tools/llvm-cov/branch-export-lcov.test +++ b/llvm/test/tools/llvm-cov/branch-export-lcov.test @@ -39,7 +39,7 @@ // Check recursive macro-expansions. // RUN: llvm-profdata merge %S/Inputs/branch-macros.proftext -o %t.profdata -// RUN: llvm-cov export --format=lcov --unify-instantiations=false %S/Inputs/branch-macros.o32l -instr-profile %t.profdata | FileCheck %s -check-prefix=MACROS +// 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 @@ -78,38 +78,3 @@ // NOBRANCH-NOT: BRF // NOBRANCH-NOT: BRH -// Check recursive macro-expansions with unify mode. -// RUN: llvm-profdata merge %S/Inputs/branch-macros.proftext -o %t.profdata -// RUN: llvm-cov export --format=lcov --unify-instantiations=true %S/Inputs/branch-macros.o32l -instr-profile %t.profdata | FileCheck %s -check-prefix=MACROS2 - -// MACROS2-COUNT-4: BRDA:17 -// MACROS2-NOT: BRDA:17 - -// MACROS2-COUNT-4: BRDA:19 -// MACROS2-NOT: BRDA:19 - -// MACROS2-COUNT-4: BRDA:21 -// MACROS2-NOT: BRDA:21 - -// MACROS2-COUNT-4: BRDA:23 -// MACROS2-NOT: BRDA:23 - -// MACROS2-COUNT-4: BRDA:25 -// MACROS2-NOT: BRDA:25 - -// MACROS2: BRDA:27,0,0,0 -// MACROS2: BRDA:27,0,1,3 -// MACROS2: BRDA:27,1,2,- -// MACROS2: BRDA:27,1,3,- -// MACROS2: BRDA:27,2,4,- -// MACROS2: BRDA:27,2,5,- -// MACROS2: BRDA:27,3,6,- -// MACROS2: BRDA:27,3,7,- -// MACROS2: BRDA:27,4,8,- -// MACROS2: BRDA:27,4,9,- - -// MACROS2-COUNT-10: BRDA:37 -// MACROS2-NOT: BRDA:37 -// MACROS2-NOT: BRDA -// MACROS2: BRF:40 -// MACROS2: BRH:24 diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index 43ad4c121a1f70..d06fd86fe52afb 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -1270,10 +1270,6 @@ int CodeCoverageTool::doExport(int argc, const char **argv, cl::desc("Don't export branch data (LCOV)"), cl::cat(ExportCategory)); - cl::opt<bool> UnifyInstantiations("unify-instantiations", cl::Optional, - cl::desc("Unify function instantiations"), - cl::init(true), cl::cat(ExportCategory)); - auto Err = commandLineParser(argc, argv); if (Err) return Err; @@ -1281,7 +1277,6 @@ int CodeCoverageTool::doExport(int argc, const char **argv, ViewOpts.SkipExpansions = SkipExpansions; ViewOpts.SkipFunctions = SkipFunctions; ViewOpts.SkipBranches = SkipBranches; - ViewOpts.UnifyFunctionInstantiations = UnifyInstantiations; 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 a0803b64bea050..d6b9367ae4c514 100644 --- a/llvm/tools/llvm-cov/CoverageExporterLcov.cpp +++ b/llvm/tools/llvm-cov/CoverageExporterLcov.cpp @@ -43,26 +43,9 @@ #include "CoverageReport.h" using namespace llvm; -using namespace coverage; namespace { -struct NestedCountedRegion : public coverage::CountedRegion { - // Contains the path to default and expanded branches. - // Size is 1 for default branches and greater 1 for expanded branches. - std::vector<LineColPair> NestedPath; - // Indicates whether this item should be ignored at rendering. - bool Ignore = false; - - NestedCountedRegion(llvm::coverage::CountedRegion Region, - std::vector<LineColPair> NestedPath) - : llvm::coverage::CountedRegion(std::move(Region)), - NestedPath(std::move(NestedPath)) {} - - // Returns the root line of the branch. - unsigned getEffectiveLine() const { return NestedPath.front().first; } -}; - void renderFunctionSummary(raw_ostream &OS, const FileCoverageSummary &Summary) { OS << "FNF:" << Summary.FunctionCoverage.getNumFunctions() << '\n' @@ -92,107 +75,58 @@ void renderLineExecutionCounts(raw_ostream &OS, } } -std::vector<NestedCountedRegion> +std::vector<llvm::coverage::CountedRegion> collectNestedBranches(const coverage::CoverageMapping &Coverage, ArrayRef<llvm::coverage::ExpansionRecord> Expansions, - std::vector<LineColPair> &NestedPath) { - std::vector<NestedCountedRegion> Branches; + int ViewDepth = 0, int SrcLine = 0) { + std::vector<llvm::coverage::CountedRegion> Branches; for (const auto &Expansion : Expansions) { auto ExpansionCoverage = Coverage.getCoverageForExpansion(Expansion); - // Track the path to the nested expansions. - NestedPath.push_back(Expansion.Region.startLoc()); + // If we're at the top level, set the corresponding source line. + if (ViewDepth == 0) + SrcLine = Expansion.Region.LineStart; // Recursively collect branches from nested expansions. auto NestedExpansions = ExpansionCoverage.getExpansions(); - auto NestedExBranches = - collectNestedBranches(Coverage, NestedExpansions, NestedPath); + auto NestedExBranches = collectNestedBranches(Coverage, NestedExpansions, + ViewDepth + 1, SrcLine); append_range(Branches, NestedExBranches); // Add branches from this level of expansion. auto ExBranches = ExpansionCoverage.getBranches(); - for (auto &B : ExBranches) + for (auto B : ExBranches) if (B.FileID == Expansion.FileID) { - Branches.push_back(NestedCountedRegion(B, NestedPath)); + B.LineStart = SrcLine; + Branches.push_back(B); } - - NestedPath.pop_back(); } return Branches; } -void appendNestedCountedRegions(const std::vector<CountedRegion> &Src, - std::vector<NestedCountedRegion> &Dst) { - auto Unfolded = make_filter_range(Src, [](auto &Region) { - return !Region.TrueFolded || !Region.FalseFolded; - }); - Dst.reserve(Dst.size() + Src.size()); - std::transform(Unfolded.begin(), Unfolded.end(), std::back_inserter(Dst), - [=](auto &Region) { - return NestedCountedRegion(Region, {Region.startLoc()}); - }); -} - -void appendNestedCountedRegions(const std::vector<NestedCountedRegion> &Src, - std::vector<NestedCountedRegion> &Dst) { - auto Unfolded = make_filter_range(Src, [](auto &NestedRegion) { - return !NestedRegion.TrueFolded || !NestedRegion.FalseFolded; - }); - Dst.reserve(Dst.size() + Src.size()); - std::copy(Unfolded.begin(), Unfolded.end(), std::back_inserter(Dst)); -} - -bool sortNested(const NestedCountedRegion &I, const NestedCountedRegion &J) { - // This sorts each element by line and column. - // Implies that all elements are first sorted by getEffectiveLine(). - return I.NestedPath < J.NestedPath; -} - -void combineInstanceCounts(std::vector<NestedCountedRegion> &Branches) { - auto NextBranch = Branches.begin(); - auto EndBranch = Branches.end(); - - while (NextBranch != EndBranch) { - auto SumBranch = NextBranch++; - - // Ensure that only branches with the same NestedPath are summed up. - while (NextBranch != EndBranch && - SumBranch->NestedPath == NextBranch->NestedPath) { - SumBranch->ExecutionCount += NextBranch->ExecutionCount; - SumBranch->FalseExecutionCount += NextBranch->FalseExecutionCount; - // Mark this branch as ignored. - NextBranch->Ignore = true; - - NextBranch++; - } - } +bool sortLine(llvm::coverage::CountedRegion I, + llvm::coverage::CountedRegion J) { + return (I.LineStart < J.LineStart) || + ((I.LineStart == J.LineStart) && (I.ColumnStart < J.ColumnStart)); } void renderBranchExecutionCounts(raw_ostream &OS, const coverage::CoverageMapping &Coverage, - const coverage::CoverageData &FileCoverage, - bool UnifyInstances) { - - std::vector<NestedCountedRegion> Branches; - - appendNestedCountedRegions(FileCoverage.getBranches(), Branches); + const coverage::CoverageData &FileCoverage) { + std::vector<llvm::coverage::CountedRegion> Branches = + FileCoverage.getBranches(); // Recursively collect branches for all file expansions. - std::vector<LineColPair> NestedPath; - std::vector<NestedCountedRegion> ExBranches = - collectNestedBranches(Coverage, FileCoverage.getExpansions(), NestedPath); + std::vector<llvm::coverage::CountedRegion> ExBranches = + collectNestedBranches(Coverage, FileCoverage.getExpansions()); // Append Expansion Branches to Source Branches. - appendNestedCountedRegions(ExBranches, Branches); + append_range(Branches, ExBranches); // Sort branches based on line number to ensure branches corresponding to the // same source line are counted together. - llvm::sort(Branches, sortNested); - - if (UnifyInstances) { - combineInstanceCounts(Branches); - } + llvm::sort(Branches, sortLine); auto NextBranch = Branches.begin(); auto EndBranch = Branches.end(); @@ -200,13 +134,12 @@ void renderBranchExecutionCounts(raw_ostream &OS, // Branches with the same source line are enumerated individually // (BranchIndex) as well as based on True/False pairs (PairIndex). while (NextBranch != EndBranch) { - unsigned CurrentLine = NextBranch->getEffectiveLine(); + unsigned CurrentLine = NextBranch->LineStart; unsigned PairIndex = 0; unsigned BranchIndex = 0; - while (NextBranch != EndBranch && - CurrentLine == NextBranch->getEffectiveLine()) { - if (!NextBranch->Ignore) { + while (NextBranch != EndBranch && CurrentLine == NextBranch->LineStart) { + if (!NextBranch->TrueFolded || !NextBranch->FalseFolded) { unsigned BC1 = NextBranch->ExecutionCount; unsigned BC2 = NextBranch->FalseExecutionCount; bool BranchNotExecuted = (BC1 == 0 && BC2 == 0); @@ -240,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 SkipBranches, bool UnifyInstances) { + bool SkipFunctions, bool SkipBranches) { OS << "SF:" << Filename << '\n'; if (!ExportSummaryOnly && !SkipFunctions) { @@ -253,7 +186,7 @@ void renderFile(raw_ostream &OS, const coverage::CoverageMapping &Coverage, auto FileCoverage = Coverage.getCoverageForFile(Filename); renderLineExecutionCounts(OS, FileCoverage); if (!SkipBranches) - renderBranchExecutionCounts(OS, Coverage, FileCoverage, UnifyInstances); + renderBranchExecutionCounts(OS, Coverage, FileCoverage); } if (!SkipBranches) renderBranchSummary(OS, FileReport); @@ -265,11 +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 SkipBranches, - bool UnifyInstances) { + 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, SkipBranches, UnifyInstances); + SkipFunctions, SkipBranches); } } // end anonymous namespace @@ -288,6 +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.SkipBranches, - Options.UnifyFunctionInstantiations); + Options.SkipFunctions, Options.SkipBranches); } diff --git a/llvm/tools/llvm-cov/CoverageViewOptions.h b/llvm/tools/llvm-cov/CoverageViewOptions.h index 0ea114ab8f6c0f..6925cffd8246d2 100644 --- a/llvm/tools/llvm-cov/CoverageViewOptions.h +++ b/llvm/tools/llvm-cov/CoverageViewOptions.h @@ -35,7 +35,6 @@ struct CoverageViewOptions { bool ShowBranchPercents; bool ShowExpandedRegions; bool ShowFunctionInstantiations; - bool UnifyFunctionInstantiations; bool ShowFullFilenames; bool ShowBranchSummary; bool ShowMCDCSummary; _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits