[lld] r299406 - [PDB] Save one type record copy

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 3 17:56:34 PDT 2017


Author: rnk
Date: Mon Apr  3 19:56:34 2017
New Revision: 299406

URL: http://llvm.org/viewvc/llvm-project?rev=299406&view=rev
Log:
[PDB] Save one type record copy

Summary:
The TypeTableBuilder provides stable storage for type records. We don't
need to copy all of the bytes into a flat vector before adding it to the
TpiStreamBuilder.

This makes addTypeRecord take an ArrayRef<uint8_t> and a hash code to go
with it, which seems like a simplification.

Reviewers: ruiu, zturner, inglorion

Subscribers: llvm-commits

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

Modified:
    lld/trunk/COFF/PDB.cpp

Modified: lld/trunk/COFF/PDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=299406&r1=299405&r2=299406&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Mon Apr  3 19:56:34 2017
@@ -83,33 +83,22 @@ static ArrayRef<uint8_t> getDebugSection
 }
 
 static void addTypeInfo(pdb::TpiStreamBuilder &TpiBuilder,
-                        codeview::TypeTableBuilder &TypeTable,
-                        std::vector<uint8_t> &Data) {
+                        codeview::TypeTableBuilder &TypeTable) {
   // Start the TPI or IPI stream header.
   TpiBuilder.setVersionHeader(pdb::PdbTpiV80);
 
   // Flatten the in memory type table.
-  // FIXME: Avoid this copy.
   TypeTable.ForEachRecord([&](TypeIndex TI, ArrayRef<uint8_t> Rec) {
-    Data.insert(Data.end(), Rec.begin(), Rec.end());
+    // FIXME: Hash types.
+    TpiBuilder.addTypeRecord(Rec, None);
   });
-
-  BinaryByteStream Stream(Data, support::little);
-  codeview::CVTypeArray Records;
-  BinaryStreamReader Reader(Stream);
-  if (auto EC = Reader.readArray(Records, Reader.getLength()))
-    fatal(EC, "Reader.readArray failed");
-  for (const codeview::CVType &Rec : Records)
-    TpiBuilder.addTypeRecord(Rec);
 }
 
 // Merge .debug$T sections into IpiData and TpiData.
 static void mergeDebugT(SymbolTable *Symtab, pdb::PDBFileBuilder &Builder,
-                        std::vector<uint8_t> &TpiData,
-                        std::vector<uint8_t> &IpiData) {
+                        codeview::TypeTableBuilder &TypeTable,
+                        codeview::TypeTableBuilder &IDTable) {
   // Visit all .debug$T sections to add them to Builder.
-  codeview::TypeTableBuilder IDTable(BAlloc);
-  codeview::TypeTableBuilder TypeTable(BAlloc);
   for (ObjectFile *File : Symtab->ObjectFiles) {
     ArrayRef<uint8_t> Data = getDebugSection(File, ".debug$T");
     if (Data.empty())
@@ -132,10 +121,10 @@ static void mergeDebugT(SymbolTable *Sym
   }
 
   // Construct TPI stream contents.
-  addTypeInfo(Builder.getTpiBuilder(), TypeTable, TpiData);
+  addTypeInfo(Builder.getTpiBuilder(), TypeTable);
 
   // Construct IPI stream contents.
-  addTypeInfo(Builder.getIpiBuilder(), IDTable, IpiData);
+  addTypeInfo(Builder.getIpiBuilder(), IDTable);
 }
 
 static void dumpDebugT(ScopedPrinter &W, ObjectFile *File) {
@@ -213,9 +202,9 @@ void coff::createPDB(StringRef Path, Sym
   auto &DbiBuilder = Builder.getDbiBuilder();
   DbiBuilder.setVersionHeader(pdb::PdbDbiV110);
 
-  std::vector<uint8_t> TpiData;
-  std::vector<uint8_t> IpiData;
-  mergeDebugT(Symtab, Builder, TpiData, IpiData);
+  codeview::TypeTableBuilder TypeTable(BAlloc);
+  codeview::TypeTableBuilder IDTable(BAlloc);
+  mergeDebugT(Symtab, Builder, TypeTable, IDTable);
 
   // Add Section Contributions.
   std::vector<pdb::SectionContrib> Contribs =




More information about the llvm-commits mailing list