diff options
author | Nicholas Wilson <nicholas@nicholaswilson.me.uk> | 2018-03-14 15:45:11 +0000 |
---|---|---|
committer | Nicholas Wilson <nicholas@nicholaswilson.me.uk> | 2018-03-14 15:45:11 +0000 |
commit | c4d9aa1b5f9b7cd5982cdd3241a839bef22967ba (patch) | |
tree | 533a254d25aefb214ffb076dbb7e44d81e020f17 | |
parent | 027b9357a8f23fdf9b0ab013ff27eaf9ec080961 (diff) | |
download | bcm5719-llvm-c4d9aa1b5f9b7cd5982cdd3241a839bef22967ba.tar.gz bcm5719-llvm-c4d9aa1b5f9b7cd5982cdd3241a839bef22967ba.zip |
[WebAssembly] Avoid COMDAT hashmap lookup for each symbol. NFC
This reduces the number of lookups to one per COMDAT group, rather than
one per symbol in a COMDAT group.
Differential Revision: https://reviews.llvm.org/D44344
llvm-svn: 327523
-rw-r--r-- | lld/wasm/InputChunks.cpp | 7 | ||||
-rw-r--r-- | lld/wasm/InputChunks.h | 9 | ||||
-rw-r--r-- | lld/wasm/InputFiles.cpp | 11 | ||||
-rw-r--r-- | lld/wasm/InputFiles.h | 1 | ||||
-rw-r--r-- | lld/wasm/SymbolTable.cpp | 4 | ||||
-rw-r--r-- | lld/wasm/SymbolTable.h | 6 | ||||
-rw-r--r-- | lld/wasm/Writer.cpp | 6 |
7 files changed, 29 insertions, 15 deletions
diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp index ef3edb8b9ca..0cac19b3d4e 100644 --- a/lld/wasm/InputChunks.cpp +++ b/lld/wasm/InputChunks.cpp @@ -36,6 +36,13 @@ std::string lld::toString(const InputChunk *C) { return (toString(C->File) + ":(" + C->getName() + ")").str(); } +StringRef InputChunk::getComdatName() const { + uint32_t Index = getComdat(); + if (Index == UINT32_MAX) + return StringRef(); + return File->getWasmObj()->linkingData().Comdats[Index]; +} + void InputChunk::copyRelocations(const WasmSection &Section) { if (Section.Relocations.empty()) return; diff --git a/lld/wasm/InputChunks.h b/lld/wasm/InputChunks.h index f4e08ab4c25..3d6ea23680f 100644 --- a/lld/wasm/InputChunks.h +++ b/lld/wasm/InputChunks.h @@ -56,8 +56,9 @@ public: ArrayRef<WasmRelocation> getRelocations() const { return Relocations; } - virtual StringRef getComdat() const = 0; virtual StringRef getName() const = 0; + virtual uint32_t getComdat() const = 0; + StringRef getComdatName() const; size_t NumRelocations() const { return Relocations.size(); } void writeRelocations(llvm::raw_ostream &OS) const; @@ -98,7 +99,7 @@ public: uint32_t getAlignment() const { return Segment.Data.Alignment; } StringRef getName() const override { return Segment.Data.Name; } - StringRef getComdat() const override { return Segment.Data.Comdat; } + uint32_t getComdat() const override { return Segment.Data.Comdat; } const OutputSegment *OutputSeg = nullptr; int32_t OutputSegmentOffset = 0; @@ -125,7 +126,7 @@ public: } StringRef getName() const override { return Function->Name; } - StringRef getComdat() const override { return Function->Comdat; } + uint32_t getComdat() const override { return Function->Comdat; } uint32_t getFunctionIndex() const { return FunctionIndex.getValue(); } bool hasFunctionIndex() const { return FunctionIndex.hasValue(); } void setFunctionIndex(uint32_t Index); @@ -161,7 +162,7 @@ public: } StringRef getName() const override { return Name; } - StringRef getComdat() const override { return StringRef(); } + uint32_t getComdat() const override { return UINT32_MAX; } void setBody(ArrayRef<uint8_t> Body_) { Body = Body_; } diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 52be12ac51a..e7436863461 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -158,6 +158,11 @@ void ObjFile::parse() { TypeMap.resize(getWasmObj()->types().size()); TypeIsUsed.resize(getWasmObj()->types().size(), false); + ArrayRef<StringRef> Comdats = WasmObj->linkingData().Comdats; + UsedComdats.resize(Comdats.size()); + for (unsigned I = 0; I < Comdats.size(); ++I) + UsedComdats[I] = Symtab->addComdat(Comdats[I]); + // Populate `Segments`. for (const WasmSegment &S : WasmObj->dataSegments()) { InputSegment *Seg = make<InputSegment>(S, this); @@ -194,10 +199,10 @@ void ObjFile::parse() { } bool ObjFile::isExcludedByComdat(InputChunk *Chunk) const { - StringRef S = Chunk->getComdat(); - if (S.empty()) + uint32_t C = Chunk->getComdat(); + if (C == UINT32_MAX) return false; - return !Symtab->addComdat(S, this); + return !UsedComdats[C]; } FunctionSymbol *ObjFile::getFunctionSymbol(uint32_t Index) const { diff --git a/lld/wasm/InputFiles.h b/lld/wasm/InputFiles.h index 1239e5bcabd..f0fd267d910 100644 --- a/lld/wasm/InputFiles.h +++ b/lld/wasm/InputFiles.h @@ -104,6 +104,7 @@ public: std::vector<bool> TypeIsUsed; // Maps function indices to table indices std::vector<uint32_t> TableEntries; + std::vector<bool> UsedComdats; std::vector<InputSegment *> Segments; std::vector<InputFunction *> Functions; std::vector<InputGlobal *> Globals; diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp index a722472c291..153b507f89d 100644 --- a/lld/wasm/SymbolTable.cpp +++ b/lld/wasm/SymbolTable.cpp @@ -304,6 +304,6 @@ void SymbolTable::addLazy(ArchiveFile *File, const Archive::Symbol *Sym) { } } -bool SymbolTable::addComdat(StringRef Name, const ObjFile *File) { - return Comdats.insert({Name, File}).first->second == File; +bool SymbolTable::addComdat(StringRef Name) { + return Comdats.insert(CachedHashStringRef(Name)).second; } diff --git a/lld/wasm/SymbolTable.h b/lld/wasm/SymbolTable.h index 17c5a3bb699..6fb5c15782d 100644 --- a/lld/wasm/SymbolTable.h +++ b/lld/wasm/SymbolTable.h @@ -13,7 +13,7 @@ #include "InputFiles.h" #include "Symbols.h" #include "llvm/ADT/CachedHashString.h" -#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/Support/raw_ostream.h" using llvm::wasm::WasmGlobalType; @@ -65,7 +65,7 @@ public: void addLazy(ArchiveFile *F, const Archive::Symbol *Sym); - bool addComdat(StringRef Name, const ObjFile *File); + bool addComdat(StringRef Name); DefinedData *addSyntheticDataSymbol(StringRef Name, uint32_t Flags); DefinedGlobal *addSyntheticGlobal(StringRef Name, uint32_t Flags, @@ -79,7 +79,7 @@ private: llvm::DenseMap<llvm::CachedHashStringRef, Symbol *> SymMap; std::vector<Symbol *> SymVector; - llvm::DenseMap<StringRef, const ObjFile *> Comdats; + llvm::DenseSet<llvm::CachedHashStringRef> Comdats; }; extern SymbolTable *Symtab; diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index b6ffd1ef983..3c6a90bf1bb 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -477,7 +477,7 @@ void Writer::createLinkingSection() { std::map<StringRef, std::vector<ComdatEntry>> Comdats; for (const InputFunction *F : InputFunctions) { - StringRef Comdat = F->getComdat(); + StringRef Comdat = F->getComdatName(); if (!Comdat.empty()) Comdats[Comdat].emplace_back( ComdatEntry{WASM_COMDAT_FUNCTION, F->getFunctionIndex()}); @@ -486,10 +486,10 @@ void Writer::createLinkingSection() { const auto &InputSegments = Segments[I]->InputSegments; if (InputSegments.empty()) continue; - StringRef Comdat = InputSegments[0]->getComdat(); + StringRef Comdat = InputSegments[0]->getComdatName(); #ifndef NDEBUG for (const InputSegment *IS : InputSegments) - assert(IS->getComdat() == Comdat); + assert(IS->getComdatName() == Comdat); #endif if (!Comdat.empty()) Comdats[Comdat].emplace_back(ComdatEntry{WASM_COMDAT_DATA, I}); |