[llvm] 9e8c799 - [Dsymutil][NFC] Move NonRelocatableStringpool into common CodeGen folder.

Alexey Lapshin via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 23:03:31 PST 2019


Author: Alexey Lapshin
Date: 2019-12-06T10:02:27+03:00
New Revision: 9e8c799e2b0dc3e3b20f5044309fa8e48e8e3e32

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

LOG: [Dsymutil][NFC] Move NonRelocatableStringpool into common CodeGen folder.

That refactoring moves NonRelocatableStringpool into common CodeGen folder.
So that NonRelocatableStringpool could be used not only inside dsymutil.

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

Added: 
    llvm/include/llvm/CodeGen/NonRelocatableStringpool.h
    llvm/lib/CodeGen/NonRelocatableStringpool.cpp

Modified: 
    llvm/lib/CodeGen/CMakeLists.txt
    llvm/tools/dsymutil/CMakeLists.txt
    llvm/tools/dsymutil/DeclContext.h
    llvm/tools/dsymutil/DwarfLinker.cpp
    llvm/tools/dsymutil/DwarfStreamer.h
    llvm/tools/dsymutil/MachOUtils.cpp

Removed: 
    llvm/tools/dsymutil/NonRelocatableStringpool.cpp
    llvm/tools/dsymutil/NonRelocatableStringpool.h


################################################################################
diff  --git a/llvm/tools/dsymutil/NonRelocatableStringpool.h b/llvm/include/llvm/CodeGen/NonRelocatableStringpool.h
similarity index 72%
rename from llvm/tools/dsymutil/NonRelocatableStringpool.h
rename to llvm/include/llvm/CodeGen/NonRelocatableStringpool.h
index ef73242d14e2..f7d082e2a2ba 100644
--- a/llvm/tools/dsymutil/NonRelocatableStringpool.h
+++ b/llvm/include/llvm/CodeGen/NonRelocatableStringpool.h
@@ -1,4 +1,4 @@
-//===- NonRelocatableStringpool.h - A simple stringpool  --------*- C++ -*-===//
+//===- llvm/CodeGen/NonRelocatableStringpool.h - A simple stringpool  -----===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,26 +6,20 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H
-#define LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H
+#ifndef LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H
+#define LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H
 
-#include "SymbolMap.h"
-
-#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/StringRef.h"
 #include "llvm/CodeGen/DwarfStringPoolEntry.h"
 #include "llvm/Support/Allocator.h"
 #include <cstdint>
 #include <vector>
 
 namespace llvm {
-namespace dsymutil {
 
 /// A string table that doesn't need relocations.
 ///
-/// We are doing a final link, no need for a string table that has relocation
-/// entries for every reference to it. This class provides this ability by just
-/// associating offsets with strings.
+/// Use this class when a string table doesn't need relocations.
+/// This class provides this ability by just associating offsets with strings.
 class NonRelocatableStringpool {
 public:
   /// Entries are stored into the StringMap and simply linked together through
@@ -34,10 +28,11 @@ class NonRelocatableStringpool {
   using MapTy = StringMap<DwarfStringPoolEntry, BumpPtrAllocator>;
 
   NonRelocatableStringpool(
-      SymbolMapTranslator Translator = SymbolMapTranslator())
+      std::function<StringRef(StringRef Input)> Translator = nullptr,
+      bool PutEmptyString = false)
       : Translator(Translator) {
-    // Legacy dsymutil puts an empty string at the start of the line table.
-    EmptyString = getEntry("");
+    if (PutEmptyString)
+      EmptyString = getEntry("");
   }
 
   DwarfStringPoolEntryRef getEntry(StringRef S);
@@ -65,7 +60,7 @@ class NonRelocatableStringpool {
   uint32_t CurrentEndOffset = 0;
   unsigned NumEntries = 0;
   DwarfStringPoolEntryRef EmptyString;
-  SymbolMapTranslator Translator;
+  std::function<StringRef(StringRef Input)> Translator;
 };
 
 /// Helper for making strong types.
@@ -75,15 +70,14 @@ template <typename T, typename S> class StrongType : public T {
   explicit StrongType(Args... A) : T(std::forward<Args>(A)...) {}
 };
 
-/// It's very easy to introduce bugs by passing the wrong string pool in the
-/// dwarf linker. By using strong types the interface enforces that the right
+/// It's very easy to introduce bugs by passing the wrong string pool.
+/// By using strong types the interface enforces that the right
 /// kind of pool is used.
 struct UniqueTag {};
 struct OffsetsTag {};
 using UniquingStringPool = StrongType<NonRelocatableStringpool, UniqueTag>;
 using OffsetsStringPool = StrongType<NonRelocatableStringpool, OffsetsTag>;
 
-} // end namespace dsymutil
 } // end namespace llvm
 
-#endif // LLVM_TOOLS_DSYMUTIL_NONRELOCATABLESTRINGPOOL_H
+#endif // LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H

diff  --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt
index c10c3f4d7863..470b027e38c8 100644
--- a/llvm/lib/CodeGen/CMakeLists.txt
+++ b/llvm/lib/CodeGen/CMakeLists.txt
@@ -102,6 +102,7 @@ add_llvm_component_library(LLVMCodeGen
   MIRPrinter.cpp
   MIRPrintingPass.cpp
   MacroFusion.cpp
+  NonRelocatableStringpool.cpp
   OptimizePHIs.cpp
   ParallelCG.cpp
   PeepholeOptimizer.cpp

diff  --git a/llvm/tools/dsymutil/NonRelocatableStringpool.cpp b/llvm/lib/CodeGen/NonRelocatableStringpool.cpp
similarity index 90%
rename from llvm/tools/dsymutil/NonRelocatableStringpool.cpp
rename to llvm/lib/CodeGen/NonRelocatableStringpool.cpp
index 8cb1590cfb64..d28399f239ce 100644
--- a/llvm/tools/dsymutil/NonRelocatableStringpool.cpp
+++ b/llvm/lib/CodeGen/NonRelocatableStringpool.cpp
@@ -1,4 +1,4 @@
-//===- NonRelocatableStringpool.cpp - A simple stringpool  ----------------===//
+//===-- llvm/CodeGen/NonRelocatableStringpool.cpp - A simple stringpool  --===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,10 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "NonRelocatableStringpool.h"
+#include "llvm/CodeGen/NonRelocatableStringpool.h"
 
 namespace llvm {
-namespace dsymutil {
 
 DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {
   if (S.empty() && !Strings.empty())
@@ -52,5 +51,4 @@ NonRelocatableStringpool::getEntriesForEmission() const {
   return Result;
 }
 
-} // namespace dsymutil
 } // namespace llvm

diff  --git a/llvm/tools/dsymutil/CMakeLists.txt b/llvm/tools/dsymutil/CMakeLists.txt
index 489ad9bfef2e..696f098c3fe0 100644
--- a/llvm/tools/dsymutil/CMakeLists.txt
+++ b/llvm/tools/dsymutil/CMakeLists.txt
@@ -28,7 +28,6 @@ add_llvm_tool(dsymutil
   DwarfStreamer.cpp
   MachODebugMapParser.cpp
   MachOUtils.cpp
-  NonRelocatableStringpool.cpp
   SymbolMap.cpp
 
   DEPENDS

diff  --git a/llvm/tools/dsymutil/DeclContext.h b/llvm/tools/dsymutil/DeclContext.h
index e88678c6613f..36ef50944083 100644
--- a/llvm/tools/dsymutil/DeclContext.h
+++ b/llvm/tools/dsymutil/DeclContext.h
@@ -10,11 +10,11 @@
 #define LLVM_TOOLS_DSYMUTIL_DECLCONTEXT_H
 
 #include "CompileUnit.h"
-#include "NonRelocatableStringpool.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/CodeGen/NonRelocatableStringpool.h"
 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
 #include "llvm/Support/Path.h"
 

diff  --git a/llvm/tools/dsymutil/DwarfLinker.cpp b/llvm/tools/dsymutil/DwarfLinker.cpp
index 80ac237f1c4e..64acab698434 100644
--- a/llvm/tools/dsymutil/DwarfLinker.cpp
+++ b/llvm/tools/dsymutil/DwarfLinker.cpp
@@ -12,7 +12,6 @@
 #include "DeclContext.h"
 #include "DwarfStreamer.h"
 #include "MachOUtils.h"
-#include "NonRelocatableStringpool.h"
 #include "dsymutil.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/BitVector.h"
@@ -36,6 +35,7 @@
 #include "llvm/CodeGen/AccelTable.h"
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/DIE.h"
+#include "llvm/CodeGen/NonRelocatableStringpool.h"
 #include "llvm/Config/config.h"
 #include "llvm/DebugInfo/DIContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
@@ -2701,12 +2701,12 @@ bool DwarfLinker::link(const DebugMap &Map) {
 
   // This Dwarf string pool which is only used for uniquing. This one should
   // never be used for offsets as its not thread-safe or predictable.
-  UniquingStringPool UniquingStringPool;
+  UniquingStringPool UniquingStringPool(nullptr, true);
 
   // This Dwarf string pool which is used for emission. It must be used
   // serially as the order of calling getStringOffset matters for
   // reproducibility.
-  OffsetsStringPool OffsetsStringPool(Options.Translator);
+  OffsetsStringPool OffsetsStringPool(Options.Translator, true);
 
   // ODR Contexts for the link.
   DeclContextTree ODRContexts;

diff  --git a/llvm/tools/dsymutil/DwarfStreamer.h b/llvm/tools/dsymutil/DwarfStreamer.h
index 821a76985abb..baf215ac1315 100644
--- a/llvm/tools/dsymutil/DwarfStreamer.h
+++ b/llvm/tools/dsymutil/DwarfStreamer.h
@@ -12,9 +12,9 @@
 #include "CompileUnit.h"
 #include "DebugMap.h"
 #include "LinkUtils.h"
-#include "NonRelocatableStringpool.h"
 #include "llvm/CodeGen/AccelTable.h"
 #include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/CodeGen/NonRelocatableStringpool.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
 #include "llvm/MC/MCAsmBackend.h"

diff  --git a/llvm/tools/dsymutil/MachOUtils.cpp b/llvm/tools/dsymutil/MachOUtils.cpp
index ec9df299ebb2..149905fb5bff 100644
--- a/llvm/tools/dsymutil/MachOUtils.cpp
+++ b/llvm/tools/dsymutil/MachOUtils.cpp
@@ -10,7 +10,7 @@
 #include "BinaryHolder.h"
 #include "DebugMap.h"
 #include "LinkUtils.h"
-#include "NonRelocatableStringpool.h"
+#include "llvm/CodeGen/NonRelocatableStringpool.h"
 #include "llvm/MC/MCAsmLayout.h"
 #include "llvm/MC/MCMachObjectWriter.h"
 #include "llvm/MC/MCObjectStreamer.h"
@@ -442,7 +442,12 @@ bool generateDsymCompanion(const DebugMap &DM, SymbolMapTranslator &Translator,
   }
 
   SmallString<0> NewSymtab;
-  NonRelocatableStringpool NewStrings(Translator);
+  std::function<StringRef(StringRef)> TranslationLambda =
+      Translator ? [&](StringRef Input) { return Translator(Input); }
+                 : static_cast<std::function<StringRef(StringRef)>>(nullptr);
+  // Legacy dsymutil puts an empty string at the start of the line table.
+  // thus we set NonRelocatableStringpool(,PutEmptyString=true)
+  NonRelocatableStringpool NewStrings(TranslationLambda, true);
   unsigned NListSize = Is64Bit ? sizeof(MachO::nlist_64) : sizeof(MachO::nlist);
   unsigned NumSyms = 0;
   uint64_t NewStringsSize = 0;


        


More information about the llvm-commits mailing list