[lld] r210242 - Add SymbolTable::isCoalescedAway

Rui Ueyama ruiu at google.com
Thu Jun 5 00:37:29 PDT 2014


Author: ruiu
Date: Thu Jun  5 02:37:29 2014
New Revision: 210242

URL: http://llvm.org/viewvc/llvm-project?rev=210242&view=rev
Log:
Add SymbolTable::isCoalescedAway

isCoalescedAway(x) is faster than replacement(x) != x as the former
does not follow the replacement atom chain. Also it's easier to use.

Modified:
    lld/trunk/include/lld/Core/SymbolTable.h
    lld/trunk/lib/Core/Resolver.cpp
    lld/trunk/lib/Core/SymbolTable.cpp

Modified: lld/trunk/include/lld/Core/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/SymbolTable.h?rev=210242&r1=210241&r2=210242&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/SymbolTable.h (original)
+++ lld/trunk/include/lld/Core/SymbolTable.h Thu Jun  5 02:37:29 2014
@@ -72,6 +72,9 @@ public:
   /// @brief if atom has been coalesced away, return replacement, else return atom
   const Atom *replacement(const Atom *);
 
+  /// @brief if atom has been coalesced away, return true
+  bool isCoalescedAway(const Atom *);
+
   /// @brief Find a group atom.
   const Atom *findGroup(StringRef name);
 

Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=210242&r1=210241&r2=210242&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Thu Jun  5 02:37:29 2014
@@ -29,24 +29,6 @@
 
 namespace lld {
 
-namespace {
-
-/// This is used as a filter function to std::remove_if to coalesced atoms.
-class AtomCoalescedAway {
-public:
-  explicit AtomCoalescedAway(SymbolTable &sym) : _symbolTable(sym) {}
-
-  bool operator()(const Atom *atom) const {
-    const Atom *rep = _symbolTable.replacement(atom);
-    return rep != atom;
-  }
-
-private:
-  SymbolTable &_symbolTable;
-};
-
-} // namespace
-
 void Resolver::handleFile(const File &file) {
   bool undefAdded = false;
   for (const DefinedAtom *atom : file.defined())
@@ -394,7 +376,7 @@ bool Resolver::checkUndefines() {
         continue;
 
       // If the undefine is coalesced away, skip over it.
-      if (_symbolTable.replacement(undefAtom) != undefAtom)
+      if (_symbolTable.isCoalescedAway(undefAtom))
         continue;
 
       // Seems like this symbol is undefined. Warn that.
@@ -416,8 +398,9 @@ bool Resolver::checkUndefines() {
 // remove from _atoms all coaleseced away atoms
 void Resolver::removeCoalescedAwayAtoms() {
   ScopedTask task(getDefaultDomain(), "removeCoalescedAwayAtoms");
-  _atoms.erase(std::remove_if(_atoms.begin(), _atoms.end(),
-                              AtomCoalescedAway(_symbolTable)),
+  _atoms.erase(std::remove_if(_atoms.begin(), _atoms.end(), [&](const Atom *a) {
+                 return _symbolTable.isCoalescedAway(a);
+               }),
                _atoms.end());
 }
 

Modified: lld/trunk/lib/Core/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/SymbolTable.cpp?rev=210242&r1=210241&r2=210242&view=diff
==============================================================================
--- lld/trunk/lib/Core/SymbolTable.cpp (original)
+++ lld/trunk/lib/Core/SymbolTable.cpp Thu Jun  5 02:37:29 2014
@@ -381,6 +381,10 @@ const Atom *SymbolTable::replacement(con
   }
 }
 
+bool SymbolTable::isCoalescedAway(const Atom *atom) {
+  return _replacedAtoms.count(atom) > 0;
+}
+
 unsigned int SymbolTable::size() {
   return _nameTable.size();
 }





More information about the llvm-commits mailing list