[llvm] r207335 - [LCG] Switch the node iterator to use the new fancy adaptor base. This

Chandler Carruth chandlerc at gmail.com
Sat Apr 26 15:43:57 PDT 2014


Author: chandlerc
Date: Sat Apr 26 17:43:56 2014
New Revision: 207335

URL: http://llvm.org/viewvc/llvm-project?rev=207335&view=rev
Log:
[LCG] Switch the node iterator to use the new fancy adaptor base. This
is *much* cleaner, makes the iterator a full random access iterator,
etc.

Modified:
    llvm/trunk/include/llvm/Analysis/LazyCallGraph.h

Modified: llvm/trunk/include/llvm/Analysis/LazyCallGraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LazyCallGraph.h?rev=207335&r1=207334&r2=207335&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LazyCallGraph.h (original)
+++ llvm/trunk/include/llvm/Analysis/LazyCallGraph.h Sat Apr 26 17:43:56 2014
@@ -113,60 +113,30 @@ public:
   /// be scanned for "calls" or uses of functions and its child information
   /// will be constructed. All of these results are accumulated and cached in
   /// the graph.
-  class iterator : public std::iterator<std::bidirectional_iterator_tag, Node> {
+  class iterator : public iterator_adaptor_base<
+                       iterator, NodeVectorImplT::iterator, Node> {
     friend class LazyCallGraph;
     friend class LazyCallGraph::Node;
 
-    /// \brief Nonce type to select the constructor for the end iterator.
-    struct IsAtEndT {};
-
     LazyCallGraph *G;
     NodeVectorImplT::iterator NI;
 
-    // Build the begin iterator for a node.
-    explicit iterator(LazyCallGraph &G, NodeVectorImplT &Nodes)
-        : G(&G), NI(Nodes.begin()) {}
-
-    // Build the end iterator for a node. This is selected purely by overload.
-    iterator(LazyCallGraph &G, NodeVectorImplT &Nodes, IsAtEndT /*Nonce*/)
-        : G(&G), NI(Nodes.end()) {}
+    // Build the iterator for a specific position in a node list.
+    iterator(LazyCallGraph &G, NodeVectorImplT::iterator NI)
+        : iterator_adaptor_base(NI), G(&G) {}
 
   public:
     iterator() {}
 
-    bool operator==(const iterator &Arg) const { return NI == Arg.NI; }
-    bool operator!=(const iterator &Arg) const { return !operator==(Arg); }
-
     reference operator*() const {
-      if (NI->is<Node *>())
-        return *NI->get<Node *>();
+      if (I->is<Node *>())
+        return *I->get<Node *>();
 
-      Function *F = NI->get<Function *>();
+      Function *F = I->get<Function *>();
       Node &ChildN = G->get(*F);
-      *NI = &ChildN;
+      *I = &ChildN;
       return ChildN;
     }
-    pointer operator->() const { return &operator*(); }
-
-    iterator &operator++() {
-      ++NI;
-      return *this;
-    }
-    iterator operator++(int) {
-      iterator prev = *this;
-      ++*this;
-      return prev;
-    }
-
-    iterator &operator--() {
-      --NI;
-      return *this;
-    }
-    iterator operator--(int) {
-      iterator next = *this;
-      --*this;
-      return next;
-    }
   };
 
   /// \brief A node in the call graph.
@@ -200,8 +170,8 @@ public:
       return F;
     };
 
-    iterator begin() const { return iterator(*G, Callees); }
-    iterator end() const { return iterator(*G, Callees, iterator::IsAtEndT()); }
+    iterator begin() const { return iterator(*G, Callees.begin()); }
+    iterator end() const { return iterator(*G, Callees.end()); }
 
     /// Equality is defined as address equality.
     bool operator==(const Node &N) const { return this == &N; }
@@ -309,8 +279,8 @@ public:
   LazyCallGraph(LazyCallGraph &&G);
   LazyCallGraph &operator=(LazyCallGraph &&RHS);
 
-  iterator begin() { return iterator(*this, EntryNodes); }
-  iterator end() { return iterator(*this, EntryNodes, iterator::IsAtEndT()); }
+  iterator begin() { return iterator(*this, EntryNodes.begin()); }
+  iterator end() { return iterator(*this, EntryNodes.end()); }
 
   postorder_scc_iterator postorder_scc_begin() {
     return postorder_scc_iterator(*this);





More information about the llvm-commits mailing list