[lld] r184653 - [PECOFF] Moves a utility function to Atoms.cpp to remove duplicate code.

Rui Ueyama ruiu at google.com
Sat Jun 22 16:14:51 PDT 2013


Author: ruiu
Date: Sat Jun 22 18:14:51 2013
New Revision: 184653

URL: http://llvm.org/viewvc/llvm-project?rev=184653&view=rev
Log:
[PECOFF] Moves a utility function to Atoms.cpp to remove duplicate code.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/Atoms.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h
    lld/trunk/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h
    lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp

Modified: lld/trunk/lib/ReaderWriter/PECOFF/Atoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/Atoms.cpp?rev=184653&r1=184652&r2=184653&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/Atoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/Atoms.cpp Sat Jun 22 18:14:51 2013
@@ -19,12 +19,30 @@ void addEdge(COFFDefinedAtom *a, COFFDef
   ref->setTarget(b);
   a->addReference(std::unique_ptr<COFFReference>(ref));
 }
-}
 
-void connectAtomsWithLayoutEdge(COFFDefinedAtom *a, COFFDefinedAtom *b) {
+void connectWithLayoutEdge(COFFDefinedAtom *a, COFFDefinedAtom *b) {
   addEdge(a, b, lld::Reference::kindLayoutAfter);
   addEdge(b, a, lld::Reference::kindLayoutBefore);
 }
+} // anonymous namespace
+
+/// Connect atoms with layout-{before,after} edges. It usually serves two
+/// purposes.
+///
+///   - To prevent atoms from being GC'ed (aka dead-stripped) if there is a
+///     reference to one of the atoms. In that case we want to emit all the
+///     atoms appeared in the same section, because the referenced "live" atom
+///     may reference other atoms in the same section. If we don't add layout
+///     edges between atoms, unreferenced atoms in the same section would be
+///     GC'ed.
+///   - To preserve the order of atmos. We want to emit the atoms in the
+///     same order as they appeared in the input object file.
+void connectAtomsWithLayoutEdge(std::vector<COFFDefinedAtom *> atoms) {
+  if (atoms.size() < 2)
+    return;
+  for (auto it = atoms.begin(), e = atoms.end(); it + 1 != e; ++it)
+    connectWithLayoutEdge(*it, *(it + 1));
+}
 
 } // namespace coff
 } // namespace lld

Modified: lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h?rev=184653&r1=184652&r2=184653&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h Sat Jun 22 18:14:51 2013
@@ -21,7 +21,7 @@ using llvm::object::COFFObjectFile;
 using llvm::object::coff_section;
 using llvm::object::coff_symbol;
 
-void connectAtomsWithLayoutEdge(COFFDefinedAtom *a, COFFDefinedAtom *b);
+void connectAtomsWithLayoutEdge(std::vector<COFFDefinedAtom *>);
 
 /// A COFFReference represents relocation information for an atom. For
 /// example, if atom X has a reference to atom Y with offsetInAtom=8, that

Modified: lld/trunk/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h?rev=184653&r1=184652&r2=184653&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/GroupedSectionsPass.h Sat Jun 22 18:14:51 2013
@@ -66,7 +66,7 @@ public:
     std::vector<std::vector<COFFDefinedAtom *>> groupedAtomsList(
         groupBySectionName(sectionToHeadAtoms));
     for (auto &groupedAtoms : groupedAtomsList)
-      connectAtoms(groupedAtoms);
+      connectAtomsWithLayoutEdge(groupedAtoms);
   }
 
 private:
@@ -107,13 +107,6 @@ private:
       vec.push_back(std::move(i.second));
     return std::move(vec);
   }
-
-  void connectAtoms(std::vector<COFFDefinedAtom *> atoms) const {
-    if (atoms.size() < 2)
-      return;
-    for (auto it = atoms.begin(), e = atoms.end(); it + 1 != e; ++it)
-      connectAtomsWithLayoutEdge(*it, *(it + 1));
-  }
 };
 
 } // namespace pecoff

Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=184653&r1=184652&r2=184653&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Sat Jun 22 18:14:51 2013
@@ -227,25 +227,6 @@ private:
     return error_code::success();
   }
 
-  /// Connect atoms appeared in the same section with layout-{before,after}
-  /// edges. It has two purposes.
-  ///
-  ///   - To prevent atoms from being GC'ed (aka dead-stripped) if there is a
-  ///     reference to one of the atoms. In that case we want to emit all the
-  ///     atoms appeared in the same section, because the referenced "live"
-  ///     atom may reference other atoms in the same section. If we don't add
-  ///     edges between atoms, unreferenced atoms in the same section would be
-  ///     GC'ed.
-  ///   - To preserve the order of atmos. We want to emit the atoms in the
-  ///     same order as they appeared in the input object file.
-  void addLayoutEdges(vector<COFFDefinedAtom *> &definedAtoms) const {
-    if (definedAtoms.size() <= 1)
-      return;
-    for (auto it = definedAtoms.begin(), e = definedAtoms.end(); it + 1 != e;
-         ++it)
-      connectAtomsWithLayoutEdge(*it, *(it + 1));
-  }
-
   error_code AtomizeDefinedSymbols(SectionToSymbolsT &definedSymbols,
                                    vector<const DefinedAtom *> &definedAtoms,
                                    SymbolNameToAtomT &symbolToAtom,
@@ -261,7 +242,7 @@ private:
         return ec;
 
       // Connect atoms with layout-before/layout-after edges.
-      addLayoutEdges(atoms);
+      connectAtomsWithLayoutEdge(atoms);
 
       for (COFFDefinedAtom *atom : atoms) {
         if (!atom->name().empty())





More information about the llvm-commits mailing list