[llvm] 10c11f5 - [llvm-pdbutil] Move global state (Filters) inside LinePrinter class.

Carlos Alberto Enciso via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 8 06:58:12 PDT 2022


Author: Carlos Alberto Enciso
Date: 2022-04-08T14:54:55+01:00
New Revision: 10c11f5c434a4162debcb53d43c8d01e9e111d21

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

LOG: [llvm-pdbutil] Move global state (Filters) inside LinePrinter class.

The changes described by:

https://reviews.llvm.org/D121801
https://reviews.llvm.org/D122226

Moved some llvm-pdbutil functionality to the debug PDB library.

This patch addresses one outstanding issue concerning the global
state (Filters) created in the PDB library.

- Move 'Filters' inside the 'LinePrinter' class.
- Omit 'Optional' and just pass 'PrintScope &HeaderScope' everywhere.

Reviewed By: aganea

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

Added: 
    

Modified: 
    llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h
    llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h
    llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
    llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp
    llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h b/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h
index d0dd570f0e056..eeb7c76d2bd87 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h
@@ -158,32 +158,32 @@ getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index);
 Expected<ModuleDebugStreamRef> getModuleDebugStream(PDBFile &File,
                                                     uint32_t Index);
 
-bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group);
+bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group,
+                           const FilterOptions &Filters);
 
 // TODO: Change these callbacks to be function_refs (de-templatify them).
 template <typename CallbackT>
-Error iterateOneModule(InputFile &File, const Optional<PrintScope> &HeaderScope,
+Error iterateOneModule(InputFile &File, const PrintScope &HeaderScope,
                        const SymbolGroup &SG, uint32_t Modi,
                        CallbackT Callback) {
-  if (HeaderScope) {
-    HeaderScope->P.formatLine(
-        "Mod {0:4} | `{1}`: ",
-        fmt_align(Modi, AlignStyle::Right, HeaderScope->LabelWidth), SG.name());
-  }
+  HeaderScope.P.formatLine(
+      "Mod {0:4} | `{1}`: ",
+      fmt_align(Modi, AlignStyle::Right, HeaderScope.LabelWidth), SG.name());
 
   AutoIndent Indent(HeaderScope);
   return Callback(Modi, SG);
 }
 
 template <typename CallbackT>
-Error iterateSymbolGroups(InputFile &Input,
-                          const Optional<PrintScope> &HeaderScope,
+Error iterateSymbolGroups(InputFile &Input, const PrintScope &HeaderScope,
                           CallbackT Callback) {
   AutoIndent Indent(HeaderScope);
 
-  if (llvm::pdb::Filters.DumpModi > 0) {
-    assert(llvm::pdb::Filters.DumpModi == 1);
-    uint32_t Modi = llvm::pdb::Filters.DumpModi;
+  FilterOptions Filters = HeaderScope.P.getFilters();
+  uint32_t Modi = Filters.DumpModi;
+
+  if (Modi > 0) {
+    assert(Modi == 1);
     SymbolGroup SG(&Input, Modi);
     return iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)),
                             SG, Modi, Callback);
@@ -192,7 +192,7 @@ Error iterateSymbolGroups(InputFile &Input,
   uint32_t I = 0;
 
   for (const auto &SG : Input.symbol_groups()) {
-    if (shouldDumpSymbolGroup(I, SG))
+    if (shouldDumpSymbolGroup(I, SG, Filters))
       if (auto Err =
               iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(I)),
                                SG, I, Callback))
@@ -205,7 +205,7 @@ Error iterateSymbolGroups(InputFile &Input,
 
 template <typename SubsectionT>
 Error iterateModuleSubsections(
-    InputFile &File, const Optional<PrintScope> &HeaderScope,
+    InputFile &File, const PrintScope &HeaderScope,
     llvm::function_ref<Error(uint32_t, const SymbolGroup &, SubsectionT &)>
         Callback) {
 

diff  --git a/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h b/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h
index 38abf6635dcd3..773bf061fb7b1 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h
@@ -40,17 +40,16 @@ class MSFStreamLayout;
 } // namespace msf
 namespace pdb {
 
-extern FilterOptions Filters;
-
 class ClassLayout;
 class PDBFile;
+class SymbolGroup;
 
 class LinePrinter {
   friend class WithColor;
 
 public:
   LinePrinter(int Indent, bool UseColor, raw_ostream &Stream,
-              FilterOptions &Filters);
+              const FilterOptions &Filters);
 
   void Indent(uint32_t Amount = 0);
   void Unindent(uint32_t Amount = 0);
@@ -87,6 +86,8 @@ class LinePrinter {
   bool IsSymbolExcluded(llvm::StringRef SymbolName);
   bool IsCompilandExcluded(llvm::StringRef CompilandName);
 
+  const FilterOptions &getFilters() const { return Filters; }
+
 private:
   template <typename Iter>
   void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
@@ -99,6 +100,7 @@ class LinePrinter {
   int IndentSpaces;
   int CurrentIndent;
   bool UseColor;
+  const FilterOptions &Filters;
 
   std::list<Regex> ExcludeCompilandFilters;
   std::list<Regex> ExcludeTypeFilters;
@@ -120,11 +122,8 @@ struct PrintScope {
   uint32_t LabelWidth = 0;
 };
 
-inline Optional<PrintScope> withLabelWidth(const Optional<PrintScope> &Scope,
-                                           uint32_t W) {
-  if (!Scope)
-    return None;
-  return PrintScope{*Scope, W};
+inline PrintScope withLabelWidth(const PrintScope &Scope, uint32_t W) {
+  return PrintScope{Scope, W};
 }
 
 struct AutoIndent {
@@ -132,11 +131,9 @@ struct AutoIndent {
       : L(&L), Amount(Amount) {
     L.Indent(Amount);
   }
-  explicit AutoIndent(const Optional<PrintScope> &Scope) {
-    if (Scope.hasValue()) {
-      L = &Scope->P;
-      Amount = Scope->IndentLevel;
-    }
+  explicit AutoIndent(const PrintScope &Scope) {
+    L = &Scope.P;
+    Amount = Scope.IndentLevel;
   }
   ~AutoIndent() {
     if (L)

diff  --git a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
index 637e0ee294f7b..ebe410748b670 100644
--- a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
@@ -573,14 +573,15 @@ static bool isMyCode(const SymbolGroup &Group) {
   return true;
 }
 
-bool llvm::pdb::shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group) {
-  if (llvm::pdb::Filters.JustMyCode && !isMyCode(Group))
+bool llvm::pdb::shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group,
+                                      const FilterOptions &Filters) {
+  if (Filters.JustMyCode && !isMyCode(Group))
     return false;
 
   // If the arg was not specified on the command line, always dump all modules.
-  if (llvm::pdb::Filters.DumpModi == 0)
+  if (Filters.DumpModi == 0)
     return true;
 
   // Otherwise, only dump if this is the same module specified.
-  return (llvm::pdb::Filters.DumpModi == Idx);
+  return (Filters.DumpModi == Idx);
 }

diff  --git a/llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp b/llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp
index 2c4ec80334b52..c12fedc23833e 100644
--- a/llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp
@@ -30,10 +30,6 @@ using namespace llvm;
 using namespace llvm::msf;
 using namespace llvm::pdb;
 
-// TODO: Move this Filters state inside the LinePrinter class and pass it by
-// reference to the iterate* functions.
-FilterOptions llvm::pdb::Filters;
-
 namespace {
 bool IsItemExcluded(llvm::StringRef Item,
                     std::list<llvm::Regex> &IncludeFilters,
@@ -58,9 +54,9 @@ bool IsItemExcluded(llvm::StringRef Item,
 using namespace llvm;
 
 LinePrinter::LinePrinter(int Indent, bool UseColor, llvm::raw_ostream &Stream,
-                         FilterOptions &Filters)
-    : OS(Stream), IndentSpaces(Indent), CurrentIndent(0), UseColor(UseColor) {
-  llvm::pdb::Filters = Filters;
+                         const FilterOptions &Filters)
+    : OS(Stream), IndentSpaces(Indent), CurrentIndent(0), UseColor(UseColor),
+      Filters(Filters) {
   SetFilters(ExcludeTypeFilters, Filters.ExcludeTypes.begin(),
              Filters.ExcludeTypes.end());
   SetFilters(ExcludeSymbolFilters, Filters.ExcludeSymbols.begin(),

diff  --git a/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp b/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
index 2bcdab14c4d71..12cda106c036d 100644
--- a/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
+++ b/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
@@ -552,10 +552,7 @@ Error DumpOutputStyle::dumpSymbolStats() {
 
   StatCollection SymStats;
   StatCollection ChunkStats;
-
-  Optional<PrintScope> Scope;
-  if (File.isPdb())
-    Scope.emplace(P, 2);
+  PrintScope Scope(P, 2);
 
   if (Error Err = iterateSymbolGroups(
           File, Scope, [&](uint32_t Modi, const SymbolGroup &SG) -> Error {


        


More information about the llvm-commits mailing list