summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-04-26 22:43:56 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-04-26 22:43:56 +0000
commitb9acdb79a5792a20b6b749a532ee0c347cf4d915 (patch)
treebbc1ee3debb616c60cae70bf96c4594b2714be73 /include
parentc37bb3a98f9ad7a694bff8a3f1ff54c9e5a05330 (diff)
downloadllvm-b9acdb79a5792a20b6b749a532ee0c347cf4d915.tar.gz
llvm-b9acdb79a5792a20b6b749a532ee0c347cf4d915.tar.bz2
llvm-b9acdb79a5792a20b6b749a532ee0c347cf4d915.tar.xz
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207335 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Analysis/LazyCallGraph.h56
1 files changed, 13 insertions, 43 deletions
diff --git a/include/llvm/Analysis/LazyCallGraph.h b/include/llvm/Analysis/LazyCallGraph.h
index 07ba0004bd..99e6fc25d9 100644
--- a/include/llvm/Analysis/LazyCallGraph.h
+++ b/include/llvm/Analysis/LazyCallGraph.h
@@ -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);