[llvm] r294135 - [llvm-cov] Refactor logic for storing demangled symbols, NFC

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 5 12:10:58 PST 2017


Author: vedantk
Date: Sun Feb  5 14:10:58 2017
New Revision: 294135

URL: http://llvm.org/viewvc/llvm-project?rev=294135&view=rev
Log:
[llvm-cov] Refactor logic for storing demangled symbols, NFC

Modified:
    llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
    llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.h

Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=294135&r1=294134&r2=294135&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Sun Feb  5 14:10:58 2017
@@ -15,6 +15,7 @@
 
 #include "CoverageFilters.h"
 #include "CoverageReport.h"
+#include "CoverageSummaryInfo.h"
 #include "CoverageViewOptions.h"
 #include "RenderingSupport.h"
 #include "SourceCoverageView.h"
@@ -98,9 +99,6 @@ private:
   /// \brief If a demangler is available, demangle all symbol names.
   void demangleSymbols(const CoverageMapping &Coverage);
 
-  /// \brief Demangle \p Sym if possible. Otherwise, just return \p Sym.
-  StringRef getSymbolForHumans(StringRef Sym) const;
-
   /// \brief Write out a source file view to the filesystem.
   void writeSourceFileView(StringRef SourceFile, CoverageMapping *Coverage,
                            CoveragePrinter *Printer, bool ShowFilenames);
@@ -136,8 +134,8 @@ private:
   /// The architecture the coverage mapping data targets.
   std::string CoverageArch;
 
-  /// A cache for demangled symbol names.
-  StringMap<std::string> DemangledNames;
+  /// A cache for demangled symbols.
+  DemangleCache DC;
 
   /// A lock which guards printing to stderr.
   std::mutex ErrsLock;
@@ -267,7 +265,7 @@ CodeCoverageTool::createFunctionView(con
     return nullptr;
 
   auto Expansions = FunctionCoverage.getExpansions();
-  auto View = SourceCoverageView::create(getSymbolForHumans(Function.Name),
+  auto View = SourceCoverageView::create(DC.demangle(Function.Name),
                                          SourceBuffer.get(), ViewOpts,
                                          std::move(FunctionCoverage));
   attachExpansionSubViews(*View, Expansions, Coverage);
@@ -293,7 +291,7 @@ CodeCoverageTool::createSourceFileView(S
   for (const auto *Function : Coverage.getInstantiations(SourceFile)) {
     std::unique_ptr<SourceCoverageView> SubView{nullptr};
 
-    StringRef Funcname = getSymbolForHumans(Function->Name);
+    StringRef Funcname = DC.demangle(Function->Name);
 
     if (Function->ExecutionCount > 0) {
       auto SubViewCoverage = Coverage.getCoverageForFunction(*Function);
@@ -453,14 +451,7 @@ void CodeCoverageTool::demangleSymbols(c
   // Cache the demangled names.
   unsigned I = 0;
   for (const auto &Function : Coverage.getCoveredFunctions())
-    DemangledNames[Function.Name] = Symbols[I++];
-}
-
-StringRef CodeCoverageTool::getSymbolForHumans(StringRef Sym) const {
-  const auto DemangledName = DemangledNames.find(Sym);
-  if (DemangledName == DemangledNames.end())
-    return Sym;
-  return DemangledName->getValue();
+    DC.DemangledNames[Function.Name] = Symbols[I++];
 }
 
 void CodeCoverageTool::writeSourceFileView(StringRef SourceFile,

Modified: llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.h?rev=294135&r1=294134&r2=294135&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.h (original)
+++ llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.h Sun Feb  5 14:10:58 2017
@@ -160,6 +160,19 @@ struct FileCoverageSummary {
   }
 };
 
+/// \brief A cache for demangled symbols.
+struct DemangleCache {
+  StringMap<std::string> DemangledNames;
+
+  /// \brief Demangle \p Sym if possible. Otherwise, just return \p Sym.
+  StringRef demangle(StringRef Sym) const {
+    const auto DemangledName = DemangledNames.find(Sym);
+    if (DemangledName == DemangledNames.end())
+      return Sym;
+    return DemangledName->getValue();
+  }
+};
+
 } // namespace llvm
 
 #endif // LLVM_COV_COVERAGESUMMARYINFO_H




More information about the llvm-commits mailing list