[llvm-commits] [lld] r154301 - in /lld/trunk: include/lld/Core/DefinedAtom.h lib/Core/NativeReader.cpp lib/Core/NativeWriter.cpp lib/Core/Resolver.cpp lib/Core/YamlReader.cpp lib/Core/YamlWriter.cpp lib/Passes/GOTPass.cpp lib/Passes/StubsPass.cpp lib/Platforms/Darwin/ExecutableWriter.cpp lib/Platforms/Darwin/StubAtoms.hpp tools/lld-core/lld-core.cpp

Nick Kledzik kledzik at apple.com
Sun Apr 8 16:52:13 PDT 2012


Author: kledzik
Date: Sun Apr  8 18:52:13 2012
New Revision: 154301

URL: http://llvm.org/viewvc/llvm-project?rev=154301&view=rev
Log:
Rename referencesBegin() to begin() so that C++11 range based for loops can be used

Modified:
    lld/trunk/include/lld/Core/DefinedAtom.h
    lld/trunk/lib/Core/NativeReader.cpp
    lld/trunk/lib/Core/NativeWriter.cpp
    lld/trunk/lib/Core/Resolver.cpp
    lld/trunk/lib/Core/YamlReader.cpp
    lld/trunk/lib/Core/YamlWriter.cpp
    lld/trunk/lib/Passes/GOTPass.cpp
    lld/trunk/lib/Passes/StubsPass.cpp
    lld/trunk/lib/Platforms/Darwin/ExecutableWriter.cpp
    lld/trunk/lib/Platforms/Darwin/StubAtoms.hpp
    lld/trunk/tools/lld-core/lld-core.cpp

Modified: lld/trunk/include/lld/Core/DefinedAtom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/DefinedAtom.h?rev=154301&r1=154300&r2=154301&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/DefinedAtom.h (original)
+++ lld/trunk/include/lld/Core/DefinedAtom.h Sun Apr  8 18:52:13 2012
@@ -279,14 +279,10 @@
   };
 
   /// Returns an iterator to the beginning of this Atom's References
-  virtual reference_iterator referencesBegin() const = 0;
+  virtual reference_iterator begin() const = 0;
 
   /// Returns an iterator to the end of this Atom's References
-  virtual reference_iterator referencesEnd() const = 0;
-
-  reference_iterator begin() const { return referencesBegin(); }
-  reference_iterator end() const { return referencesEnd(); }
-
+  virtual reference_iterator end() const = 0;
 
   static inline bool classof(const Atom *a) {
     return a->definition() == definitionRegular;

Modified: lld/trunk/lib/Core/NativeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/NativeReader.cpp?rev=154301&r1=154300&r2=154301&view=diff
==============================================================================
--- lld/trunk/lib/Core/NativeReader.cpp (original)
+++ lld/trunk/lib/Core/NativeReader.cpp Sun Apr  8 18:52:13 2012
@@ -92,9 +92,9 @@
 
   virtual ArrayRef<uint8_t> rawContent() const;
 
-  virtual reference_iterator referencesBegin() const;
+  virtual reference_iterator begin() const;
 
-  virtual reference_iterator referencesEnd() const;
+  virtual reference_iterator end() const;
 
   virtual const Reference* derefIterator(const void*) const;
 
@@ -731,13 +731,13 @@
   return _file->string(offset);
 }
 
-DefinedAtom::reference_iterator NativeDefinedAtomV1::referencesBegin() const {
+DefinedAtom::reference_iterator NativeDefinedAtomV1::begin() const {
   uintptr_t index = _ivarData->referencesStartIndex;
   const void* it = reinterpret_cast<const void*>(index);
   return reference_iterator(*this, it);
 }
 
-DefinedAtom::reference_iterator NativeDefinedAtomV1::referencesEnd() const {
+DefinedAtom::reference_iterator NativeDefinedAtomV1::end() const {
   uintptr_t index = _ivarData->referencesStartIndex+_ivarData->referencesCount;
   const void* it = reinterpret_cast<const void*>(index);
   return reference_iterator(*this, it);

Modified: lld/trunk/lib/Core/NativeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/NativeWriter.cpp?rev=154301&r1=154300&r2=154301&view=diff
==============================================================================
--- lld/trunk/lib/Core/NativeWriter.cpp (original)
+++ lld/trunk/lib/Core/NativeWriter.cpp Sun Apr  8 18:52:13 2012
@@ -30,25 +30,17 @@
     // reserve first byte for unnamed atoms
     _stringPool.push_back('\0');
     // visit all atoms
-    for(File::defined_iterator it=file.definedAtomsBegin(),
-                              end=file.definedAtomsEnd();
-                               it != end; ++it) {
-      this->addIVarsForDefinedAtom(**it);
-    }
-    for(File::undefined_iterator it=file.undefinedAtomsBegin(),
-                              end=file.undefinedAtomsEnd();
-                               it != end; ++it) {
-      this->addIVarsForUndefinedAtom(**it);
-    }
-    for(File::shared_library_iterator it=file.sharedLibraryAtomsBegin(),
-                              end=file.sharedLibraryAtomsEnd();
-                               it != end; ++it) {
-      this->addIVarsForSharedLibraryAtom(**it);
-    }
-    for(File::absolute_iterator it=file.absoluteAtomsBegin(),
-                              end=file.absoluteAtomsEnd();
-                               it != end; ++it) {
-      this->addIVarsForAbsoluteAtom(**it);
+    for ( const DefinedAtom *defAtom : file.defined() ) {
+      this->addIVarsForDefinedAtom(*defAtom);
+    }
+    for ( const UndefinedAtom *undefAtom : file.undefined() ) {
+      this->addIVarsForUndefinedAtom(*undefAtom);
+    }
+    for ( const SharedLibraryAtom *shlibAtom : file.sharedLibrary() ) {
+      this->addIVarsForSharedLibraryAtom(*shlibAtom);
+    }
+    for ( const AbsoluteAtom *absAtom : file.absolute() ) {
+      this->addIVarsForAbsoluteAtom(*absAtom);
     }
 
 
@@ -412,9 +404,7 @@
     count = 0;
     size_t startRefSize = _references.size();
     uint32_t result = startRefSize;
-    for (auto it=atom.referencesBegin(), end=atom.referencesEnd();
-                                                    it != end; ++it) {
-      const Reference* ref = *it;
+    for (const Reference *ref : atom) {
       NativeReferenceIvarsV1 nref;
       nref.offsetInAtom = ref->offsetInAtom();
       nref.kind = ref->kind();

Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=154301&r1=154300&r2=154301&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Sun Apr  8 18:52:13 2012
@@ -175,9 +175,8 @@
     undefineGenCount = _symbolTable.size();
     std::vector<const Atom *> undefines;
     _symbolTable.undefines(undefines);
-    for (std::vector<const Atom *>::iterator it = undefines.begin();
-         it != undefines.end(); ++it) {
-      StringRef undefName = (*it)->name();
+    for ( const Atom *undefAtom : undefines ) {
+      StringRef undefName = undefAtom->name();
       // load for previous undefine may also have loaded this undefine
       if (!_symbolTable.isDefined(undefName)) {
         _inputFiles.searchLibraries(undefName, true, true, false, *this);
@@ -194,18 +193,16 @@
     // search libraries for overrides of common symbols
     if (searchArchives || searchDylibs) {
       std::vector<const Atom *> tents;
-      for (std::vector<const Atom *>::iterator ait = _atoms.begin();
-           ait != _atoms.end(); ++ait) {
-        if (const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(*ait)) {
+      for ( const Atom *tent : tents ) {
+        if (const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(tent)) {
           if ( defAtom->merge() == DefinedAtom::mergeAsTentative )
             tents.push_back(defAtom);
         }
       }
-      for (std::vector<const Atom *>::iterator dit = tents.begin();
-           dit != tents.end(); ++dit) {
+      for ( const Atom *tent : tents ) {
         // load for previous tentative may also have loaded
         // this tentative, so check again
-        StringRef tentName = (*dit)->name();
+        StringRef tentName = tent->name();
         const Atom *curAtom = _symbolTable.findByName(tentName);
         assert(curAtom != nullptr);
         if (const DefinedAtom* curDefAtom = dyn_cast<DefinedAtom>(curAtom)) {
@@ -222,11 +219,9 @@
 // switch all references to undefined or coalesced away atoms
 // to the new defined atom
 void Resolver::updateReferences() {
-  for (auto ait = _atoms.begin(); ait != _atoms.end(); ++ait) {
-    if (const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(*ait)) {
-      for (auto rit=defAtom->referencesBegin(), end=defAtom->referencesEnd();
-                                                        rit != end; ++rit) {
-        const Reference* ref = *rit;
+  for(const Atom *atom : _atoms) {
+    if (const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(atom)) {
+      for (const Reference *ref : *defAtom) {
         const Atom* newTarget = _symbolTable.replacement(ref->target());
         (const_cast<Reference*>(ref))->setTarget(newTarget);
       }
@@ -262,9 +257,7 @@
   thisChain.previous = previous;
   thisChain.referer = &atom;
   if ( const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(&atom)) {
-    for (auto rit=defAtom->referencesBegin(), end=defAtom->referencesEnd();
-                                                        rit != end; ++rit) {
-      const Reference* ref = *rit;
+    for (const Reference *ref : *defAtom) {
       this->markLive(*ref->target(), &thisChain);
     }
   }
@@ -299,12 +292,11 @@
     this->addAtoms(platRootAtoms);
 
   // mark all roots as live, and recursively all atoms they reference
-  for (std::set<const Atom *>::iterator it = _deadStripRoots.begin();
-       it != _deadStripRoots.end(); ++it) {
+  for ( const Atom *dsrAtom : _deadStripRoots) {
     WhyLiveBackChain rootChain;
     rootChain.previous = nullptr;
-    rootChain.referer = *it;
-    this->markLive(**it, &rootChain);
+    rootChain.referer = dsrAtom;
+    this->markLive(*dsrAtom, &rootChain);
   }
 
   // now remove all non-live atoms from _atoms
@@ -342,9 +334,8 @@
 // check for interactions between symbols defined in this linkage unit
 // and same symbol name in linked dynamic shared libraries
 void Resolver::checkDylibSymbolCollisions() {
-  for (std::vector<const Atom *>::const_iterator it = _atoms.begin();
-       it != _atoms.end(); ++it) {
-    const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(*it);
+  for ( const Atom *atom : _atoms ) {
+    const DefinedAtom* defAtom = dyn_cast<DefinedAtom>(atom);
     if (defAtom == nullptr)
       continue;
     if ( defAtom->merge() != DefinedAtom::mergeAsTentative )
@@ -407,8 +398,8 @@
 }
 
 void Resolver::MergedFile::addAtoms(std::vector<const Atom*>& all) {
-  for(std::vector<const Atom*>::iterator it=all.begin(); it != all.end(); ++it){
-    this->addAtom(**it);
+  for ( const Atom *atom : all ) {
+    this->addAtom(*atom);
   }
 }
 

Modified: lld/trunk/lib/Core/YamlReader.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/YamlReader.cpp?rev=154301&r1=154300&r2=154301&view=diff
==============================================================================
--- lld/trunk/lib/Core/YamlReader.cpp (original)
+++ lld/trunk/lib/Core/YamlReader.cpp Sun Apr  8 18:52:13 2012
@@ -456,13 +456,13 @@
     return _ord;
   }
 
-  DefinedAtom::reference_iterator referencesBegin() const {
+  DefinedAtom::reference_iterator begin() const {
     uintptr_t index = _refStartIndex;
     const void* it = reinterpret_cast<const void*>(index);
     return reference_iterator(*this, it);
   }
 
-  DefinedAtom::reference_iterator referencesEnd() const {
+  DefinedAtom::reference_iterator end() const {
     uintptr_t index = _refEndIndex;
     const void* it = reinterpret_cast<const void*>(index);
     return reference_iterator(*this, it);

Modified: lld/trunk/lib/Core/YamlWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/YamlWriter.cpp?rev=154301&r1=154300&r2=154301&view=diff
==============================================================================
--- lld/trunk/lib/Core/YamlWriter.cpp (original)
+++ lld/trunk/lib/Core/YamlWriter.cpp Sun Apr  8 18:52:13 2012
@@ -57,9 +57,7 @@
         buildDuplicateNameMap(*atom);
 
       // Find references to unnamed atoms and create ref-names for them.
-      for (auto rit=atom->referencesBegin(), rend=atom->referencesEnd();
-                                                        rit != rend; ++rit) {
-        const Reference* ref = *rit;
+      for (const Reference *ref : *atom) {
         // create refname for any unnamed reference target
         if ( ref->target()->name().empty() ) {
           std::string Storage;
@@ -313,9 +311,7 @@
     }
 
     bool wroteFirstFixup = false;
-    for (auto it=atom.referencesBegin(), end=atom.referencesEnd();
-                                                    it != end; ++it) {
-      const Reference* ref = *it;
+    for (const Reference *ref : atom) {
       if ( !wroteFirstFixup ) {
         out  << "      fixups:\n";
         wroteFirstFixup = true;

Modified: lld/trunk/lib/Passes/GOTPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Passes/GOTPass.cpp?rev=154301&r1=154300&r2=154301&view=diff
==============================================================================
--- lld/trunk/lib/Passes/GOTPass.cpp (original)
+++ lld/trunk/lib/Passes/GOTPass.cpp Sun Apr  8 18:52:13 2012
@@ -47,12 +47,8 @@
   llvm::DenseMap<const Atom*, const DefinedAtom*> targetToGOT;
   
   // Scan all references in all atoms.
-  for(auto ait=_file.definedAtomsBegin(), aend=_file.definedAtomsEnd(); 
-                                                      ait != aend; ++ait) {
-    const DefinedAtom* atom = *ait;
-    for (auto rit=atom->referencesBegin(), rend=atom->referencesEnd(); 
-                                                      rit != rend; ++rit) {
-      const Reference* ref = *rit;
+  for(const DefinedAtom *atom : _file.defined()) {
+    for (const Reference *ref : *atom) {
       // Look at instructions accessing the GOT.
       bool canBypassGOT;
       if ( _platform.isGOTAccess(ref->kind(), canBypassGOT) ) {

Modified: lld/trunk/lib/Passes/StubsPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Passes/StubsPass.cpp?rev=154301&r1=154300&r2=154301&view=diff
==============================================================================
--- lld/trunk/lib/Passes/StubsPass.cpp (original)
+++ lld/trunk/lib/Passes/StubsPass.cpp Sun Apr  8 18:52:13 2012
@@ -31,12 +31,8 @@
     return;
 
   // Scan all references in all atoms.
-  for(auto ait=_file.definedAtomsBegin(), aend=_file.definedAtomsEnd();
-                                                      ait != aend; ++ait) {
-    const DefinedAtom* atom = *ait;
-    for (auto rit=atom->referencesBegin(), rend=atom->referencesEnd();
-                                                      rit != rend; ++rit) {
-      const Reference* ref = *rit;
+  for(const DefinedAtom *atom : _file.defined()) {
+    for (const Reference *ref : *atom) {
       // Look at call-sites.
       if ( _platform.isCallSite(ref->kind()) ) {
         const Atom* target = ref->target();

Modified: lld/trunk/lib/Platforms/Darwin/ExecutableWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Platforms/Darwin/ExecutableWriter.cpp?rev=154301&r1=154300&r2=154301&view=diff
==============================================================================
--- lld/trunk/lib/Platforms/Darwin/ExecutableWriter.cpp (original)
+++ lld/trunk/lib/Platforms/Darwin/ExecutableWriter.cpp Sun Apr  8 18:52:13 2012
@@ -556,9 +556,7 @@
     ArrayRef<uint8_t> content = atomInfo.atom->rawContent();
     buffer.resize(content.size());
     ::memcpy(buffer.data(), content.data(), content.size());
-    for (auto rit=atomInfo.atom->referencesBegin(), 
-               rend=atomInfo.atom->referencesEnd(); rit != rend; ++rit) {
-      const Reference* ref = *rit;
+    for (const Reference *ref : *atomInfo.atom) {
       uint32_t offset = ref->offsetInAtom();
       uint64_t targetAddress = 0;
       if ( ref->target() != nullptr )

Modified: lld/trunk/lib/Platforms/Darwin/StubAtoms.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Platforms/Darwin/StubAtoms.hpp?rev=154301&r1=154300&r2=154301&view=diff
==============================================================================
--- lld/trunk/lib/Platforms/Darwin/StubAtoms.hpp (original)
+++ lld/trunk/lib/Platforms/Darwin/StubAtoms.hpp Sun Apr  8 18:52:13 2012
@@ -126,13 +126,13 @@
     return false;
   }
   
-  virtual DefinedAtom::reference_iterator referencesBegin() const {
+  virtual DefinedAtom::reference_iterator begin() const {
     uintptr_t index = 0;
     const void* it = reinterpret_cast<const void*>(index);
     return reference_iterator(*this, it);
   }
 
-  virtual DefinedAtom::reference_iterator referencesEnd() const {
+  virtual DefinedAtom::reference_iterator end() const {
     uintptr_t index = _references.size();
     const void* it = reinterpret_cast<const void*>(index);
     return reference_iterator(*this, it);

Modified: lld/trunk/tools/lld-core/lld-core.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/tools/lld-core/lld-core.cpp?rev=154301&r1=154300&r2=154301&view=diff
==============================================================================
--- lld/trunk/tools/lld-core/lld-core.cpp (original)
+++ lld/trunk/tools/lld-core/lld-core.cpp Sun Apr  8 18:52:13 2012
@@ -119,11 +119,11 @@
     return ArrayRef<uint8_t>();
   }
   
-  virtual reference_iterator referencesBegin() const {
+  virtual reference_iterator begin() const {
     return reference_iterator(*this, nullptr);
   }
   
-  virtual reference_iterator referencesEnd() const {
+  virtual reference_iterator end() const {
     return reference_iterator(*this, nullptr);
   }
   
@@ -218,11 +218,11 @@
     return ArrayRef<uint8_t>();
   }
   
-  virtual reference_iterator referencesBegin() const {
+  virtual reference_iterator begin() const {
     return reference_iterator(*this, nullptr);
   }
   
-  virtual reference_iterator referencesEnd() const {
+  virtual reference_iterator end() const {
     return reference_iterator(*this, nullptr);
   }
   
@@ -449,9 +449,7 @@
 
   // InputFiles interface
   virtual void forEachInitialAtom(InputFiles::Handler& handler) const {
-    for (std::vector<const File *>::iterator fit = _files.begin();
-                                       fit != _files.end(); ++fit) {
-      const File* file = *fit;
+    for ( const File *file : _files ) {
       handler.doFile(*file);
       for(auto it=file->definedAtomsBegin(),end=file->definedAtomsEnd(); 
                                  it != end; ++it) {





More information about the llvm-commits mailing list