[lld] r248104 - COFF: Change Symbol::Body type from atomic pointer to regular pointer.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 19 17:00:05 PDT 2015
Author: ruiu
Date: Sat Sep 19 19:00:05 2015
New Revision: 248104
URL: http://llvm.org/viewvc/llvm-project?rev=248104&view=rev
Log:
COFF: Change Symbol::Body type from atomic pointer to regular pointer.
I made the field an atomic pointer in hope that we would be able to
parallelize the symbol resolver soon, but that's not going to happen
soon. This patch reverts that change for the sake of readability.
Modified:
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/COFF/Symbols.h
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=248104&r1=248103&r2=248104&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Sat Sep 19 19:00:05 2015
@@ -168,20 +168,16 @@ void SymbolTable::addLazy(Lazy *New, std
Symbol *Sym = insert(New);
if (Sym->Body == New)
return;
- for (;;) {
- SymbolBody *Existing = Sym->Body;
- if (isa<Defined>(Existing))
- return;
- if (Lazy *L = dyn_cast<Lazy>(Existing))
- if (L->getFileIndex() < New->getFileIndex())
- return;
- if (!Sym->Body.compare_exchange_strong(Existing, New))
- continue;
- New->setBackref(Sym);
- if (isa<Undefined>(Existing))
- Accum->push_back(Sym);
+ SymbolBody *Existing = Sym->Body;
+ if (isa<Defined>(Existing))
return;
- }
+ if (Lazy *L = dyn_cast<Lazy>(Existing))
+ if (L->getFileIndex() < New->getFileIndex())
+ return;
+ Sym->Body = New;
+ New->setBackref(Sym);
+ if (isa<Undefined>(Existing))
+ Accum->push_back(Sym);
}
void SymbolTable::addSymbol(SymbolBody *New) {
@@ -190,37 +186,32 @@ void SymbolTable::addSymbol(SymbolBody *
Symbol *Sym = insert(New);
if (Sym->Body == New)
return;
+ SymbolBody *Existing = Sym->Body;
- for (;;) {
- SymbolBody *Existing = Sym->Body;
-
- // If we have an undefined symbol and a lazy symbol,
- // let the lazy symbol to read a member file.
- if (auto *L = dyn_cast<Lazy>(Existing)) {
- // Undefined symbols with weak aliases need not to be resolved,
- // since they would be replaced with weak aliases if they remain
- // undefined.
- if (auto *U = dyn_cast<Undefined>(New))
- if (!U->WeakAlias) {
- addMemberFile(L);
- return;
- }
- if (!Sym->Body.compare_exchange_strong(Existing, New))
- continue;
- return;
+ // If we have an undefined symbol and a lazy symbol,
+ // let the lazy symbol to read a member file.
+ if (auto *L = dyn_cast<Lazy>(Existing)) {
+ // Undefined symbols with weak aliases need not to be resolved,
+ // since they would be replaced with weak aliases if they remain
+ // undefined.
+ if (auto *U = dyn_cast<Undefined>(New)) {
+ if (!U->WeakAlias) {
+ addMemberFile(L);
+ return;
+ }
}
-
- // compare() returns -1, 0, or 1 if the lhs symbol is less preferable,
- // equivalent (conflicting), or more preferable, respectively.
- int Comp = Existing->compare(New);
- if (Comp == 0)
- error(Twine("duplicate symbol: ") + Existing->getDebugName() + " and " +
- New->getDebugName());
- if (Comp < 0)
- if (!Sym->Body.compare_exchange_strong(Existing, New))
- continue;
+ Sym->Body = New;
return;
}
+
+ // compare() returns -1, 0, or 1 if the lhs symbol is less preferable,
+ // equivalent (conflicting), or more preferable, respectively.
+ int Comp = Existing->compare(New);
+ if (Comp == 0)
+ error(Twine("duplicate symbol: ") + Existing->getDebugName() + " and " +
+ New->getDebugName());
+ if (Comp < 0)
+ Sym->Body = New;
}
Symbol *SymbolTable::insert(SymbolBody *New) {
Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=248104&r1=248103&r2=248104&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Sat Sep 19 19:00:05 2015
@@ -39,7 +39,7 @@ class SymbolBody;
// The resolver updates SymbolBody pointers as it resolves symbols.
struct Symbol {
explicit Symbol(SymbolBody *P) : Body(P) {}
- std::atomic<SymbolBody *> Body;
+ SymbolBody *Body;
};
// The base class for real symbol classes.
@@ -82,7 +82,7 @@ public:
// has chosen the object among other objects having the same name,
// you can access P->Backref->Body to get the resolver's result.
void setBackref(Symbol *P) { Backref = P; }
- SymbolBody *repl() { return Backref ? Backref->Body.load() : this; }
+ SymbolBody *repl() { return Backref ? Backref->Body : this; }
// Decides which symbol should "win" in the symbol table, this or
// the Other. Returns 1 if this wins, -1 if the Other wins, or 0 if
@@ -416,13 +416,4 @@ inline uint64_t Defined::getRVA() {
} // namespace coff
} // namespace lld
-// Support isa<>, cast<> and dyn_cast<> for Symbol::Body.
-namespace llvm {
-template <typename T>
-struct simplify_type<std::atomic<T *>> {
- typedef T *SimpleType;
- static T *getSimplifiedValue(std::atomic<T *> &A) { return A.load(); }
-};
-}
-
#endif
More information about the llvm-commits
mailing list