[PATCH] Do not check deadStripNever twice.

Rui Ueyama ruiu at google.com
Thu Apr 3 15:11:36 PDT 2014


  Realized that the meaningful part of NotLive class is now only
  one line, so inlined it for brevity.

Hi Bigcheese, shankarke, kledzik,

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D3282?vs=8351&id=8352#toc

Files:
  lib/Core/Resolver.cpp

Index: lib/Core/Resolver.cpp
===================================================================
--- lib/Core/Resolver.cpp
+++ lib/Core/Resolver.cpp
@@ -31,27 +31,6 @@
 
 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:
@@ -381,9 +360,10 @@
     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
@@ -393,10 +373,10 @@
   _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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3282.2.patch
Type: text/x-patch
Size: 2044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140403/aecc4bc6/attachment.bin>


More information about the llvm-commits mailing list