[lld] r322871 - Speed up iteration of CodeView record streams.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 10:35:02 PST 2018


Author: zturner
Date: Thu Jan 18 10:35:01 2018
New Revision: 322871

URL: http://llvm.org/viewvc/llvm-project?rev=322871&view=rev
Log:
Speed up iteration of CodeView record streams.

There's some abstraction overhead in the underlying
mechanisms that were being used, and it was leading to an
abundance of small but not-free copies being made.  This
showed up on a profile.  Eliminating this and going back to
a low-level byte-based implementation speeds up lld with
/DEBUG between 10 and 15%.

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

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=322871&r1=322870&r2=322871&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Thu Jan 18 10:35:01 2018
@@ -677,54 +677,61 @@ static void mergeSymbolRecords(BumpPtrAl
                                BinaryStreamRef SymData) {
   // FIXME: Improve error recovery by warning and skipping records when
   // possible.
-  CVSymbolArray Syms;
-  BinaryStreamReader Reader(SymData);
-  ExitOnErr(Reader.readArray(Syms, Reader.getLength()));
+  ArrayRef<uint8_t> SymsBuffer;
+  cantFail(SymData.readBytes(0, SymData.getLength(), SymsBuffer));
   SmallVector<SymbolScope, 4> Scopes;
-  for (CVSymbol Sym : Syms) {
-    // Discover type index references in the record. Skip it if we don't know
-    // where they are.
-    SmallVector<TiReference, 32> TypeRefs;
-    if (!discoverTypeIndicesInSymbol(Sym, TypeRefs)) {
-      log("ignoring unknown symbol record with kind 0x" + utohexstr(Sym.kind()));
-      continue;
-    }
-
-    // Copy the symbol record so we can mutate it.
-    MutableArrayRef<uint8_t> NewData = copySymbolForPdb(Sym, Alloc);
-
-    // Re-map all the type index references.
-    MutableArrayRef<uint8_t> Contents =
-        NewData.drop_front(sizeof(RecordPrefix));
-    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.
-    translateIdSymbols(NewData, IDTable);
-
-    // If this record refers to an offset in the object file's string table,
-    // add that item to the global PDB string table and re-write the index.
-    recordStringTableReferences(Sym.kind(), Contents, StringTableRefs);
-
-    SymbolKind NewKind = symbolKind(NewData);
-
-    // Fill in "Parent" and "End" fields by maintaining a stack of scopes.
-    CVSymbol NewSym(NewKind, NewData);
-    if (symbolOpensScope(NewKind))
-      scopeStackOpen(Scopes, File->ModuleDBI->getNextSymbolOffset(), NewSym);
-    else if (symbolEndsScope(NewKind))
-      scopeStackClose(Scopes, File->ModuleDBI->getNextSymbolOffset(), File);
-
-    // Add the symbol to the globals stream if necessary.  Do this before adding
-    // the symbol to the module since we may need to get the next symbol offset,
-    // and writing to the module's symbol stream will update that offset.
-    if (symbolGoesInGlobalsStream(NewSym))
-      addGlobalSymbol(GsiBuilder, *File, NewSym);
-
-    // Add the symbol to the module.
-    if (symbolGoesInModuleStream(NewSym))
-      File->ModuleDBI->addSymbol(NewSym);
-  }
+
+  auto EC = forEachCodeViewRecord<CVSymbol>(
+      SymsBuffer, [&](const CVSymbol &Sym) -> llvm::Error {
+        // Discover type index references in the record. Skip it if we don't
+        // know where they are.
+        SmallVector<TiReference, 32> TypeRefs;
+        if (!discoverTypeIndicesInSymbol(Sym, TypeRefs)) {
+          log("ignoring unknown symbol record with kind 0x" +
+              utohexstr(Sym.kind()));
+          return Error::success();
+        }
+
+        // Copy the symbol record so we can mutate it.
+        MutableArrayRef<uint8_t> NewData = copySymbolForPdb(Sym, Alloc);
+
+        // Re-map all the type index references.
+        MutableArrayRef<uint8_t> Contents =
+            NewData.drop_front(sizeof(RecordPrefix));
+        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.
+        translateIdSymbols(NewData, IDTable);
+
+        // If this record refers to an offset in the object file's string table,
+        // add that item to the global PDB string table and re-write the index.
+        recordStringTableReferences(Sym.kind(), Contents, StringTableRefs);
+
+        SymbolKind NewKind = symbolKind(NewData);
+
+        // Fill in "Parent" and "End" fields by maintaining a stack of scopes.
+        CVSymbol NewSym(NewKind, NewData);
+        if (symbolOpensScope(NewKind))
+          scopeStackOpen(Scopes, File->ModuleDBI->getNextSymbolOffset(),
+                         NewSym);
+        else if (symbolEndsScope(NewKind))
+          scopeStackClose(Scopes, File->ModuleDBI->getNextSymbolOffset(), File);
+
+        // Add the symbol to the globals stream if necessary.  Do this before
+        // adding the symbol to the module since we may need to get the next
+        // symbol offset, and writing to the module's symbol stream will update
+        // that offset.
+        if (symbolGoesInGlobalsStream(NewSym))
+          addGlobalSymbol(GsiBuilder, *File, NewSym);
+
+        // Add the symbol to the module.
+        if (symbolGoesInModuleStream(NewSym))
+          File->ModuleDBI->addSymbol(NewSym);
+        return Error::success();
+      });
+  cantFail(std::move(EC));
 }
 
 // Allocate memory for a .debug$S section and relocate it.




More information about the llvm-commits mailing list