diff options
author | Alexey Lapshin <a.v.lapshin@mail.ru> | 2019-12-05 13:11:32 +0300 |
---|---|---|
committer | Alexey Lapshin <a.v.lapshin@mail.ru> | 2019-12-06 10:02:27 +0300 |
commit | 9e8c799e2b0dc3e3b20f5044309fa8e48e8e3e32 (patch) | |
tree | 2a81ec27e98950aaea1a061b2fdaa884a35d0882 | |
parent | c4d8c6319f576a7540017168db2f0440691914f4 (diff) | |
download | bcm5719-llvm-9e8c799e2b0dc3e3b20f5044309fa8e48e8e3e32.tar.gz bcm5719-llvm-9e8c799e2b0dc3e3b20f5044309fa8e48e8e3e32.zip |
[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
-rw-r--r-- | llvm/include/llvm/CodeGen/NonRelocatableStringpool.h (renamed from llvm/tools/dsymutil/NonRelocatableStringpool.h) | 32 | ||||
-rw-r--r-- | llvm/lib/CodeGen/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/CodeGen/NonRelocatableStringpool.cpp (renamed from llvm/tools/dsymutil/NonRelocatableStringpool.cpp) | 6 | ||||
-rw-r--r-- | llvm/tools/dsymutil/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/tools/dsymutil/DeclContext.h | 2 | ||||
-rw-r--r-- | llvm/tools/dsymutil/DwarfLinker.cpp | 6 | ||||
-rw-r--r-- | llvm/tools/dsymutil/DwarfStreamer.h | 2 | ||||
-rw-r--r-- | llvm/tools/dsymutil/MachOUtils.cpp | 9 |
8 files changed, 28 insertions, 31 deletions
diff --git a/llvm/tools/dsymutil/NonRelocatableStringpool.h b/llvm/include/llvm/CodeGen/NonRelocatableStringpool.h index ef73242d14e..f7d082e2a2b 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 @@ public: 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 @@ private: 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 @@ public: 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 c10c3f4d786..470b027e38c 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 index 8cb1590cfb6..d28399f239c 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 489ad9bfef2..696f098c3fe 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 e88678c6613..36ef5094408 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 80ac237f1c4..64acab69843 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 821a76985ab..baf215ac131 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 ec9df299ebb..149905fb5bf 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; |