* Added comments
[oota-llvm.git] / include / llvm / CFGdecls.h
1 //===-- llvm/CFGdecls.h - CFG forward declarations ---------------*- C++ -*--=//
2 //
3 // This file contains forward declarations for CFG functions and data
4 // structures.  This is used to reduce compile time dependencies among files.
5 // Any users of these functions must include CFG.h to get their full 
6 // definitions.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CFG_DECLS_H
11 #define LLVM_CFG_DECLS_H
12
13 #include "llvm/Value.h"
14 class TerminatorInst;
15 class BasicBlock;
16 class Method;
17
18 //===----------------------------------------------------------------------===//
19 //                                Interface
20 //===----------------------------------------------------------------------===//
21
22 namespace cfg {
23
24 //===--------------------------------------------------------------------===//
25 // Predecessor iterator code
26 //===--------------------------------------------------------------------===//
27 // 
28 // This is used to figure out what basic blocks we could be coming from.
29 //
30
31 // Forward declare iterator class template...
32 template <class _Ptr, class _USE_iterator> class PredIterator;
33
34 typedef PredIterator<BasicBlock, Value::use_iterator> pred_iterator;
35 typedef PredIterator<const BasicBlock, 
36                      Value::use_const_iterator> pred_const_iterator;
37
38 inline pred_iterator       pred_begin(      BasicBlock *BB);
39 inline pred_const_iterator pred_begin(const BasicBlock *BB);
40 inline pred_iterator       pred_end  (      BasicBlock *BB);
41 inline pred_const_iterator pred_end  (const BasicBlock *BB);
42
43
44 //===--------------------------------------------------------------------===//
45 // Successor iterator code
46 //===--------------------------------------------------------------------===//
47 // 
48 // This is used to figure out what basic blocks we could be going to...
49 //
50
51 // Forward declare iterator class template...
52 template <class _Term, class _BB> class SuccIterator;
53
54 typedef SuccIterator<TerminatorInst*, BasicBlock> succ_iterator;
55 typedef SuccIterator<const TerminatorInst*, 
56                      const BasicBlock> succ_const_iterator;
57
58 inline succ_iterator       succ_begin(      BasicBlock *BB);
59 inline succ_const_iterator succ_begin(const BasicBlock *BB);
60 inline succ_iterator       succ_end  (      BasicBlock *BB);
61 inline succ_const_iterator succ_end  (const BasicBlock *BB);
62
63
64 //===--------------------------------------------------------------------===//
65 // <Reverse> Depth First CFG iterator code
66 //===--------------------------------------------------------------------===//
67 // 
68 // This is used to visit basic blocks in a method in either depth first, or 
69 // reverse depth first ordering, depending on the value passed to the df_begin
70 // method.
71 //
72 struct      BasicBlockGraph;
73 struct ConstBasicBlockGraph;
74 struct      InverseBasicBlockGraph;
75 struct ConstInverseBasicBlockGraph;
76
77 // Forward declare iterator class template...
78 template<class GraphInfo> class DFIterator;
79
80 // Normal Depth First Iterator Definitions (Forward and Reverse)
81 typedef DFIterator<     BasicBlockGraph> df_iterator;
82 typedef DFIterator<ConstBasicBlockGraph> df_const_iterator;
83
84 inline df_iterator       df_begin(      Method *M, bool Reverse = false);
85 inline df_const_iterator df_begin(const Method *M, bool Reverse = false);
86 inline df_iterator       df_end  (      Method *M);
87 inline df_const_iterator df_end  (const Method *M);
88
89 inline df_iterator       df_begin(      BasicBlock *BB, bool Reverse = false);
90 inline df_const_iterator df_begin(const BasicBlock *BB, bool Reverse = false);
91 inline df_iterator       df_end  (      BasicBlock *BB);
92 inline df_const_iterator df_end  (const BasicBlock *BB);
93
94
95 // Inverse Depth First Iterator Definitions (Forward and Reverse) - Traverse
96 // predecessors instead of successors...
97 //
98 typedef DFIterator<     InverseBasicBlockGraph> idf_iterator;
99 typedef DFIterator<ConstInverseBasicBlockGraph> idf_const_iterator;
100
101 inline idf_iterator       idf_begin(      BasicBlock *BB, bool Reverse = false);
102 inline idf_const_iterator idf_begin(const BasicBlock *BB, bool Reverse = false);
103 inline idf_iterator       idf_end  (      BasicBlock *BB);
104 inline idf_const_iterator idf_end  (const BasicBlock *BB);
105
106
107 //===--------------------------------------------------------------------===//
108 // Post Order CFG iterator code
109 //===--------------------------------------------------------------------===//
110 // 
111 // This is used to visit basic blocks in a method in standard post order.
112 //
113
114 // Forward declare iterator class template...
115 template<class BBType, class SuccItTy> class POIterator;
116
117 typedef POIterator<BasicBlock, succ_iterator> po_iterator;
118 typedef POIterator<const BasicBlock, 
119                    succ_const_iterator> po_const_iterator;
120
121 inline po_iterator       po_begin(      Method *M);
122 inline po_const_iterator po_begin(const Method *M);
123 inline po_iterator       po_end  (      Method *M);
124 inline po_const_iterator po_end  (const Method *M);
125
126 inline po_iterator       po_begin(      BasicBlock *BB);
127 inline po_const_iterator po_begin(const BasicBlock *BB);
128 inline po_iterator       po_end  (      BasicBlock *BB);
129 inline po_const_iterator po_end  (const BasicBlock *BB);
130
131
132 //===--------------------------------------------------------------------===//
133 // Reverse Post Order CFG iterator code
134 //===--------------------------------------------------------------------===//
135 // 
136 // This is used to visit basic blocks in a method in reverse post order.  This
137 // class is awkward to use because I don't know a good incremental algorithm to
138 // computer RPO from a graph.  Because of this, the construction of the 
139 // ReversePostOrderTraversal object is expensive (it must walk the entire graph
140 // with a postorder iterator to build the data structures).  The moral of this
141 // story is: Don't create more ReversePostOrderTraversal classes than neccesary.
142 //
143 // This class should be used like this:
144 // {
145 //   cfg::ReversePostOrderTraversal RPOT(MethodPtr);   // Expensive to create
146 //   for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
147 //      ...
148 //   }
149 //   for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
150 //      ...
151 //   }
152 // }
153 //
154
155 //typedef reverse_iterator<vector<BasicBlock*>::const_iterator> 
156 // rpo_const_iterator;
157 typedef reverse_iterator<vector<BasicBlock*>::iterator> rpo_iterator;
158
159 class ReversePostOrderTraversal;
160
161 }    // End namespace cfg
162
163 #endif