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;
77 // Forward declare iterator class template...
78 template<class GraphInfo> class DFIterator;
80 // Normal Depth First Iterator Definitions (Forward and Reverse)
81 typedef DFIterator< BasicBlockGraph> df_iterator;
82 typedef DFIterator<ConstBasicBlockGraph> df_const_iterator;
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);
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);
95 // Inverse Depth First Iterator Definitions (Forward and Reverse) - Traverse
96 // predecessors instead of successors...
98 typedef DFIterator< InverseBasicBlockGraph> idf_iterator;
99 typedef DFIterator<ConstInverseBasicBlockGraph> idf_const_iterator;
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);
107 //===--------------------------------------------------------------------===//
108 // Post Order CFG iterator code
109 //===--------------------------------------------------------------------===//
111 // This is used to visit basic blocks in a method in standard post order.
114 // Forward declare iterator class template...
115 template<class BBType, class SuccItTy> class POIterator;
117 typedef POIterator<BasicBlock, succ_iterator> po_iterator;
118 typedef POIterator<const BasicBlock,
119 succ_const_iterator> po_const_iterator;
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);
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);
132 //===--------------------------------------------------------------------===//
133 // Reverse Post Order CFG iterator code
134 //===--------------------------------------------------------------------===//
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.
143 // This class should be used like this:
145 // cfg::ReversePostOrderTraversal RPOT(MethodPtr); // Expensive to create
146 // for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
149 // for (cfg::rpo_iterator I = RPOT.begin(); I != RPOT.end(); ++I) {
155 //typedef reverse_iterator<vector<BasicBlock*>::const_iterator>
156 // rpo_const_iterator;
157 typedef reverse_iterator<vector<BasicBlock*>::iterator> rpo_iterator;
159 class ReversePostOrderTraversal;
161 } // End namespace cfg