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
-//===- 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.
//
//===----------------------------------------------------------------------===//
-#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
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);
uint32_t CurrentEndOffset = 0;
unsigned NumEntries = 0;
DwarfStringPoolEntryRef EmptyString;
- SymbolMapTranslator Translator;
+ std::function<StringRef(StringRef Input)> Translator;
};
/// Helper for making strong types.
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
MIRPrinter.cpp
MIRPrintingPass.cpp
MacroFusion.cpp
+ NonRelocatableStringpool.cpp
OptimizePHIs.cpp
ParallelCG.cpp
PeepholeOptimizer.cpp
-//===- 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.
//
//===----------------------------------------------------------------------===//
-#include "NonRelocatableStringpool.h"
+#include "llvm/CodeGen/NonRelocatableStringpool.h"
namespace llvm {
-namespace dsymutil {
DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {
if (S.empty() && !Strings.empty())
return Result;
}
-} // namespace dsymutil
} // namespace llvm
DwarfStreamer.cpp
MachODebugMapParser.cpp
MachOUtils.cpp
- NonRelocatableStringpool.cpp
SymbolMap.cpp
DEPENDS
#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"
#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"
#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"
// 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;
#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"
#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"
}
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;