From 466c82b74f72c6b122e97a3a4c903c173045ef08 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 24 May 2017 18:22:27 +0000 Subject: [PATCH] Simplify a variable type by using StringRef instead of CachedHashStringRef. A variable `ComdatGroup` is not supposed to contain a large number of items. Even when linking clang, it ends up having only 300K strings. It doesn't make sense to use CachedHashStringRef for this hash table. This patch has neutral or slightly positive impact on performance while reducing code complexity. llvm-svn: 303787 --- lld/ELF/InputFiles.cpp | 21 +++++++++------------ lld/ELF/InputFiles.h | 9 +++------ lld/ELF/SymbolTable.cpp | 2 +- lld/ELF/SymbolTable.h | 2 +- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index fe036a644f41..05140d49d270 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -192,7 +192,7 @@ ArrayRef elf::ObjectFile::getSymbols() { } template -void elf::ObjectFile::parse(DenseSet &ComdatGroups) { +void elf::ObjectFile::parse(DenseSet &ComdatGroups) { // Read section and symbol tables. initializeSections(ComdatGroups); initializeSymbols(); @@ -280,7 +280,7 @@ bool elf::ObjectFile::shouldMerge(const Elf_Shdr &Sec) { template void elf::ObjectFile::initializeSections( - DenseSet &ComdatGroups) { + DenseSet &ComdatGroups) { ArrayRef ObjSections = check(this->getObj().sections(), toString(this)); const ELFFile &Obj = this->getObj(); @@ -305,10 +305,7 @@ void elf::ObjectFile::initializeSections( switch (Sec.sh_type) { case SHT_GROUP: this->Sections[I] = &InputSection::Discarded; - if (ComdatGroups - .insert( - CachedHashStringRef(getShtGroupSignature(ObjSections, Sec))) - .second) + if (ComdatGroups.insert(getShtGroupSignature(ObjSections, Sec)).second) continue; for (uint32_t SecIndex : getShtGroupEntries(Sec)) { if (SecIndex >= Size) @@ -876,10 +873,10 @@ static Symbol *createBitcodeSymbol(const std::vector &KeptComdats, } template -void BitcodeFile::parse(DenseSet &ComdatGroups) { +void BitcodeFile::parse(DenseSet &ComdatGroups) { std::vector KeptComdats; for (StringRef S : Obj->getComdatTable()) - KeptComdats.push_back(ComdatGroups.insert(CachedHashStringRef(S)).second); + KeptComdats.push_back(ComdatGroups.insert(StringRef(S)).second); for (const lto::InputFile::Symbol &ObjSym : Obj->symbols()) Symbols.push_back(createBitcodeSymbol(KeptComdats, ObjSym, this)); @@ -1048,10 +1045,10 @@ template void ArchiveFile::parse(); template void ArchiveFile::parse(); template void ArchiveFile::parse(); -template void BitcodeFile::parse(DenseSet &); -template void BitcodeFile::parse(DenseSet &); -template void BitcodeFile::parse(DenseSet &); -template void BitcodeFile::parse(DenseSet &); +template void BitcodeFile::parse(DenseSet &); +template void BitcodeFile::parse(DenseSet &); +template void BitcodeFile::parse(DenseSet &); +template void BitcodeFile::parse(DenseSet &); template void LazyObjectFile::parse(); template void LazyObjectFile::parse(); diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 6daf26649859..8b0e2e3f0bcd 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -17,7 +17,6 @@ #include "lld/Core/LLVM.h" #include "lld/Core/Reproduce.h" -#include "llvm/ADT/CachedHashString.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/STLExtras.h" #include "llvm/IR/Comdat.h" @@ -157,7 +156,7 @@ public: ArrayRef getLocalSymbols(); ObjectFile(MemoryBufferRef M, StringRef ArchiveName); - void parse(llvm::DenseSet &ComdatGroups); + void parse(llvm::DenseSet &ComdatGroups); InputSectionBase *getSection(const Elf_Sym &Sym) const; @@ -189,8 +188,7 @@ public: StringRef SourceFile; private: - void - initializeSections(llvm::DenseSet &ComdatGroups); + void initializeSections(llvm::DenseSet &ComdatGroups); void initializeSymbols(); void initializeDwarfLine(); InputSectionBase *getRelocTarget(const Elf_Shdr &Sec); @@ -265,8 +263,7 @@ public: BitcodeFile(MemoryBufferRef M, StringRef ArchiveName, uint64_t OffsetInArchive); static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; } - template - void parse(llvm::DenseSet &ComdatGroups); + template void parse(llvm::DenseSet &ComdatGroups); ArrayRef getSymbols() { return Symbols; } std::unique_ptr Obj; diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index ed8a790c9599..dae294fca6ee 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -122,7 +122,7 @@ template void SymbolTable::addCombinedLTOObject() { for (InputFile *File : LTO->compile()) { ObjectFile *Obj = cast>(File); - DenseSet DummyGroups; + DenseSet DummyGroups; Obj->parse(DummyGroups); ObjectFiles.push_back(Obj); } diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h index 1a745f9deea5..2f39e98e4a68 100644 --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -117,7 +117,7 @@ private: // Comdat groups define "link once" sections. If two comdat groups have the // same name, only one of them is linked, and the other is ignored. This set // is used to uniquify them. - llvm::DenseSet ComdatGroups; + llvm::DenseSet ComdatGroups; std::vector *> ObjectFiles; std::vector *> SharedFiles;