[lld] r205575 - Do not check deadStripNever twice.

Rui Ueyama ruiu at google.com
Thu Apr 3 15:24:40 PDT 2014


Author: ruiu
Date: Thu Apr  3 17:24:40 2014
New Revision: 205575

URL: http://llvm.org/viewvc/llvm-project?rev=205575&view=rev
Log:
Do not check deadStripNever twice.

Atoms with deadStripNever attribute has already been added to the
dead strip root set at end of Resolver::doDefinedAtom, so no need
to check it for each atom again.

Differential Revision: http://llvm-reviews.chandlerc.com/D3282

Modified:
    lld/trunk/lib/Core/Resolver.cpp

Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=205575&r1=205574&r2=205575&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Thu Apr  3 17:24:40 2014
@@ -31,27 +31,6 @@ namespace lld {
 
 namespace {
 
-/// This is used as a filter function to std::remove_if to dead strip atoms.
-class NotLive {
-public:
-  explicit NotLive(const llvm::DenseSet<const Atom *> &la) : _liveAtoms(la) {}
-
-  bool operator()(const Atom *atom) const {
-    // don't remove if live
-    if (_liveAtoms.count(atom))
-      return false;
-    // don't remove if marked never-dead-strip
-    if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom))
-      if (defAtom->deadStrip() == DefinedAtom::deadStripNever)
-        return false;
-    // do remove this atom
-    return true;
-  }
-
-private:
-  const llvm::DenseSet<const Atom *> &_liveAtoms;
-};
-
 /// This is used as a filter function to std::remove_if to coalesced atoms.
 class AtomCoalescedAway {
 public:
@@ -377,9 +356,10 @@ void Resolver::deadStripOptimize() {
     markLive(*dsrAtom);
 
   // now remove all non-live atoms from _atoms
-  _atoms.erase(
-      std::remove_if(_atoms.begin(), _atoms.end(), NotLive(_liveAtoms)),
-      _atoms.end());
+  _atoms.erase(std::remove_if(_atoms.begin(), _atoms.end(), [&](const Atom *a) {
+                 return _liveAtoms.count(a) == 0;
+               }),
+               _atoms.end());
 }
 
 // error out if some undefines remain
@@ -389,10 +369,10 @@ bool Resolver::checkUndefines() {
   _symbolTable.undefines(undefinedAtoms);
   if (_context.deadStrip()) {
     // When dead code stripping, we don't care if dead atoms are undefined.
-    undefinedAtoms.erase(std::remove_if(undefinedAtoms.begin(),
-                                        undefinedAtoms.end(),
-                                        NotLive(_liveAtoms)),
-                         undefinedAtoms.end());
+    undefinedAtoms.erase(
+        std::remove_if(undefinedAtoms.begin(), undefinedAtoms.end(),
+                       [&](const Atom *a) { return _liveAtoms.count(a) == 0; }),
+        undefinedAtoms.end());
   }
 
   // error message about missing symbols





More information about the llvm-commits mailing list