[llvm-commits] [lld] r153912 - in /lld/trunk: include/lld/Core/AbsoluteAtom.h include/lld/Core/Atom.h include/lld/Core/DefinedAtom.h include/lld/Core/SharedLibraryAtom.h include/lld/Core/UndefinedAtom.h lib/Core/Resolver.cpp lib/Core/SymbolTable.cpp lib/Passes/GOTPass.cpp lib/Passes/StubsPass.cpp

Michael J. Spencer bigcheesegs at gmail.com
Mon Apr 2 16:56:36 PDT 2012


Author: mspencer
Date: Mon Apr  2 18:56:36 2012
New Revision: 153912

URL: http://llvm.org/viewvc/llvm-project?rev=153912&view=rev
Log:
Use the LLVM RTTI library.

Modified:
    lld/trunk/include/lld/Core/AbsoluteAtom.h
    lld/trunk/include/lld/Core/Atom.h
    lld/trunk/include/lld/Core/DefinedAtom.h
    lld/trunk/include/lld/Core/SharedLibraryAtom.h
    lld/trunk/include/lld/Core/UndefinedAtom.h
    lld/trunk/lib/Core/Resolver.cpp
    lld/trunk/lib/Core/SymbolTable.cpp
    lld/trunk/lib/Passes/GOTPass.cpp
    lld/trunk/lib/Passes/StubsPass.cpp

Modified: lld/trunk/include/lld/Core/AbsoluteAtom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/AbsoluteAtom.h?rev=153912&r1=153911&r2=153912&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/AbsoluteAtom.h (original)
+++ lld/trunk/include/lld/Core/AbsoluteAtom.h Mon Apr  2 18:56:36 2012
@@ -18,21 +18,15 @@
 /// It exists to represent content at fixed addresses in memory.
 class AbsoluteAtom : public Atom {
 public:
-  virtual Definition definition() const {
-    return Atom::definitionAbsolute;
-  }
-
-  /// like dynamic_cast, if atom is definitionAbsolute
-  /// returns atom cast to AbsoluteAtom*, else returns nullptr
-  virtual const AbsoluteAtom* absoluteAtom() const { 
-    return this;
-  }
-  
   virtual uint64_t value() const = 0;
   
-  
+  static inline bool classof(const Atom *a) {
+    return a->definition() == definitionAbsolute;
+  }
+  static inline bool classof(const AbsoluteAtom *) { return true; }
+
 protected:
-           AbsoluteAtom() {}
+  AbsoluteAtom() : Atom(definitionAbsolute) {}
   virtual ~AbsoluteAtom() {}
 };
 

Modified: lld/trunk/include/lld/Core/Atom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Atom.h?rev=153912&r1=153911&r2=153912&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Atom.h (original)
+++ lld/trunk/include/lld/Core/Atom.h Mon Apr  2 18:56:36 2012
@@ -21,10 +21,6 @@
 namespace lld {
 
 class File;
-class DefinedAtom;
-class UndefinedAtom;
-class SharedLibraryAtom;
-class AbsoluteAtom;
 
 ///
 /// The linker has a Graph Theory model of linking. An object file is seen
@@ -52,33 +48,22 @@
   
   /// definition - Whether this atom is a definition or represents an undefined
   /// symbol.
-  virtual Definition definition() const = 0;
-  
-  /// definedAtom - like dynamic_cast, if atom is definitionRegular
-  /// returns atom cast to DefinedAtom*, else returns nullptr;
-  virtual const DefinedAtom* definedAtom() const { return nullptr; }
-
-  /// undefinedAtom - like dynamic_cast, if atom is definitionUndefined
-  /// returns atom cast to UndefinedAtom*, else returns nullptr;
-  virtual const UndefinedAtom* undefinedAtom() const { return nullptr; }
-  
-  /// sharedLibraryAtom - like dynamic_cast, if atom is definitionSharedLibrary
-  /// returns atom cast to SharedLibraryAtom*, else returns nullptr;
-  virtual const SharedLibraryAtom* sharedLibraryAtom() const { return nullptr; }
-  
-  /// absoluteAtom - like dynamic_cast, if atom is definitionAbsolute
-  /// returns atom cast to AbsoluteAtom*, else returns nullptr;
-  virtual const AbsoluteAtom* absoluteAtom() const { return nullptr; }
+  Definition definition() const { return _definition; };
+
+  static inline bool classof(const Atom *a) { return true; }
   
 protected:
   /// Atom is an abstract base class.  Only subclasses can access constructor.
-  Atom() {}
+  Atom(Definition def) : _definition(def) {}
   
   /// The memory for Atom objects is always managed by the owning File
   /// object.  Therefore, no one but the owning File object should call
   /// delete on an Atom.  In fact, some File objects may bulk allocate
   /// an array of Atoms, so they cannot be individually deleted by anyone.
   virtual ~Atom() {}
+
+private:
+  Definition _definition;
 };
 
 } // namespace lld

Modified: lld/trunk/include/lld/Core/DefinedAtom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/DefinedAtom.h?rev=153912&r1=153911&r2=153912&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/DefinedAtom.h (original)
+++ lld/trunk/include/lld/Core/DefinedAtom.h Mon Apr  2 18:56:36 2012
@@ -88,15 +88,6 @@
 ///
 class DefinedAtom : public Atom {
 public:
-  /// Whether this atom is defined or a proxy for an undefined symbol
-  virtual Definition definition() const {
-    return Atom::definitionRegular;
-  }
-
-  virtual const DefinedAtom* definedAtom() const { 
-    return this; 
-  }
-
   /// The scope in which this atom is acessible to other atoms.
   enum Scope {
     scopeTranslationUnit,  ///< Accessible only to atoms in the same translation
@@ -293,11 +284,15 @@
   /// Returns an iterator to the end of this Atom's References
   virtual reference_iterator referencesEnd() const = 0;
  
+  static inline bool classof(const Atom *a) {
+    return a->definition() == definitionRegular;
+  }
+  static inline bool classof(const DefinedAtom *) { return true; }
  
 protected:
   /// DefinedAtom is an abstract base class.  
   /// Only subclasses can access constructor.
-  DefinedAtom() { }
+  DefinedAtom() : Atom(definitionRegular) { }
   
   /// The memory for DefinedAtom objects is always managed by the owning File
   /// object.  Therefore, no one but the owning File object should call

Modified: lld/trunk/include/lld/Core/SharedLibraryAtom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/SharedLibraryAtom.h?rev=153912&r1=153911&r2=153912&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/SharedLibraryAtom.h (original)
+++ lld/trunk/include/lld/Core/SharedLibraryAtom.h Mon Apr  2 18:56:36 2012
@@ -22,16 +22,6 @@
 /// It exists to represent a symbol which will be bound at runtime.
 class SharedLibraryAtom : public Atom {
 public:
-  virtual Definition definition() const {
-    return Atom::definitionSharedLibrary;
-  }
-
-  /// like dynamic_cast, if atom is definitionSharedLibrary
-  /// returns atom cast to SharedLibraryAtom*, else returns nullptr
-  virtual const SharedLibraryAtom* sharedLibraryAtom() const { 
-    return this;
-  }
-
   /// Returns shared library name used to load it at runtime.
   /// On linux that is the DT_NEEDED name.
   /// On Darwin it is the LC_DYLIB_LOAD dylib name.
@@ -40,9 +30,14 @@
   /// Returns if shared library symbol can be missing at runtime and if
   /// so the loader should silently resolve address of symbol to be nullptr.
   virtual bool canBeNullAtRuntime() const = 0;
+
+  static inline bool classof(const Atom *a) {
+    return a->definition() == definitionSharedLibrary;
+  }
+  static inline bool classof(const SharedLibraryAtom *) { return true; }
   
 protected:
-           SharedLibraryAtom() {}
+  SharedLibraryAtom() : Atom(definitionSharedLibrary) {}
   virtual ~SharedLibraryAtom() {}
 };
 

Modified: lld/trunk/include/lld/Core/UndefinedAtom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/UndefinedAtom.h?rev=153912&r1=153911&r2=153912&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/UndefinedAtom.h (original)
+++ lld/trunk/include/lld/Core/UndefinedAtom.h Mon Apr  2 18:56:36 2012
@@ -18,16 +18,6 @@
 /// It exists as a place holder for a future atom.
 class UndefinedAtom : public Atom {
 public:
-  virtual Definition definition() const {
-    return Atom::definitionUndefined;
-  }
-
-  /// like dynamic_cast, if atom is definitionUndefined
-  /// returns atom cast to UndefinedAtom*, else returns nullptr
-  virtual const UndefinedAtom* undefinedAtom() const { 
-    return this;
-  }
-
   /// Whether this undefined symbol needs to be resolved,
   /// or whether it can just evaluate to nullptr.
   /// This concept is often called "weak", but that term
@@ -61,9 +51,13 @@
   
   virtual CanBeNull canBeNull() const = 0;
   
+  static inline bool classof(const Atom *a) {
+    return a->definition() == definitionUndefined;
+  }
+  static inline bool classof(const UndefinedAtom *) { return true; }
    
 protected:
-           UndefinedAtom() {}
+  UndefinedAtom() : Atom(definitionUndefined) {}
   virtual ~UndefinedAtom() {}
 };
 

Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=153912&r1=153911&r2=153912&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Mon Apr  2 18:56:36 2012
@@ -15,6 +15,7 @@
 #include "lld/Core/SymbolTable.h"
 #include "lld/Core/UndefinedAtom.h"
 
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/raw_ostream.h"
 
 #include <algorithm>
@@ -33,7 +34,7 @@
     if ( _liveAtoms.count(atom) )
       return false;
    // don't remove if marked never-dead-strip
-    if ( const DefinedAtom* defAtom = atom->definedAtom() ) {
+    if (const DefinedAtom* defAtom = llvm::dyn_cast<DefinedAtom>(atom)) {
       if ( defAtom->deadStrip() == DefinedAtom::deadStripNever )
         return false;
     }
@@ -194,7 +195,7 @@
       std::vector<const Atom *> tents;
       for (std::vector<const Atom *>::iterator ait = _atoms.begin();
            ait != _atoms.end(); ++ait) {
-        if ( const DefinedAtom* defAtom = (*ait)->definedAtom() ) {
+        if (const DefinedAtom* defAtom = llvm::dyn_cast<DefinedAtom>(*ait)) {
           if ( defAtom->merge() == DefinedAtom::mergeAsTentative )
             tents.push_back(defAtom);
         }
@@ -206,7 +207,8 @@
         llvm::StringRef tentName = (*dit)->name();
         const Atom *curAtom = _symbolTable.findByName(tentName);
         assert(curAtom != nullptr);
-        if ( const DefinedAtom* curDefAtom = curAtom->definedAtom() ) {
+        if (const DefinedAtom* curDefAtom =
+              llvm::dyn_cast<DefinedAtom>(curAtom)) {
           if (curDefAtom->merge() == DefinedAtom::mergeAsTentative )
             _inputFiles.searchLibraries(tentName, searchDylibs, 
                                         true, true, *this);
@@ -221,7 +223,7 @@
 // to the new defined atom
 void Resolver::updateReferences() {
   for (auto ait = _atoms.begin(); ait != _atoms.end(); ++ait) {
-    if ( const DefinedAtom* defAtom = (*ait)->definedAtom() ) {
+    if (const DefinedAtom* defAtom = llvm::dyn_cast<DefinedAtom>(*ait)) {
       for (auto rit=defAtom->referencesBegin(), end=defAtom->referencesEnd();
                                                         rit != end; ++rit) {
         const Reference* ref = *rit;
@@ -259,7 +261,7 @@
   WhyLiveBackChain thisChain;
   thisChain.previous = previous;
   thisChain.referer = &atom;
-  if ( const DefinedAtom* defAtom = atom.definedAtom() ) {
+  if ( const DefinedAtom* defAtom = llvm::dyn_cast<DefinedAtom>(&atom)) {
     for (auto rit=defAtom->referencesBegin(), end=defAtom->referencesEnd();
                                                         rit != end; ++rit) {
       const Reference* ref = *rit;
@@ -342,7 +344,7 @@
 void Resolver::checkDylibSymbolCollisions() {
   for (std::vector<const Atom *>::const_iterator it = _atoms.begin();
        it != _atoms.end(); ++it) {
-    const DefinedAtom* defAtom = (*it)->definedAtom();
+    const DefinedAtom* defAtom = llvm::dyn_cast<DefinedAtom>(*it);
     if (defAtom == nullptr)
       continue;
     if ( defAtom->merge() != DefinedAtom::mergeAsTentative ) 
@@ -389,25 +391,23 @@
 }
 
 void Resolver::MergedFile::addAtom(const Atom& atom) {
-  if ( const DefinedAtom* defAtom = atom.definedAtom() ) {
+  if (const DefinedAtom* defAtom = llvm::dyn_cast<DefinedAtom>(&atom)) {
     _definedAtoms._atoms.push_back(defAtom);
-  }
-  else if ( const UndefinedAtom* undefAtom = atom.undefinedAtom() ) {
+  } else if (const UndefinedAtom* undefAtom =
+               llvm::dyn_cast<UndefinedAtom>(&atom)) {
     _undefinedAtoms._atoms.push_back(undefAtom);
-  }
-  else if ( const SharedLibraryAtom* slAtom = atom.sharedLibraryAtom() ) {
+  } else if (const SharedLibraryAtom* slAtom =
+               llvm::dyn_cast<SharedLibraryAtom>(&atom)) {
     _sharedLibraryAtoms._atoms.push_back(slAtom);
-  }
-  else if ( const AbsoluteAtom* abAtom = atom.absoluteAtom() ) {
+  } else if (const AbsoluteAtom* abAtom = llvm::dyn_cast<AbsoluteAtom>(&atom)) {
     _absoluteAtoms._atoms.push_back(abAtom);
-  }
-  else {
+  } else {
     assert(0 && "atom has unknown definition kind");
   }
 }
 
 void Resolver::MergedFile::addAtoms(std::vector<const Atom*>& all) {
-  for(std::vector<const Atom*>::iterator it=all.begin(); it != all.end(); ++it) {
+  for(std::vector<const Atom*>::iterator it=all.begin(); it != all.end(); ++it){
     this->addAtom(**it);
   }
 }

Modified: lld/trunk/lib/Core/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/SymbolTable.cpp?rev=153912&r1=153911&r2=153912&view=diff
==============================================================================
--- lld/trunk/lib/Core/SymbolTable.cpp (original)
+++ lld/trunk/lib/Core/SymbolTable.cpp Mon Apr  2 18:56:36 2012
@@ -20,6 +20,7 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 
 #include <algorithm>
@@ -160,8 +161,10 @@
         }
         break;
       case NCR_DupUndef: {
-          const UndefinedAtom* existingUndef = existing->undefinedAtom();
-          const UndefinedAtom* newUndef = newAtom.undefinedAtom();
+          const UndefinedAtom* existingUndef =
+            llvm::dyn_cast<UndefinedAtom>(existing);
+          const UndefinedAtom* newUndef =
+            llvm::dyn_cast<UndefinedAtom>(&newAtom);
           assert(existingUndef != nullptr);
           assert(newUndef != nullptr);
           if ( existingUndef->canBeNull() == newUndef->canBeNull() ) {
@@ -176,8 +179,10 @@
         }
         break;
       case NCR_DupShLib: {
-          const SharedLibraryAtom* existingShLib = existing->sharedLibraryAtom();
-          const SharedLibraryAtom* newShLib = newAtom.sharedLibraryAtom();
+          const SharedLibraryAtom* existingShLib =
+            llvm::dyn_cast<SharedLibraryAtom>(existing);
+          const SharedLibraryAtom* newShLib =
+            llvm::dyn_cast<SharedLibraryAtom>(&newAtom);
           assert(existingShLib != nullptr);
           assert(newShLib != nullptr);
           if ( (existingShLib->canBeNullAtRuntime() 

Modified: lld/trunk/lib/Passes/GOTPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Passes/GOTPass.cpp?rev=153912&r1=153911&r2=153912&view=diff
==============================================================================
--- lld/trunk/lib/Passes/GOTPass.cpp (original)
+++ lld/trunk/lib/Passes/GOTPass.cpp Mon Apr  2 18:56:36 2012
@@ -38,6 +38,7 @@
 #include "lld/Core/Reference.h"
 
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/Support/Casting.h"
 
 namespace lld {
 
@@ -57,7 +58,7 @@
       if ( _platform.isGOTAccess(ref->kind(), canBypassGOT) ) {
         const Atom* target = ref->target();
         assert(target != nullptr);
-        const DefinedAtom* defTarget = target->definedAtom();
+        const DefinedAtom* defTarget = llvm::dyn_cast<DefinedAtom>(target);
         bool replaceTargetWithGOTAtom = false;
         if ( target->definition() == Atom::definitionSharedLibrary ) {
           // Accesses to shared library symbols must go through GOT.

Modified: lld/trunk/lib/Passes/StubsPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Passes/StubsPass.cpp?rev=153912&r1=153911&r2=153912&view=diff
==============================================================================
--- lld/trunk/lib/Passes/StubsPass.cpp (original)
+++ lld/trunk/lib/Passes/StubsPass.cpp Mon Apr  2 18:56:36 2012
@@ -21,6 +21,7 @@
 #include "lld/Core/Reference.h"
 
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/Support/Casting.h"
 
 namespace lld {
 
@@ -47,8 +48,8 @@
         if ( target->definition() == Atom::definitionSharedLibrary ) {
           // Calls to shared libraries go through stubs.
           replaceCalleeWithStub = true;
-        }
-        else if ( const DefinedAtom* defTarget = target->definedAtom() ) {
+        } else if (const DefinedAtom* defTarget =
+                     llvm::dyn_cast<DefinedAtom>(target)) {
           if ( defTarget->interposable() != DefinedAtom::interposeNo ) {
             // Calls to interposable functions in same linkage unit 
             // must also go through a stub.





More information about the llvm-commits mailing list