Object: Have the irsymtab builder take a string table builder. NFCI.

This will be needed in order to share the irsymtab string table with
the bitcode string table.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305937 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Peter Collingbourne 2017-06-21 18:23:19 +00:00
parent d8cbb8e87a
commit dc07e63ced
2 changed files with 23 additions and 19 deletions

View File

@ -38,6 +38,7 @@
namespace llvm {
struct BitcodeFileContents;
class StringTableBuilder;
namespace irsymtab {
@ -136,9 +137,10 @@ struct Header {
} // end namespace storage
/// Fills in Symtab and Strtab with a valid symbol and string table for Mods.
/// Fills in Symtab and StrtabBuilder with a valid symbol and string table for
/// Mods.
Error build(ArrayRef<Module *> Mods, SmallVector<char, 0> &Symtab,
SmallVector<char, 0> &Strtab);
StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc);
/// This represents a symbol that has been read from a storage::Symbol and
/// possibly a storage::Uncommon.

View File

@ -46,15 +46,15 @@ namespace {
/// Stores the temporary state that is required to build an IR symbol table.
struct Builder {
SmallVector<char, 0> &Symtab;
SmallVector<char, 0> &Strtab;
StringTableBuilder &StrtabBuilder;
StringSaver Saver;
Builder(SmallVector<char, 0> &Symtab, SmallVector<char, 0> &Strtab)
: Symtab(Symtab), Strtab(Strtab) {}
StringTableBuilder StrtabBuilder{StringTableBuilder::RAW};
BumpPtrAllocator Alloc;
StringSaver Saver{Alloc};
// This ctor initializes a StringSaver using the passed in BumpPtrAllocator.
// The StringTableBuilder does not create a copy of any strings added to it,
// so this provides somewhere to store any strings that we create.
Builder(SmallVector<char, 0> &Symtab, StringTableBuilder &StrtabBuilder,
BumpPtrAllocator &Alloc)
: Symtab(Symtab), StrtabBuilder(StrtabBuilder), Saver(Alloc) {}
DenseMap<const Comdat *, unsigned> ComdatMap;
Mangler Mang;
@ -240,7 +240,7 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
return Err;
COFFLinkerOptsOS.flush();
setStr(Hdr.COFFLinkerOpts, COFFLinkerOpts);
setStr(Hdr.COFFLinkerOpts, Saver.save(COFFLinkerOpts));
// We are about to fill in the header's range fields, so reserve space for it
// and copy it in afterwards.
@ -251,19 +251,15 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
writeRange(Hdr.Uncommons, Uncommons);
*reinterpret_cast<storage::Header *>(Symtab.data()) = Hdr;
raw_svector_ostream OS(Strtab);
StrtabBuilder.finalizeInOrder();
StrtabBuilder.write(OS);
return Error::success();
}
} // end anonymous namespace
Error irsymtab::build(ArrayRef<Module *> Mods, SmallVector<char, 0> &Symtab,
SmallVector<char, 0> &Strtab) {
return Builder(Symtab, Strtab).build(Mods);
StringTableBuilder &StrtabBuilder,
BumpPtrAllocator &Alloc) {
return Builder(Symtab, StrtabBuilder, Alloc).build(Mods);
}
// Upgrade a vector of bitcode modules created by an old version of LLVM by
@ -285,9 +281,15 @@ static Expected<FileContents> upgrade(ArrayRef<BitcodeModule> BMs) {
OwnedMods.push_back(std::move(*MOrErr));
}
if (Error E = build(Mods, FC.Symtab, FC.Strtab))
StringTableBuilder StrtabBuilder(StringTableBuilder::RAW);
BumpPtrAllocator Alloc;
if (Error E = build(Mods, FC.Symtab, StrtabBuilder, Alloc))
return std::move(E);
StrtabBuilder.finalizeInOrder();
FC.Strtab.resize(StrtabBuilder.getSize());
StrtabBuilder.write((uint8_t *)FC.Strtab.data());
FC.TheReader = {{FC.Symtab.data(), FC.Symtab.size()},
{FC.Strtab.data(), FC.Strtab.size()}};
return std::move(FC);