Add support for walking type graphs
[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 struct TypeGraph;
77
78 // Forward declare iterator class template...
79 template<class GraphInfo> class DFIterator;
80
81 // Normal Depth First Iterator Definitions (Forward and Reverse)
82 typedef DFIterator<     BasicBlockGraph> df_iterator;
83 typedef DFIterator<ConstBasicBlockGraph> df_const_iterator;
84
85 inline df_iterator       df_begin(      Method *M, bool Reverse = false);
86 inline df_const_iterator df_begin(const Method *M, bool Reverse = false);
87 inline df_iterator       df_end  (      Method *M);
88 inline df_const_iterator df_end  (const Method *M);
89
90 inline df_iterator       df_begin(      BasicBlock *BB, bool Reverse = false);
91 inline df_const_iterator df_begin(const BasicBlock *BB, bool Reverse = false);
92 inline df_iterator       df_end  (      BasicBlock *BB);
93 inline df_const_iterator df_end  (const BasicBlock *BB);
94
95
96 // Inverse Depth First Iterator Definitions (Forward and Reverse) - Traverse
97 // predecessors instead of successors...
98 //
99 typedef DFIterator<     InverseBasicBlockGraph> idf_iterator;
100 typedef DFIterator<ConstInverseBasicBlockGraph> idf_const_iterator;
101
102 inline idf_iterator       idf_begin(      BasicBlock *BB, bool Reverse = false);
103 inline idf_const_iterator idf_begin(const BasicBlock *BB, bool Reverse = false);
104 inline idf_iterator       idf_end  (      BasicBlock *BB);
105 inline idf_const_iterator idf_end  (const BasicBlock *BB);
106
107
108 // Depth First Iterator Definitions for Types.  This lets you iterator over 
109 // (possibly cyclic) type graphs in dfo
110 //
111 typedef DFIterator<TypeGraph> tdf_iterator;
112
113 inline tdf_iterator tdf_begin(const Type *T, bool Reverse = false);
114 inline tdf_iterator tdf_end  (const Type *T);
115
116
117 //===--------------------------------------------------------------------===//
118 // Post Order CFG iterator code
119 //===--------------------------------------------------------------------===//
120 // 
121 // This is used to visit basic blocks in a method in standard post order.
122 //
123
124 // Forward declare iterator class template...
125 template<class BBType, class SuccItTy> class POIterator;
126
127 typedef POIterator<BasicBlock, succ_iterator> po_iterator;
128 typedef POIterator<const BasicBlock, 
129                    succ_const_iterator> po_const_iterator;
130
131 inline po_iterator       po_begin(      Method *M);
132 inline po_const_iterator po_begin(const Method *M);
133 inline po_iterator       po_end  (      Method *M);
134 inline po_const_iterator po_end  (const Method *M);
135
136 inline po_iterator       po_begin(      BasicBlock *BB);
137 inline po_const_iterator po_begin(const BasicBlock *BB);
138 inline po_iterator       po_end  (      BasicBlock *BB);
139 inline po_const_iterator po_end  (const BasicBlock *BB);
140
141
142 //===--------------------------------------------------------------------===//
143 // Reverse Post Order CFG iterator code
144 //===--------------------------------------------------------------------===//
145 // 
146 // This is used to visit basic blocks in a method in reverse post order.  This
147 // class is awkward to use because I don't know a good incremental algorithm to
148 // computer RPO from a graph.  Because of this, the construction of the 
149 // ReversePostOrderTraversal object is expensive (it must walk the entire graph
150 // with a postorder iterator to build the data structures).  The moral of this
151 // story is: Don't create more ReversePostOrderTraversal classes than neccesary.
152 //
153 // This class should be used like this:
154 // {
155 //   cfg::ReversePostOrderTraversal RPOT(MethodPtr);   // Expensive to create
156 //   for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
157 //      ...
158 //   }
159 //   for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
160 //      ...
161 //   }
162 // }
163 //
164
165 //typedef reverse_iterator<vector<BasicBlock*>::const_iterator> 
166 // rpo_const_iterator;
167 typedef reverse_iterator<vector<BasicBlock*>::iterator> rpo_iterator;
168
169 class ReversePostOrderTraversal;
170
171 }    // End namespace cfg
172
173 #endif