Expose passinfo from BreakCriticalEdges pass so that it may be "Required" by
[oota-llvm.git] / include / llvm / ADT / PostOrderIterator.h
index 89a9b4db8699cac2480780f385cdeb56cbb0cee7..a9f13da03deb313c2eb1d328703f325a8880d559 100644 (file)
 #define LLVM_SUPPORT_POSTORDER_ITERATOR_H
 
 #include "Support/GraphTraits.h"
-#include <iterator>
+#include <Support/iterator>
 #include <stack>
 #include <set>
 
 template<class GraphT, class GT = GraphTraits<GraphT> >
-class po_iterator : public std::forward_iterator<typename GT::NodeType,
-                                                 ptrdiff_t> {
+class po_iterator : public forward_iterator<typename GT::NodeType, ptrdiff_t> {
+  typedef forward_iterator<typename GT::NodeType, ptrdiff_t> super;
+  typedef typename super::pointer pointer;
   typedef typename GT::NodeType          NodeType;
   typedef typename GT::ChildIteratorType ChildItTy;
 
-  set<NodeType *>   Visited;    // All of the blocks visited so far...
+  std::set<NodeType *> Visited;    // All of the blocks visited so far...
   // VisitStack - Used to maintain the ordering.  Top = current block
   // First element is basic block pointer, second is the 'next child' to visit
-  stack<pair<NodeType *, ChildItTy> > VisitStack;
+  std::stack<std::pair<NodeType *, ChildItTy> > VisitStack;
 
   void traverseChild() {
     while (VisitStack.top().second != GT::child_end(VisitStack.top().first)) {
@@ -112,29 +113,28 @@ ipo_iterator<T> ipo_end(T G){
 //
 // This class should be used like this:
 // {
-//   cfg::ReversePostOrderTraversal RPOT(MethodPtr);   // Expensive to create
-//   for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
+//   ReversePostOrderTraversal<Method*> RPOT(MethodPtr); // Expensive to create
+//   for (rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
 //      ...
 //   }
-//   for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
+//   for (rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
 //      ...
 //   }
 // }
 //
 
-typedef reverse_iterator<vector<BasicBlock*>::iterator> rpo_iterator;
-// TODO: FIXME: ReversePostOrderTraversal is not generic!
+template<class GraphT, class GT = GraphTraits<GraphT> >
 class ReversePostOrderTraversal {
-  vector<BasicBlock*> Blocks;       // Block list in normal PO order
-  inline void Initialize(BasicBlock *BB) {
+  typedef typename GT::NodeType NodeType;
+  std::vector<NodeType*> Blocks;       // Block list in normal PO order
+  inline void Initialize(NodeType *BB) {
     copy(po_begin(BB), po_end(BB), back_inserter(Blocks));
   }
 public:
-  inline ReversePostOrderTraversal(Method *M) {
-    Initialize(M->front());
-  }
-  inline ReversePostOrderTraversal(BasicBlock *BB) {
-    Initialize(BB);
+  typedef typename std::vector<NodeType*>::reverse_iterator rpo_iterator;
+
+  inline ReversePostOrderTraversal(GraphT G) {
+    Initialize(GT::getEntryNode(G));
   }
 
   // Because we want a reverse post order, use reverse iterators from the vector