From dcf6234dade8f8333ebec7412288d80ddd3b9081 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 1 Mar 2018 23:29:05 +0000 Subject: [PATCH] [WebAssembly] Simplify COMDAT handling. Differential Revision: https://reviews.llvm.org/D43966 llvm-svn: 326509 --- lld/wasm/InputFiles.cpp | 9 ++++----- lld/wasm/SymbolTable.cpp | 16 ++-------------- lld/wasm/SymbolTable.h | 7 ++++--- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index fc5caee..fab6db2 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -117,9 +117,6 @@ void ObjFile::parse() { TypeMap.resize(getWasmObj()->types().size()); TypeIsUsed.resize(getWasmObj()->types().size(), false); - for (StringRef Name : WasmObj->comdats()) - Symtab->addComdat(Name, this); - // Populate `Segments`. for (const WasmSegment &S : WasmObj->dataSegments()) { InputSegment *Seg = make(S, this); @@ -156,8 +153,10 @@ void ObjFile::parse() { } bool ObjFile::isExcludedByComdat(InputChunk *Chunk) const { - StringRef Comdat = Chunk->getComdat(); - return !Comdat.empty() && Symtab->findComdat(Comdat) != this; + StringRef S = Chunk->getComdat(); + if (S.empty()) + return false; + return !Symtab->addComdat(S, this); } FunctionSymbol *ObjFile::getFunctionSymbol(uint32_t Index) const { diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp index 5a2f153..6375358 100644 --- a/lld/wasm/SymbolTable.cpp +++ b/lld/wasm/SymbolTable.cpp @@ -301,18 +301,6 @@ void SymbolTable::addLazy(ArchiveFile *File, const Archive::Symbol *Sym) { } } -bool SymbolTable::addComdat(StringRef Name, ObjFile *F) { - DEBUG(dbgs() << "addComdat: " << Name << "\n"); - ObjFile *&File = ComdatMap[CachedHashStringRef(Name)]; - if (File) { - DEBUG(dbgs() << "COMDAT already defined\n"); - return false; - } - File = F; - return true; -} - -ObjFile *SymbolTable::findComdat(StringRef Name) const { - auto It = ComdatMap.find(CachedHashStringRef(Name)); - return It == ComdatMap.end() ? nullptr : It->second; +bool SymbolTable::addComdat(StringRef Name, const ObjFile *File) { + return Comdats.insert({Name, File}).first->second == File; } diff --git a/lld/wasm/SymbolTable.h b/lld/wasm/SymbolTable.h index ac1aa29..466ed10 100644 --- a/lld/wasm/SymbolTable.h +++ b/lld/wasm/SymbolTable.h @@ -46,7 +46,6 @@ public: ArrayRef getSymbols() const { return SymVector; } Symbol *find(StringRef Name); - ObjFile *findComdat(StringRef Name) const; Symbol *addDefinedFunction(StringRef Name, uint32_t Flags, InputFile *File, InputFunction *Function); @@ -63,7 +62,8 @@ public: const WasmGlobalType *Type); void addLazy(ArchiveFile *F, const Archive::Symbol *Sym); - bool addComdat(StringRef Name, ObjFile *); + + bool addComdat(StringRef Name, const ObjFile *File); DefinedData *addSyntheticDataSymbol(StringRef Name, uint32_t Flags); DefinedGlobal *addSyntheticGlobal(StringRef Name, uint32_t Flags, @@ -75,9 +75,10 @@ public: private: std::pair insert(StringRef Name); - llvm::DenseMap ComdatMap; llvm::DenseMap SymMap; std::vector SymVector; + + llvm::DenseMap Comdats; }; extern SymbolTable *Symtab; -- 2.7.4