[lld] r185125 - [PECOFF][Writer] Templatize connectAtomsWithLayoutEdge()

Rui Ueyama ruiu at google.com
Thu Jun 27 20:41:08 PDT 2013


Author: ruiu
Date: Thu Jun 27 22:41:07 2013
New Revision: 185125

URL: http://llvm.org/viewvc/llvm-project?rev=185125&view=rev
Log:
[PECOFF][Writer] Templatize connectAtomsWithLayoutEdge()

Templatize connectAtomsWithLayoutEdge() so that it can handle other types of
defined atoms.

Removed:
    lld/trunk/lib/ReaderWriter/PECOFF/Atoms.cpp
Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h
    lld/trunk/lib/ReaderWriter/PECOFF/CMakeLists.txt

Removed: lld/trunk/lib/ReaderWriter/PECOFF/Atoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/Atoms.cpp?rev=185124&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/Atoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/Atoms.cpp (removed)
@@ -1,48 +0,0 @@
-//===- lib/ReaderWriter/PECOFF/Atoms.cpp ----------------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "Atoms.h"
-
-namespace lld {
-namespace coff {
-
-namespace {
-void addEdge(COFFDefinedAtom *a, COFFDefinedAtom *b,
-             lld::Reference::Kind kind) {
-  auto ref = new COFFReference(kind);
-  ref->setTarget(b);
-  a->addReference(std::unique_ptr<COFFReference>(ref));
-}
-
-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=185125&r1=185124&r2=185125&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h Thu Jun 27 22:41:07 2013
@@ -21,8 +21,6 @@ using llvm::object::COFFObjectFile;
 using llvm::object::coff_section;
 using llvm::object::coff_symbol;
 
-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
 /// means that the address starting at 8th byte of the content of atom X needs
@@ -201,5 +199,43 @@ private:
   uint64_t _ordinal;
 };
 
+//===----------------------------------------------------------------------===//
+//
+// Utility functions to handle layout edges.
+//
+//===----------------------------------------------------------------------===//
+
+template<typename T, typename U>
+void addLayoutEdge(T *a, U *b, lld::Reference::Kind kind) {
+  auto ref = new COFFReference(kind);
+  ref->setTarget(b);
+  a->addReference(std::unique_ptr<COFFReference>(ref));
+}
+
+template<typename T, typename U>
+void connectWithLayoutEdge(T *a, U *b) {
+  addLayoutEdge(a, b, lld::Reference::kindLayoutAfter);
+  addLayoutEdge(b, a, lld::Reference::kindLayoutBefore);
+}
+
+/// 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.
+template<typename T>
+void connectAtomsWithLayoutEdge(std::vector<T *> &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/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/CMakeLists.txt?rev=185125&r1=185124&r2=185125&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/CMakeLists.txt (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/CMakeLists.txt Thu Jun 27 22:41:07 2013
@@ -1,5 +1,4 @@
 add_lld_library(lldPECOFF
-  Atoms.cpp
   PECOFFTargetInfo.cpp
   ReaderCOFF.cpp
   ReaderImportHeader.cpp





More information about the llvm-commits mailing list