[llvm] r305937 - Object: Have the irsymtab builder take a string table builder. NFCI.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 21 11:23:19 PDT 2017
Author: pcc
Date: Wed Jun 21 13:23:19 2017
New Revision: 305937
URL: http://llvm.org/viewvc/llvm-project?rev=305937&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm/Object/IRSymtab.h
llvm/trunk/lib/Object/IRSymtab.cpp
Modified: llvm/trunk/include/llvm/Object/IRSymtab.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/IRSymtab.h?rev=305937&r1=305936&r2=305937&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/IRSymtab.h (original)
+++ llvm/trunk/include/llvm/Object/IRSymtab.h Wed Jun 21 13:23:19 2017
@@ -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.
Modified: llvm/trunk/lib/Object/IRSymtab.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRSymtab.cpp?rev=305937&r1=305936&r2=305937&view=diff
==============================================================================
--- llvm/trunk/lib/Object/IRSymtab.cpp (original)
+++ llvm/trunk/lib/Object/IRSymtab.cpp Wed Jun 21 13:23:19 2017
@@ -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 *>
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 *>
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(Ar
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);
More information about the llvm-commits
mailing list