[lld] r326509 - [WebAssembly] Simplify COMDAT handling.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 1 15:29:05 PST 2018
Author: ruiu
Date: Thu Mar 1 15:29:05 2018
New Revision: 326509
URL: http://llvm.org/viewvc/llvm-project?rev=326509&view=rev
Log:
[WebAssembly] Simplify COMDAT handling.
Differential Revision: https://reviews.llvm.org/D43966
Modified:
lld/trunk/wasm/InputFiles.cpp
lld/trunk/wasm/SymbolTable.cpp
lld/trunk/wasm/SymbolTable.h
Modified: lld/trunk/wasm/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.cpp?rev=326509&r1=326508&r2=326509&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.cpp (original)
+++ lld/trunk/wasm/InputFiles.cpp Thu Mar 1 15:29:05 2018
@@ -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<InputSegment>(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 {
Modified: lld/trunk/wasm/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.cpp?rev=326509&r1=326508&r2=326509&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.cpp (original)
+++ lld/trunk/wasm/SymbolTable.cpp Thu Mar 1 15:29:05 2018
@@ -301,18 +301,6 @@ void SymbolTable::addLazy(ArchiveFile *F
}
}
-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;
}
Modified: lld/trunk/wasm/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.h?rev=326509&r1=326508&r2=326509&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.h (original)
+++ lld/trunk/wasm/SymbolTable.h Thu Mar 1 15:29:05 2018
@@ -46,7 +46,6 @@ public:
ArrayRef<Symbol *> 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<Symbol *, bool> insert(StringRef Name);
- llvm::DenseMap<llvm::CachedHashStringRef, ObjFile *> ComdatMap;
llvm::DenseMap<llvm::CachedHashStringRef, Symbol *> SymMap;
std::vector<Symbol *> SymVector;
+
+ llvm::DenseMap<StringRef, const ObjFile *> Comdats;
};
extern SymbolTable *Symtab;
More information about the llvm-commits
mailing list