From 4a6f9ee16ea9306347f1bf6192be1e65c3bf307f Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Fri, 5 May 2017 22:02:37 +0000 Subject: [PATCH] [CodeView] Reserve TypeDatabase records up front. Most of the time we know exactly how many type records we have in a list, and we want to use the visitor to deserialize them into actual records in a database. Previously we were just using push_back() every time without reserving the space up front in the vector. This is obviously terrible from a performance standpoint, and it's not uncommon to have PDB files with half a million type records, where the performance degredation was quite noticeable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302302 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DebugInfo/CodeView/TypeDatabase.h | 2 +- lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 2 +- lib/DebugInfo/CodeView/TypeDatabase.cpp | 5 +++++ tools/llvm-pdbdump/Analyze.cpp | 2 +- tools/llvm-pdbdump/LLVMOutputStyle.cpp | 6 +++--- tools/llvm-readobj/COFFDumper.cpp | 6 +++--- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/llvm/DebugInfo/CodeView/TypeDatabase.h b/include/llvm/DebugInfo/CodeView/TypeDatabase.h index 220de4bf0ee..be7b19e7df0 100644 --- a/include/llvm/DebugInfo/CodeView/TypeDatabase.h +++ b/include/llvm/DebugInfo/CodeView/TypeDatabase.h @@ -21,7 +21,7 @@ namespace llvm { namespace codeview { class TypeDatabase { public: - TypeDatabase() : TypeNameStorage(Allocator) {} + explicit TypeDatabase(uint32_t ExpectedSize); /// Gets the type index for the next type record. TypeIndex getNextTypeIndex() const; diff --git a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index 28fa7826ad1..87b45c001de 100644 --- a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -469,7 +469,7 @@ void CodeViewDebug::emitTypeInformation() { CommentPrefix += ' '; } - TypeDatabase TypeDB; + TypeDatabase TypeDB(TypeTable.records().size()); CVTypeDumper CVTD(TypeDB); TypeTable.ForEachRecord([&](TypeIndex Index, ArrayRef Record) { if (OS.isVerboseAsm()) { diff --git a/lib/DebugInfo/CodeView/TypeDatabase.cpp b/lib/DebugInfo/CodeView/TypeDatabase.cpp index efaba4646ff..5b8841041f8 100644 --- a/lib/DebugInfo/CodeView/TypeDatabase.cpp +++ b/lib/DebugInfo/CodeView/TypeDatabase.cpp @@ -65,6 +65,11 @@ static const SimpleTypeEntry SimpleTypeNames[] = { {"__bool64*", SimpleTypeKind::Boolean64}, }; +TypeDatabase::TypeDatabase(uint32_t ExpectedSize) : TypeNameStorage(Allocator) { + CVUDTNames.reserve(ExpectedSize); + TypeRecords.reserve(ExpectedSize); +} + /// Gets the type index for the next type record. TypeIndex TypeDatabase::getNextTypeIndex() const { return TypeIndex(TypeIndex::FirstNonSimpleIndex + CVUDTNames.size()); diff --git a/tools/llvm-pdbdump/Analyze.cpp b/tools/llvm-pdbdump/Analyze.cpp index b65dd40d25f..f7d6ec53b03 100644 --- a/tools/llvm-pdbdump/Analyze.cpp +++ b/tools/llvm-pdbdump/Analyze.cpp @@ -74,7 +74,7 @@ Error AnalysisStyle::dump() { if (!Tpi) return Tpi.takeError(); - TypeDatabase TypeDB; + TypeDatabase TypeDB(Tpi->getNumTypeRecords()); TypeDatabaseVisitor DBV(TypeDB); TypeDeserializer Deserializer; TypeVisitorCallbackPipeline Pipeline; diff --git a/tools/llvm-pdbdump/LLVMOutputStyle.cpp b/tools/llvm-pdbdump/LLVMOutputStyle.cpp index ca7efa69939..2dd4ef0fb30 100644 --- a/tools/llvm-pdbdump/LLVMOutputStyle.cpp +++ b/tools/llvm-pdbdump/LLVMOutputStyle.cpp @@ -631,7 +631,7 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) { Visitors.push_back(make_unique()); if (!StreamDB.hasValue()) { - StreamDB.emplace(); + StreamDB.emplace(Tpi->getNumTypeRecords()); Visitors.push_back(make_unique(*StreamDB)); } // If we're in dump mode, add a dumper with the appropriate detail level. @@ -722,14 +722,14 @@ Error LLVMOutputStyle::buildTypeDatabase(uint32_t SN) { if (DB.hasValue()) return Error::success(); - DB.emplace(); - auto Tpi = (SN == StreamTPI) ? File.getPDBTpiStream() : File.getPDBIpiStream(); if (!Tpi) return Tpi.takeError(); + DB.emplace(Tpi->getNumTypeRecords()); + TypeVisitorCallbackPipeline Pipeline; TypeDeserializer Deserializer; TypeDatabaseVisitor DBV(*DB); diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 04386875b95..3f4b6c79178 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -70,7 +70,7 @@ class COFFDumper : public ObjDumper { public: friend class COFFObjectDumpDelegate; COFFDumper(const llvm::object::COFFObjectFile *Obj, ScopedPrinter &Writer) - : ObjDumper(Writer), Obj(Obj), Writer(Writer) {} + : ObjDumper(Writer), Obj(Obj), Writer(Writer), TypeDB(100) {} void printFileHeaders() override; void printSections() override; @@ -1553,7 +1553,7 @@ void llvm::dumpCodeViewMergedTypes(ScopedPrinter &Writer, TypeBuf.append(Record.begin(), Record.end()); }); - TypeDatabase TypeDB; + TypeDatabase TypeDB(CVTypes.records().size()); { ListScope S(Writer, "MergedTypeStream"); CVTypeDumper CVTD(TypeDB); @@ -1574,7 +1574,7 @@ void llvm::dumpCodeViewMergedTypes(ScopedPrinter &Writer, { ListScope S(Writer, "MergedIDStream"); - TypeDatabase IDDB; + TypeDatabase IDDB(IDTable.records().size()); CVTypeDumper CVTD(IDDB); TypeDumpVisitor TDV(TypeDB, &Writer, opts::CodeViewSubsectionBytes); TDV.setItemDB(IDDB); -- 2.11.0