[lld] r234365 - Define SimpleFile::addAtom for concrete atom types.

Rui Ueyama ruiu at google.com
Tue Apr 7 15:21:18 PDT 2015


Author: ruiu
Date: Tue Apr  7 17:21:18 2015
New Revision: 234365

URL: http://llvm.org/viewvc/llvm-project?rev=234365&view=rev
Log:
Define SimpleFile::addAtom for concrete atom types.

Previously, addAtom always used dynamic dispatching mechanism to
bin atoms. This patch eliminates dynamic dispatching in most cases.

Modified:
    lld/trunk/include/lld/Core/Simple.h

Modified: lld/trunk/include/lld/Core/Simple.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Simple.h?rev=234365&r1=234364&r2=234365&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Simple.h (original)
+++ lld/trunk/include/lld/Core/Simple.h Tue Apr  7 17:21:18 2015
@@ -30,50 +30,55 @@ class SimpleFile : public File {
 public:
   SimpleFile(StringRef path) : File(path, kindObject) {}
 
+  void addAtom(const DefinedAtom &a) { _defined._atoms.push_back(&a); }
+  void addAtom(const UndefinedAtom &a) { _undefined._atoms.push_back(&a); }
+  void addAtom(const SharedLibraryAtom &a) { _shared._atoms.push_back(&a); }
+  void addAtom(const AbsoluteAtom &a) { _absolute._atoms.push_back(&a); }
+
   void addAtom(const Atom &atom) {
-    if (auto *defAtom = dyn_cast<DefinedAtom>(&atom)) {
-      _definedAtoms._atoms.push_back(defAtom);
-    } else if (auto *undefAtom = dyn_cast<UndefinedAtom>(&atom)) {
-      _undefinedAtoms._atoms.push_back(undefAtom);
-    } else if (auto *shlibAtom = dyn_cast<SharedLibraryAtom>(&atom)) {
-      _sharedLibraryAtoms._atoms.push_back(shlibAtom);
-    } else if (auto *absAtom = dyn_cast<AbsoluteAtom>(&atom)) {
-      _absoluteAtoms._atoms.push_back(absAtom);
+    if (auto *p = dyn_cast<DefinedAtom>(&atom)) {
+      _defined._atoms.push_back(p);
+    } else if (auto *p = dyn_cast<UndefinedAtom>(&atom)) {
+      _undefined._atoms.push_back(p);
+    } else if (auto *p = dyn_cast<SharedLibraryAtom>(&atom)) {
+      _shared._atoms.push_back(p);
+    } else if (auto *p = dyn_cast<AbsoluteAtom>(&atom)) {
+      _absolute._atoms.push_back(p);
     } else {
       llvm_unreachable("atom has unknown definition kind");
     }
   }
 
   void removeDefinedAtomsIf(std::function<bool(const DefinedAtom *)> pred) {
-    auto &atoms = _definedAtoms._atoms;
+    auto &atoms = _defined._atoms;
     auto newEnd = std::remove_if(atoms.begin(), atoms.end(), pred);
     atoms.erase(newEnd, atoms.end());
   }
 
   const atom_collection<DefinedAtom> &defined() const override {
-    return _definedAtoms;
+    return _defined;
   }
 
   const atom_collection<UndefinedAtom> &undefined() const override {
-    return _undefinedAtoms;
+    return _undefined;
   }
 
   const atom_collection<SharedLibraryAtom> &sharedLibrary() const override {
-    return _sharedLibraryAtoms;
+    return _shared;
   }
 
   const atom_collection<AbsoluteAtom> &absolute() const override {
-    return _absoluteAtoms;
+    return _absolute;
   }
 
   typedef range<std::vector<const DefinedAtom *>::iterator> DefinedAtomRange;
-  DefinedAtomRange definedAtoms() { return make_range(_definedAtoms._atoms); }
+  DefinedAtomRange definedAtoms() { return make_range(_defined._atoms); }
 
 private:
-  atom_collection_vector<DefinedAtom>        _definedAtoms;
-  atom_collection_vector<UndefinedAtom>      _undefinedAtoms;
-  atom_collection_vector<SharedLibraryAtom>  _sharedLibraryAtoms;
-  atom_collection_vector<AbsoluteAtom>       _absoluteAtoms;
+  atom_collection_vector<DefinedAtom> _defined;
+  atom_collection_vector<UndefinedAtom> _undefined;
+  atom_collection_vector<SharedLibraryAtom> _shared;
+  atom_collection_vector<AbsoluteAtom> _absolute;
 };
 
 /// \brief Archive library file that may be used as a virtual container





More information about the llvm-commits mailing list