Use a CachedHashString for comdats too.

We were already using it in the larger sets/maps. This provides about
1% speedup in linking xul and chromium.

llvm-svn: 284862
This commit is contained in:
Rafael Espindola 2016-10-21 19:49:42 +00:00
parent 653baa2aaa
commit 8b2c8536e5
4 changed files with 25 additions and 19 deletions

View File

@ -141,7 +141,7 @@ template <class ELFT> uint32_t elf::ObjectFile<ELFT>::getMipsGp0() const {
}
template <class ELFT>
void elf::ObjectFile<ELFT>::parse(DenseSet<StringRef> &ComdatGroups) {
void elf::ObjectFile<ELFT>::parse(DenseSet<CachedHashStringRef> &ComdatGroups) {
// Read section and symbol tables.
initializeSections(ComdatGroups);
initializeSymbols();
@ -227,7 +227,7 @@ bool elf::ObjectFile<ELFT>::shouldMerge(const Elf_Shdr &Sec) {
template <class ELFT>
void elf::ObjectFile<ELFT>::initializeSections(
DenseSet<StringRef> &ComdatGroups) {
DenseSet<CachedHashStringRef> &ComdatGroups) {
uint64_t Size = this->ELFObj.getNumSections();
Sections.resize(Size);
unsigned I = -1;
@ -248,7 +248,8 @@ void elf::ObjectFile<ELFT>::initializeSections(
switch (Sec.sh_type) {
case SHT_GROUP:
Sections[I] = &InputSection<ELFT>::Discarded;
if (ComdatGroups.insert(getShtGroupSignature(Sec)).second)
if (ComdatGroups.insert(CachedHashStringRef(getShtGroupSignature(Sec)))
.second)
continue;
for (uint32_t SecIndex : getShtGroupEntries(Sec)) {
if (SecIndex >= Size)
@ -693,8 +694,8 @@ static uint8_t mapVisibility(GlobalValue::VisibilityTypes GvVisibility) {
}
template <class ELFT>
static Symbol *createBitcodeSymbol(DenseSet<StringRef> &KeptComdats,
DenseSet<StringRef> &ComdatGroups,
static Symbol *createBitcodeSymbol(DenseSet<CachedHashStringRef> &KeptComdats,
DenseSet<CachedHashStringRef> &ComdatGroups,
const lto::InputFile::Symbol &ObjSym,
StringSaver &Saver, BitcodeFile *F) {
StringRef NameRef = Saver.save(ObjSym.getName());
@ -707,12 +708,14 @@ static Symbol *createBitcodeSymbol(DenseSet<StringRef> &KeptComdats,
StringRef C = check(ObjSym.getComdat());
if (!C.empty()) {
bool Keep = KeptComdats.count(C);
auto CH = CachedHashStringRef(C);
bool Keep = KeptComdats.count(CH);
if (!Keep) {
StringRef N = Saver.save(C);
if (ComdatGroups.insert(N).second) {
CachedHashStringRef NH(N, CH.hash());
if (ComdatGroups.insert(NH).second) {
Keep = true;
KeptComdats.insert(C);
KeptComdats.insert(NH);
}
}
if (!Keep)
@ -734,7 +737,7 @@ static Symbol *createBitcodeSymbol(DenseSet<StringRef> &KeptComdats,
}
template <class ELFT>
void BitcodeFile::parse(DenseSet<StringRef> &ComdatGroups) {
void BitcodeFile::parse(DenseSet<CachedHashStringRef> &ComdatGroups) {
// Here we pass a new MemoryBufferRef which is identified by ArchiveName
// (the fully resolved path of the archive) + member name + offset of the
@ -747,7 +750,7 @@ void BitcodeFile::parse(DenseSet<StringRef> &ComdatGroups) {
Obj = check(lto::InputFile::create(MemoryBufferRef(
MB.getBuffer(), Saver.save(ArchiveName + MB.getBufferIdentifier() +
utostr(OffsetInArchive)))));
DenseSet<StringRef> KeptComdats;
DenseSet<CachedHashStringRef> KeptComdats;
for (const lto::InputFile::Symbol &ObjSym : Obj->symbols())
Symbols.push_back(createBitcodeSymbol<ELFT>(KeptComdats, ComdatGroups,
ObjSym, Saver, this));
@ -872,10 +875,10 @@ template void ArchiveFile::parse<ELF32BE>();
template void ArchiveFile::parse<ELF64LE>();
template void ArchiveFile::parse<ELF64BE>();
template void BitcodeFile::parse<ELF32LE>(DenseSet<StringRef> &);
template void BitcodeFile::parse<ELF32BE>(DenseSet<StringRef> &);
template void BitcodeFile::parse<ELF64LE>(DenseSet<StringRef> &);
template void BitcodeFile::parse<ELF64BE>(DenseSet<StringRef> &);
template void BitcodeFile::parse<ELF32LE>(DenseSet<CachedHashStringRef> &);
template void BitcodeFile::parse<ELF32BE>(DenseSet<CachedHashStringRef> &);
template void BitcodeFile::parse<ELF64LE>(DenseSet<CachedHashStringRef> &);
template void BitcodeFile::parse<ELF64BE>(DenseSet<CachedHashStringRef> &);
template void LazyObjectFile::parse<ELF32LE>();
template void LazyObjectFile::parse<ELF32BE>();

View File

@ -17,6 +17,7 @@
#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"
@ -151,7 +152,7 @@ public:
ArrayRef<SymbolBody *> getNonLocalSymbols();
explicit ObjectFile(MemoryBufferRef M);
void parse(llvm::DenseSet<StringRef> &ComdatGroups);
void parse(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
ArrayRef<InputSectionBase<ELFT> *> getSections() const { return Sections; }
InputSectionBase<ELFT> *getSection(const Elf_Sym &Sym) const;
@ -184,7 +185,8 @@ public:
llvm::BumpPtrAllocator Alloc;
private:
void initializeSections(llvm::DenseSet<StringRef> &ComdatGroups);
void
initializeSections(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
void initializeSymbols();
void initializeReverseDependencies();
InputSectionBase<ELFT> *getRelocTarget(const Elf_Shdr &Sec);
@ -261,7 +263,8 @@ class BitcodeFile : public InputFile {
public:
explicit BitcodeFile(MemoryBufferRef M);
static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
template <class ELFT> void parse(llvm::DenseSet<StringRef> &ComdatGroups);
template <class ELFT>
void parse(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
ArrayRef<Symbol *> getSymbols() { return Symbols; }
std::unique_ptr<llvm::lto::InputFile> Obj;

View File

@ -114,7 +114,7 @@ template <class ELFT> void SymbolTable<ELFT>::addCombinedLtoObject() {
for (InputFile *File : Lto->compile()) {
ObjectFile<ELFT> *Obj = cast<ObjectFile<ELFT>>(File);
DenseSet<StringRef> DummyGroups;
DenseSet<CachedHashStringRef> DummyGroups;
Obj->parse(DummyGroups);
ObjectFiles.push_back(Obj);
}

View File

@ -123,7 +123,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<StringRef> ComdatGroups;
llvm::DenseSet<llvm::CachedHashStringRef> ComdatGroups;
std::vector<ObjectFile<ELFT> *> ObjectFiles;
std::vector<SharedFile<ELFT> *> SharedFiles;