[lld] r319345 - Make TypeTableBuilder inherit from TypeCollection.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 11:35:22 PST 2017


Author: zturner
Date: Wed Nov 29 11:35:21 2017
New Revision: 319345

URL: http://llvm.org/viewvc/llvm-project?rev=319345&view=rev
Log:
Make TypeTableBuilder inherit from TypeCollection.

A couple of places in LLD were passing references to
TypeTableCollections around, which makes it hard to change the
implementation at runtime.  However, these cases only needed to
iterate over the types in the collection, and TypeCollection
already provides a handy abstract interface for this purpose.

By implementing this interface, we can get rid of the need to
pass TypeTableBuilder references around, which should allow us
to swap the implementation at runtime in subsequent patches.

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=319345&r1=319344&r2=319345&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Wed Nov 29 11:35:21 2017
@@ -161,19 +161,16 @@ static ArrayRef<uint8_t> getDebugSection
 }
 
 static void addTypeInfo(pdb::TpiStreamBuilder &TpiBuilder,
-                        TypeTableBuilder &TypeTable) {
+                        TypeCollection &TypeTable) {
   // Start the TPI or IPI stream header.
   TpiBuilder.setVersionHeader(pdb::PdbTpiV80);
 
   // Flatten the in memory type table and hash each type.
-  TypeTable.ForEachRecord([&](TypeIndex TI, ArrayRef<uint8_t> Rec) {
-    assert(Rec.size() >= sizeof(RecordPrefix));
-    const RecordPrefix *P = reinterpret_cast<const RecordPrefix *>(Rec.data());
-    CVType Type(static_cast<TypeLeafKind>(unsigned(P->RecordKind)), Rec);
+  TypeTable.ForEachRecord([&](TypeIndex TI, const CVType &Type) {
     auto Hash = pdb::hashTypeRecord(Type);
     if (auto E = Hash.takeError())
       fatal("type hashing error");
-    TpiBuilder.addTypeRecord(Rec, *Hash);
+    TpiBuilder.addTypeRecord(Type.RecordData, *Hash);
   });
 }
 
@@ -308,7 +305,6 @@ static bool remapTypeIndex(TypeIndex &TI
 static void remapTypesInSymbolRecord(ObjFile *File, SymbolKind SymKind,
                                      MutableArrayRef<uint8_t> Contents,
                                      const CVIndexMap &IndexMap,
-                                     const TypeTableBuilder &IDTable,
                                      ArrayRef<TiReference> TypeRefs) {
   for (const TiReference &Ref : TypeRefs) {
     unsigned ByteSize = Ref.Count * sizeof(TypeIndex);
@@ -343,7 +339,7 @@ static SymbolKind symbolKind(ArrayRef<ui
 
 /// MSVC translates S_PROC_ID_END to S_END, and S_[LG]PROC32_ID to S_[LG]PROC32
 static void translateIdSymbols(MutableArrayRef<uint8_t> &RecordData,
-                               const TypeTableBuilder &IDTable) {
+                               TypeCollection &IDTable) {
   RecordPrefix *Prefix = reinterpret_cast<RecordPrefix *>(RecordData.data());
 
   SymbolKind Kind = symbolKind(RecordData);
@@ -373,7 +369,7 @@ static void translateIdSymbols(MutableAr
     // Note that LF_FUNC_ID and LF_MEMFUNC_ID have the same record layout, and
     // in both cases we just need the second type index.
     if (!TI->isSimple() && !TI->isNoneType()) {
-      ArrayRef<uint8_t> FuncIdData = IDTable.records()[TI->toArrayIndex()];
+      CVType FuncIdData = IDTable.getType(*TI);
       SmallVector<TypeIndex, 2> Indices;
       discoverTypeIndices(FuncIdData, Indices);
       assert(Indices.size() == 2);
@@ -550,7 +546,7 @@ static void addGlobalSymbol(pdb::GSIStre
 static void mergeSymbolRecords(BumpPtrAllocator &Alloc, ObjFile *File,
                                pdb::GSIStreamBuilder &GsiBuilder,
                                const CVIndexMap &IndexMap,
-                               const TypeTableBuilder &IDTable,
+                               TypeCollection &IDTable,
                                BinaryStreamRef SymData) {
   // FIXME: Improve error recovery by warning and skipping records when
   // possible.
@@ -573,8 +569,7 @@ static void mergeSymbolRecords(BumpPtrAl
     // Re-map all the type index references.
     MutableArrayRef<uint8_t> Contents =
         NewData.drop_front(sizeof(RecordPrefix));
-    remapTypesInSymbolRecord(File, Sym.kind(), Contents, IndexMap, IDTable,
-                             TypeRefs);
+    remapTypesInSymbolRecord(File, Sym.kind(), Contents, IndexMap, TypeRefs);
 
     // An object file may have S_xxx_ID symbols, but these get converted to
     // "real" symbols in a PDB.




More information about the llvm-commits mailing list