1 //===-- llvm/CFGdecls.h - CFG forward declarations ---------------*- C++ -*--=//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CFG_DECLS_H
11 #define LLVM_CFG_DECLS_H
13 #include "llvm/Value.h"
18 //===----------------------------------------------------------------------===//
20 //===----------------------------------------------------------------------===//
24 //===--------------------------------------------------------------------===//
25 // Predecessor iterator code
26 //===--------------------------------------------------------------------===//
28 // This is used to figure out what basic blocks we could be coming from.
31 // Forward declare iterator class template...
32 template <class _Ptr, class _USE_iterator> class PredIterator;
34 typedef PredIterator<BasicBlock, Value::use_iterator> pred_iterator;
35 typedef PredIterator<const BasicBlock,
36 Value::use_const_iterator> pred_const_iterator;
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);
44 //===--------------------------------------------------------------------===//
45 // Successor iterator code
46 //===--------------------------------------------------------------------===//
48 // This is used to figure out what basic blocks we could be going to...
51 // Forward declare iterator class template...
52 template <class _Term, class _BB> class SuccIterator;
54 typedef SuccIterator<TerminatorInst*, BasicBlock> succ_iterator;
55 typedef SuccIterator<const TerminatorInst*,
56 const BasicBlock> succ_const_iterator;
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);
64 //===--------------------------------------------------------------------===//
65 // <Reverse> Depth First CFG iterator code
66 //===--------------------------------------------------------------------===//
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
72 struct BasicBlockGraph;
73 struct ConstBasicBlockGraph;
74 struct InverseBasicBlockGraph;
75 struct ConstInverseBasicBlockGraph;
78 // Forward declare iterator class template...
79 template<class GraphInfo> class DFIterator;
81 // Normal Depth First Iterator Definitions (Forward and Reverse)
82 typedef DFIterator< BasicBlockGraph> df_iterator;
83 typedef DFIterator<ConstBasicBlockGraph> df_const_iterator;
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);
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);
96 // Inverse Depth First Iterator Definitions (Forward and Reverse) - Traverse
97 // predecessors instead of successors...
99 typedef DFIterator< InverseBasicBlockGraph> idf_iterator;
100 typedef DFIterator<ConstInverseBasicBlockGraph> idf_const_iterator;
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);
108 // Depth First Iterator Definitions for Types. This lets you iterator over
109 // (possibly cyclic) type graphs in dfo
111 typedef DFIterator<TypeGraph> tdf_iterator;
113 inline tdf_iterator tdf_begin(const Type *T, bool Reverse = false);
114 inline tdf_iterator tdf_end (const Type *T);
117 //===--------------------------------------------------------------------===//
118 // Post Order CFG iterator code
119 //===--------------------------------------------------------------------===//
121 // This is used to visit basic blocks in a method in standard post order.
124 // Forward declare iterator class template...
125 template<class BBType, class SuccItTy> class POIterator;
127 typedef POIterator<BasicBlock, succ_iterator> po_iterator;
128 typedef POIterator<const BasicBlock,
129 succ_const_iterator> po_const_iterator;
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);
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);
142 //===--------------------------------------------------------------------===//
143 // Reverse Post Order CFG iterator code
144 //===--------------------------------------------------------------------===//
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.
153 // This class should be used like this:
155 // cfg::ReversePostOrderTraversal RPOT(MethodPtr); // Expensive to create
156 // for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
159 // for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
165 //typedef reverse_iterator<vector<BasicBlock*>::const_iterator>
166 // rpo_const_iterator;
167 typedef reverse_iterator<vector<BasicBlock*>::iterator> rpo_iterator;
169 class ReversePostOrderTraversal;
171 } // End namespace cfg