[lld] r327523 - [WebAssembly] Avoid COMDAT hashmap lookup for each symbol. NFC
Nicholas Wilson via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 14 08:45:11 PDT 2018
Author: ncw
Date: Wed Mar 14 08:45:11 2018
New Revision: 327523
URL: http://llvm.org/viewvc/llvm-project?rev=327523&view=rev
Log:
[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
Modified:
lld/trunk/wasm/InputChunks.cpp
lld/trunk/wasm/InputChunks.h
lld/trunk/wasm/InputFiles.cpp
lld/trunk/wasm/InputFiles.h
lld/trunk/wasm/SymbolTable.cpp
lld/trunk/wasm/SymbolTable.h
lld/trunk/wasm/Writer.cpp
Modified: lld/trunk/wasm/InputChunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputChunks.cpp?rev=327523&r1=327522&r2=327523&view=diff
==============================================================================
--- lld/trunk/wasm/InputChunks.cpp (original)
+++ lld/trunk/wasm/InputChunks.cpp Wed Mar 14 08:45:11 2018
@@ -36,6 +36,13 @@ std::string lld::toString(const InputChu
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;
Modified: lld/trunk/wasm/InputChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputChunks.h?rev=327523&r1=327522&r2=327523&view=diff
==============================================================================
--- lld/trunk/wasm/InputChunks.h (original)
+++ lld/trunk/wasm/InputChunks.h Wed Mar 14 08:45:11 2018
@@ -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_; }
Modified: lld/trunk/wasm/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.cpp?rev=327523&r1=327522&r2=327523&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.cpp (original)
+++ lld/trunk/wasm/InputFiles.cpp Wed Mar 14 08:45:11 2018
@@ -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 {
Modified: lld/trunk/wasm/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.h?rev=327523&r1=327522&r2=327523&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.h (original)
+++ lld/trunk/wasm/InputFiles.h Wed Mar 14 08:45:11 2018
@@ -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;
Modified: lld/trunk/wasm/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.cpp?rev=327523&r1=327522&r2=327523&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.cpp (original)
+++ lld/trunk/wasm/SymbolTable.cpp Wed Mar 14 08:45:11 2018
@@ -304,6 +304,6 @@ void SymbolTable::addLazy(ArchiveFile *F
}
}
-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;
}
Modified: lld/trunk/wasm/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.h?rev=327523&r1=327522&r2=327523&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.h (original)
+++ lld/trunk/wasm/SymbolTable.h Wed Mar 14 08:45:11 2018
@@ -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;
Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=327523&r1=327522&r2=327523&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Wed Mar 14 08:45:11 2018
@@ -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});
More information about the llvm-commits
mailing list