[llvm] r303676 - [CodeView] Eliminate redundant hashes and allocations.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Tue May 23 11:56:23 PDT 2017


Author: zturner
Date: Tue May 23 13:56:23 2017
New Revision: 303676

URL: http://llvm.org/viewvc/llvm-project?rev=303676&view=rev
Log:
[CodeView] Eliminate redundant hashes and allocations.

When writing field list records, we would construct a temporary
type serializer that shared a bump ptr allocator with the rest
of the application, so anything allocated from here would live
forever.  Furthermore, this temporary serializer had all the
properties of a full blown serializer including record hashing
and de-duplication.

These features are required when you're merging multiple type
streams into each other, because different streams may contain
identical records, but records from the same type stream will
never collide with each other.  So all of this hashing was
unnecessary.

To solve this, two fixes are made:

1) The temporary serializer keeps its own bump ptr allocator
instead of sharing a global one.  When it's finished, all of
its memory is freed.

2) Instead of using the same temporary serializer for the life
of an entire type stream, we use it only for the life of a single
field list record and delete it when the field list record is
completed.  This way the hash table will not grow as other
records from the same type stream get inserted.  Further improvements
could eliminate hashing entirely from this codepath.

This reduces the link time by 85% in my test, from 1 minute to 9
seconds.

Modified:
    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeTableBuilder.h
    llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeTableBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeTableBuilder.h?rev=303676&r1=303675&r2=303676&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeTableBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeTableBuilder.h Tue May 23 13:56:23 2017
@@ -82,12 +82,13 @@ public:
 
 class FieldListRecordBuilder {
   TypeTableBuilder &TypeTable;
+  BumpPtrAllocator Allocator;
   TypeSerializer TempSerializer;
   CVType Type;
 
 public:
   explicit FieldListRecordBuilder(TypeTableBuilder &TypeTable)
-      : TypeTable(TypeTable), TempSerializer(TypeTable.getAllocator()) {
+      : TypeTable(TypeTable), TempSerializer(Allocator) {
     Type.Type = TypeLeafKind::LF_FIELDLIST;
   }
 

Modified: llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp?rev=303676&r1=303675&r2=303676&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp Tue May 23 13:56:23 2017
@@ -416,6 +416,8 @@ Error TypeStreamMerger::visitKnownRecord
   assert(DestTypeStream);
   // Visit the members inside the field list.
   HadUntranslatedMember = false;
+  FieldListBuilder = llvm::make_unique<FieldListRecordBuilder>(*DestTypeStream);
+
   FieldListBuilder->begin();
   if (auto EC = codeview::visitMemberRecordStream(R.Data, *this))
     return EC;
@@ -428,6 +430,7 @@ Error TypeStreamMerger::visitKnownRecord
     FieldListBuilder->reset();
   addMapping(DestIdx);
 
+  FieldListBuilder.reset();
   return Error::success();
 }
 
@@ -496,7 +499,6 @@ Error TypeStreamMerger::visitUnknownType
 Error TypeStreamMerger::mergeTypeRecords(TypeTableBuilder &Dest,
                                          TypeCollection &Types) {
   DestTypeStream = &Dest;
-  FieldListBuilder = llvm::make_unique<FieldListRecordBuilder>(Dest);
 
   return doit(Types);
 }
@@ -515,7 +517,6 @@ Error TypeStreamMerger::mergeTypesAndIds
                                          TypeCollection &IdsAndTypes) {
   DestIdStream = &DestIds;
   DestTypeStream = &DestTypes;
-  FieldListBuilder = llvm::make_unique<FieldListRecordBuilder>(DestTypes);
 
   return doit(IdsAndTypes);
 }




More information about the llvm-commits mailing list