llvm.org GIT mirror llvm / f0604b8
Pull predecessor and successor iterators out of the CFG*.h files, and plop them into the BasicBlock class where they should be. pred_begin/pred_end become methods on BasicBlock, and the cfg namespace isn't used anymore. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@691 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 19 years ago
16 changed file(s) with 181 addition(s) and 373 deletion(s). Raw diff Collapse all Expand all
None /* Title: MethodLiveVarInfo.h
0 /* Title: MethodLiveVarInfo.h -*- C++ -*-
11 Author: Ruchira Sasanka
22 Date: Jun 30, 01
33 Purpose:
7272 #include "llvm/BasicBlock.h"
7373 #include "llvm/Instruction.h"
7474 #include "llvm/Method.h"
75 #include "llvm/CFG.h"
7675
7776 #include "LiveVarMap.h"
7877 #include "BBLiveVar.h"
2121 #ifndef LLVM_BASICBLOCK_H
2222 #define LLVM_BASICBLOCK_H
2323
24 #include "llvm/Value.h" // Get the definition of Value
24 #include "llvm/Value.h"
2525 #include "llvm/ValueHolder.h"
2626 #include "llvm/Support/GraphTraits.h"
27
28 #include "llvm/CFGdecls.h" // TODO FIXME: remove
27 #include "llvm/InstrTypes.h"
28 #include
2929
3030 class Instruction;
3131 class Method;
3333 class MachineCodeForBasicBlock;
3434
3535 class BasicBlock : public Value { // Basic blocks are data objects also
36 template class PredIterator;
37 template class SuccIterator;
3638 public:
3739 typedef ValueHolder InstListType;
3840 private :
4951 typedef reverse_iterator const_reverse_iterator;
5052 typedef reverse_iterator reverse_iterator;
5153
52 typedef cfg::succ_iterator succ_iterator; // Include CFG.h to use these
53 typedef cfg::pred_iterator pred_iterator;
54 typedef cfg::succ_const_iterator succ_const_iterator;
55 typedef cfg::pred_const_iterator pred_const_iterator;
56
54 // Predecessor and successor iterators...
55 typedef PredIterator pred_iterator;
56 typedef PredIterator
57 Value::use_const_iterator> pred_const_iterator;
58 typedef SuccIterator succ_iterator;
59 typedef SuccIterator
60 const BasicBlock> succ_const_iterator;
61
62 // Ctor, dtor
5763 BasicBlock(const string &Name = "", Method *Parent = 0);
5864 ~BasicBlock();
5965
6066 // Specialize setName to take care of symbol table majik
6167 virtual void setName(const string &name, SymbolTable *ST = 0);
6268
69 // getParent - Return the enclosing method, or null if none
6370 const Method *getParent() const { return InstList.getParent(); }
6471 Method *getParent() { return InstList.getParent(); }
6572
6976 //
7077 TerminatorInst *getTerminator();
7178 const TerminatorInst *const getTerminator() const;
72
7379
7480 // Machine code accessor...
7581 inline MachineCodeForBasicBlock& getMachineInstrVec() const {
7884
7985 //===--------------------------------------------------------------------===//
8086 // Instruction iterator methods
87 //
8188 inline iterator begin() { return InstList.begin(); }
8289 inline const_iterator begin() const { return InstList.begin(); }
8390 inline iterator end () { return InstList.end(); }
139146 // the basic block).
140147 //
141148 BasicBlock *splitBasicBlock(iterator I);
142 };
143
144 #include "llvm/CFG.h" // TODO FIXME when succ iterators are in BB.h
149
150
151 //===--------------------------------------------------------------------===//
152 // Predecessor and Successor Iterators
153 //
154 template // Predecessor Iterator
155 class PredIterator : public std::bidirectional_iterator<_Ptr, ptrdiff_t> {
156 _Ptr *BB;
157 _USE_iterator It;
158 public:
159 typedef PredIterator<_Ptr,_USE_iterator> _Self;
160
161 inline void advancePastConstPool() {
162 // TODO: This is bad
163 // Loop to ignore constant pool references
164 while (It != BB->use_end() &&
165 ((!(*It)->isInstruction()) ||
166 !(((Instruction*)(*It))->isTerminator())))
167 ++It;
168 }
169
170 inline PredIterator(_Ptr *bb) : BB(bb), It(bb->use_begin()) {
171 advancePastConstPool();
172 }
173 inline PredIterator(_Ptr *bb, bool) : BB(bb), It(bb->use_end()) {}
174
175 inline bool operator==(const _Self& x) const { return It == x.It; }
176 inline bool operator!=(const _Self& x) const { return !operator==(x); }
177
178 inline pointer operator*() const {
179 return (*It)->castInstructionAsserting()->getParent();
180 }
181 inline pointer *operator->() const { return &(operator*()); }
182
183 inline _Self& operator++() { // Preincrement
184 ++It; advancePastConstPool();
185 return *this;
186 }
187
188 inline _Self operator++(int) { // Postincrement
189 _Self tmp = *this; ++*this; return tmp;
190 }
191
192 inline _Self& operator--() { --It; return *this; } // Predecrement
193 inline _Self operator--(int) { // Postdecrement
194 _Self tmp = *this; --*this; return tmp;
195 }
196 };
197
198 inline pred_iterator pred_begin() { return pred_iterator(this); }
199 inline pred_const_iterator pred_begin() const {
200 return pred_const_iterator(this);
201 }
202 inline pred_iterator pred_end() { return pred_iterator(this, true); }
203 inline pred_const_iterator pred_end() const {
204 return pred_const_iterator(this, true);
205 }
206
207 template // Successor Iterator
208 class SuccIterator : public std::bidirectional_iterator<_BB, ptrdiff_t> {
209 const _Term Term;
210 unsigned idx;
211 public:
212 typedef SuccIterator<_Term, _BB> _Self;
213 // TODO: This can be random access iterator, need operator+ and stuff tho
214
215 inline SuccIterator(_Term T) : Term(T), idx(0) { // begin iterator
216 assert(T && "getTerminator returned null!");
217 }
218 inline SuccIterator(_Term T, bool) // end iterator
219 : Term(T), idx(Term->getNumSuccessors()) {
220 assert(T && "getTerminator returned null!");
221 }
222
223 inline bool operator==(const _Self& x) const { return idx == x.idx; }
224 inline bool operator!=(const _Self& x) const { return !operator==(x); }
225
226 inline pointer operator*() const { return Term->getSuccessor(idx); }
227 inline pointer operator->() const { return operator*(); }
228
229 inline _Self& operator++() { ++idx; return *this; } // Preincrement
230 inline _Self operator++(int) { // Postincrement
231 _Self tmp = *this; ++*this; return tmp;
232 }
233
234 inline _Self& operator--() { --idx; return *this; } // Predecrement
235 inline _Self operator--(int) { // Postdecrement
236 _Self tmp = *this; --*this; return tmp;
237 }
238 };
239
240 inline succ_iterator succ_begin() { return succ_iterator(getTerminator()); }
241 inline succ_const_iterator succ_begin() const {
242 return succ_const_iterator(getTerminator());
243 }
244 inline succ_iterator succ_end() {return succ_iterator(getTerminator(), true);}
245 inline succ_const_iterator succ_end() const {
246 return succ_const_iterator(getTerminator(), true);
247 }
248 };
249
250
251 //===--------------------------------------------------------------------===//
252 // GraphTraits specializations for basic block graphs (CFGs)
253 //===--------------------------------------------------------------------===//
145254
146255 // Provide specializations of GraphTraits to be able to treat a method as a
147256 // graph of basic blocks...
152261
153262 static NodeType *getEntryNode(BasicBlock *BB) { return BB; }
154263 static inline ChildIteratorType child_begin(NodeType *N) {
155 return cfg::succ_begin(N);
264 return N->succ_begin();
156265 }
157266 static inline ChildIteratorType child_end(NodeType *N) {
158 return cfg::succ_end(N);
267 return N->succ_end();
159268 }
160269 };
161270
166275 static NodeType *getEntryNode(const BasicBlock *BB) { return BB; }
167276
168277 static inline ChildIteratorType child_begin(NodeType *N) {
169 return cfg::succ_begin(N);
278 return N->succ_begin();
170279 }
171280 static inline ChildIteratorType child_end(NodeType *N) {
172 return cfg::succ_end(N);
281 return N->succ_end();
173282 }
174283 };
175284
183292 typedef BasicBlock::pred_iterator ChildIteratorType;
184293 static NodeType *getEntryNode(Inverse G) { return G.Graph; }
185294 static inline ChildIteratorType child_begin(NodeType *N) {
186 return cfg::pred_begin(N);
295 return N->pred_begin();
187296 }
188297 static inline ChildIteratorType child_end(NodeType *N) {
189 return cfg::pred_end(N);
298 return N->pred_end();
190299 }
191300 };
192301
197306 return G.Graph;
198307 }
199308 static inline ChildIteratorType child_begin(NodeType *N) {
200 return cfg::pred_begin(N);
309 return N->pred_begin();
201310 }
202311 static inline ChildIteratorType child_end(NodeType *N) {
203 return cfg::pred_end(N);
312 return N->pred_end();
204313 }
205314 };
206315
+0
-149
include/llvm/CFG.h less more
None //===-- llvm/CFG.h - CFG definitions and useful classes ----------*- C++ -*--=//
1 //
2 // This file contains the class definitions useful for operating on the control
3 // flow graph.
4 //
5 // Currently it contains functionality for these three applications:
6 //
7 // 1. Iterate over the predecessors of a basic block:
8 // pred_iterator, pred_const_iterator, pred_begin, pred_end
9 // 2. Iterate over the successors of a basic block:
10 // succ_iterator, succ_const_iterator, succ_begin, succ_end
11 // 3. Iterate over the basic blocks of a method in depth first ordering or
12 // reverse depth first order. df_iterator, df_const_iterator,
13 // df_begin, df_end. df_begin takes an arg to specify reverse or not.
14 // 4. Iterator over the basic blocks of a method in post order.
15 // 5. Iterator over a method in reverse post order.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_CFG_H
20 #define LLVM_CFG_H
21
22 #include "llvm/CFGdecls.h" // See this file for concise interface info
23 #include "llvm/BasicBlock.h"
24 #include "llvm/InstrTypes.h"
25 #include "llvm/Type.h"
26 #include
27
28 namespace cfg {
29
30 //===----------------------------------------------------------------------===//
31 // Implementation
32 //===----------------------------------------------------------------------===//
33
34 //===----------------------------------------------------------------------===//
35 // Basic Block Predecessor Iterator
36 //
37
38 template // Predecessor Iterator
39 class PredIterator : public std::bidirectional_iterator<_Ptr, ptrdiff_t> {
40 _Ptr *BB;
41 _USE_iterator It;
42 public:
43 typedef PredIterator<_Ptr,_USE_iterator> _Self;
44
45 inline void advancePastConstPool() {
46 // TODO: This is bad
47 // Loop to ignore constant pool references
48 while (It != BB->use_end() &&
49 ((!(*It)->isInstruction()) ||
50 !(((Instruction*)(*It))->isTerminator())))
51 ++It;
52 }
53
54 inline PredIterator(_Ptr *bb) : BB(bb), It(bb->use_begin()) {
55 advancePastConstPool();
56 }
57 inline PredIterator(_Ptr *bb, bool) : BB(bb), It(bb->use_end()) {}
58
59 inline bool operator==(const _Self& x) const { return It == x.It; }
60 inline bool operator!=(const _Self& x) const { return !operator==(x); }
61
62 inline pointer operator*() const {
63 return (*It)->castInstructionAsserting()->getParent();
64 }
65 inline pointer *operator->() const { return &(operator*()); }
66
67 inline _Self& operator++() { // Preincrement
68 ++It; advancePastConstPool();
69 return *this;
70 }
71
72 inline _Self operator++(int) { // Postincrement
73 _Self tmp = *this; ++*this; return tmp;
74 }
75
76 inline _Self& operator--() { --It; return *this; } // Predecrement
77 inline _Self operator--(int) { // Postdecrement
78 _Self tmp = *this; --*this; return tmp;
79 }
80 };
81
82 inline pred_iterator pred_begin( BasicBlock *BB) {
83 return pred_iterator(BB);
84 }
85 inline pred_const_iterator pred_begin(const BasicBlock *BB) {
86 return pred_const_iterator(BB);
87 }
88 inline pred_iterator pred_end( BasicBlock *BB) {
89 return pred_iterator(BB,true);
90 }
91 inline pred_const_iterator pred_end(const BasicBlock *BB) {
92 return pred_const_iterator(BB,true);
93 }
94
95
96 //===----------------------------------------------------------------------===//
97 // Basic Block Successor Iterator
98 //
99
100 template // Successor Iterator
101 class SuccIterator : public std::bidirectional_iterator<_BB, ptrdiff_t> {
102 const _Term Term;
103 unsigned idx;
104 public:
105 typedef SuccIterator<_Term, _BB> _Self;
106 // TODO: This can be random access iterator, need operator+ and stuff tho
107
108 inline SuccIterator(_Term T) : Term(T), idx(0) { // begin iterator
109 assert(T && "getTerminator returned null!");
110 }
111 inline SuccIterator(_Term T, bool) // end iterator
112 : Term(T), idx(Term->getNumSuccessors()) {
113 assert(T && "getTerminator returned null!");
114 }
115
116 inline bool operator==(const _Self& x) const { return idx == x.idx; }
117 inline bool operator!=(const _Self& x) const { return !operator==(x); }
118
119 inline pointer operator*() const { return Term->getSuccessor(idx); }
120 inline pointer operator->() const { return operator*(); }
121
122 inline _Self& operator++() { ++idx; return *this; } // Preincrement
123 inline _Self operator++(int) { // Postincrement
124 _Self tmp = *this; ++*this; return tmp;
125 }
126
127 inline _Self& operator--() { --idx; return *this; } // Predecrement
128 inline _Self operator--(int) { // Postdecrement
129 _Self tmp = *this; --*this; return tmp;
130 }
131 };
132
133 inline succ_iterator succ_begin( BasicBlock *BB) {
134 return succ_iterator(BB->getTerminator());
135 }
136 inline succ_const_iterator succ_begin(const BasicBlock *BB) {
137 return succ_const_iterator(BB->getTerminator());
138 }
139 inline succ_iterator succ_end( BasicBlock *BB) {
140 return succ_iterator(BB->getTerminator(),true);
141 }
142 inline succ_const_iterator succ_end(const BasicBlock *BB) {
143 return succ_const_iterator(BB->getTerminator(),true);
144 }
145
146 } // End namespace cfg
147
148 #endif
+0
-144
include/llvm/CFGdecls.h less more
None //===-- llvm/CFGdecls.h - CFG forward declarations ---------------*- C++ -*--=//
1 //
2 // This file contains forward declarations for CFG functions and data
3 // structures. This is used to reduce compile time dependencies among files.
4 // Any users of these functions must include CFG.h to get their full
5 // definitions.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_CFG_DECLS_H
10 #define LLVM_CFG_DECLS_H
11
12 #include "llvm/Value.h"
13 class TerminatorInst;
14 class BasicBlock;
15 class Method;
16
17 //===----------------------------------------------------------------------===//
18 // Interface
19 //===----------------------------------------------------------------------===//
20
21 namespace cfg {
22
23 //===--------------------------------------------------------------------===//
24 // Predecessor iterator code
25 //===--------------------------------------------------------------------===//
26 //
27 // This is used to figure out what basic blocks we could be coming from.
28 //
29
30 // Forward declare iterator class template...
31 template class PredIterator;
32
33 typedef PredIterator pred_iterator;
34 typedef PredIterator
35 Value::use_const_iterator> pred_const_iterator;
36
37 inline pred_iterator pred_begin( BasicBlock *BB);
38 inline pred_const_iterator pred_begin(const BasicBlock *BB);
39 inline pred_iterator pred_end ( BasicBlock *BB);
40 inline pred_const_iterator pred_end (const BasicBlock *BB);
41
42
43 //===--------------------------------------------------------------------===//
44 // Successor iterator code
45 //===--------------------------------------------------------------------===//
46 //
47 // This is used to figure out what basic blocks we could be going to...
48 //
49
50 // Forward declare iterator class template...
51 template class SuccIterator;
52
53 typedef SuccIterator succ_iterator;
54 typedef SuccIterator
55 const BasicBlock> succ_const_iterator;
56
57 inline succ_iterator succ_begin( BasicBlock *BB);
58 inline succ_const_iterator succ_begin(const BasicBlock *BB);
59 inline succ_iterator succ_end ( BasicBlock *BB);
60 inline succ_const_iterator succ_end (const BasicBlock *BB);
61
62 #if 0
63 //===--------------------------------------------------------------------===//
64 // Depth First CFG iterator code
65 //===--------------------------------------------------------------------===//
66 //
67 // This is used to visit basic blocks in a method in either depth first, or
68 // reverse depth first ordering, depending on the value passed to the df_begin
69 // method.
70 //
71 struct BasicBlockGraph;
72 struct ConstBasicBlockGraph;
73 struct InverseBasicBlockGraph;
74 struct ConstInverseBasicBlockGraph;
75 struct TypeGraph;
76
77 // Forward declare iterator class template...
78 template class DFIterator;
79
80 // Normal Depth First Iterator Definitions (Forward and Reverse)
81 typedef DFIterator< BasicBlockGraph> df_iterator;
82 typedef DFIterator 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 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 // Depth First Iterator Definitions for Types. This lets you iterator over
108 // (possibly cyclic) type graphs in dfo
109 //
110 typedef DFIterator tdf_iterator;
111
112 inline tdf_iterator tdf_begin(const Type *T, bool Reverse = false);
113 inline tdf_iterator tdf_end (const Type *T);
114
115
116 //===--------------------------------------------------------------------===//
117 // Post Order CFG iterator code
118 //===--------------------------------------------------------------------===//
119 //
120 // This is used to visit basic blocks in a method in standard post order.
121 //
122
123 // Forward declare iterator class template...
124 template class POIterator;
125
126 typedef POIterator po_iterator;
127 typedef POIterator
128 succ_const_iterator> po_const_iterator;
129
130 inline po_iterator po_begin( Method *M);
131 inline po_const_iterator po_begin(const Method *M);
132 inline po_iterator po_end ( Method *M);
133 inline po_const_iterator po_end (const Method *M);
134
135 inline po_iterator po_begin( BasicBlock *BB);
136 inline po_const_iterator po_begin(const BasicBlock *BB);
137 inline po_iterator po_end ( BasicBlock *BB);
138 inline po_const_iterator po_end (const BasicBlock *BB);
139 #endif
140
141 } // End namespace cfg
142
143 #endif
None /* Title: MethodLiveVarInfo.h
0 /* Title: MethodLiveVarInfo.h -*- C++ -*-
11 Author: Ruchira Sasanka
22 Date: Jun 30, 01
33 Purpose:
7272 #include "llvm/BasicBlock.h"
7373 #include "llvm/Instruction.h"
7474 #include "llvm/Method.h"
75 #include "llvm/CFG.h"
7675
7776 #include "LiveVarMap.h"
7877 #include "BBLiveVar.h"
77 #include "llvm/Analysis/Interval.h"
88 #include "llvm/BasicBlock.h"
99
10 using namespace cfg;
11
1210 //===----------------------------------------------------------------------===//
1311 // Interval Implementation
1412 //===----------------------------------------------------------------------===//
1513
1614 // isLoop - Find out if there is a back edge in this interval...
1715 //
18 bool Interval::isLoop() const {
16 bool cfg::Interval::isLoop() const {
1917 // There is a loop in this interval iff one of the predecessors of the header
2018 // node lives in the interval.
21 for (BasicBlock::pred_iterator I = pred_begin(HeaderNode),
22 E = pred_end(HeaderNode); I != E; ++I) {
19 for (BasicBlock::pred_iterator I = HeaderNode->pred_begin(),
20 E = HeaderNode->pred_end(); I != E; ++I) {
2321 if (contains(*I)) return true;
2422 }
2523 return false;
161161 // whose POId is lower
162162
163163
164 cfg::pred_const_iterator PredBBI = cfg::pred_begin(BaseBB);
165
166 for( ; PredBBI != cfg::pred_end(BaseBB) ; PredBBI++) {
164 BasicBlock::pred_const_iterator PredBBI = BaseBB->pred_begin();
165
166 for( ; PredBBI != BaseBB->pred_end() ; PredBBI++) {
167167 assert( *PredBBI ); // assert that the predecessor is valid
168168 BBLiveVar *PredLVBB = LVMap[*PredBBI];
169169
None /* Title: BBLiveVar.h
0 /* Title: BBLiveVar.h -*- C++ -*-
11 Author: Ruchira Sasanka
22 Date: Jun 30, 01
33 Purpose: This is a wrapper class for BasicBlock which is used by live
1212
1313 #include "llvm/BasicBlock.h"
1414 #include "llvm/Instruction.h"
15 #include "llvm/CFG.h"
1615 #include "llvm/Type.h"
1716 #include "llvm/iOther.h"
1817
6262 df_iterator It = df_begin(M), End = df_end(M);
6363 for ( ; It != End; ++It) {
6464 const BasicBlock *BB = *It;
65 pred_const_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
65 BasicBlock::pred_const_iterator PI = BB->pred_begin(),
66 PEnd = BB->pred_end();
6667 if (PI != PEnd) { // Is there SOME predecessor?
6768 // Loop until we get to a predecessor that has had it's dom set filled
6869 // in at least once. We are guaranteed to have this because we are
113114 idf_iterator It = idf_begin(Root), End = idf_end(Root);
114115 for ( ; It != End; ++It) {
115116 const BasicBlock *BB = *It;
116 succ_const_iterator PI = succ_begin(BB), PEnd = succ_end(BB);
117 BasicBlock::succ_const_iterator PI = BB->succ_begin(),
118 PEnd = BB->succ_end();
117119 if (PI != PEnd) { // Is there SOME predecessor?
118120 // Loop until we get to a successor that has had it's dom set filled
119121 // in at least once. We are guaranteed to have this because we are
319321 const BasicBlock *BB = Node->getNode();
320322 DomSetType &S = Frontiers[BB]; // The new set to fill in...
321323
322 for (succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB);
323 SI != SE; ++SI) {
324 for (BasicBlock::succ_const_iterator SI = BB->succ_begin(),
325 SE = BB->succ_end(); SI != SE; ++SI) {
324326 // Does Node immediately dominate this successor?
325327 if (DT[*SI]->getIDom() != Node)
326328 S.insert(*SI);
353355 DomSetType &S = Frontiers[BB]; // The new set to fill in...
354356 if (!Root) return S;
355357
356 for (pred_const_iterator SI = pred_begin(BB), SE = pred_end(BB);
357 SI != SE; ++SI) {
358 for (BasicBlock::pred_const_iterator SI = BB->pred_begin(),
359 SE = BB->pred_end(); SI != SE; ++SI) {
358360 // Does Node immediately dominate this predeccessor?
359361 if (DT[*SI]->getIDom() != Node)
360362 S.insert(*SI);
161161 // whose POId is lower
162162
163163
164 cfg::pred_const_iterator PredBBI = cfg::pred_begin(BaseBB);
165
166 for( ; PredBBI != cfg::pred_end(BaseBB) ; PredBBI++) {
164 BasicBlock::pred_const_iterator PredBBI = BaseBB->pred_begin();
165
166 for( ; PredBBI != BaseBB->pred_end() ; PredBBI++) {
167167 assert( *PredBBI ); // assert that the predecessor is valid
168168 BBLiveVar *PredLVBB = LVMap[*PredBBI];
169169
None /* Title: BBLiveVar.h
0 /* Title: BBLiveVar.h -*- C++ -*-
11 Author: Ruchira Sasanka
22 Date: Jun 30, 01
33 Purpose: This is a wrapper class for BasicBlock which is used by live
1212
1313 #include "llvm/BasicBlock.h"
1414 #include "llvm/Instruction.h"
15 #include "llvm/CFG.h"
1615 #include "llvm/Type.h"
1716 #include "llvm/iOther.h"
1817
263263 }
264264
265265 // Recursively traverse successors of this basic block.
266 cfg::succ_iterator SI = cfg::succ_begin(BB), SE = cfg::succ_end(BB);
266 BasicBlock::succ_iterator SI = BB->succ_begin(), SE = BB->succ_end();
267267 for (; SI != SE; ++SI) {
268268 BasicBlock *Succ = *SI;
269269 BasicBlock *Repl = fixupCFG(Succ, VisitedBlocks, AliveBlocks);
277277 BasicBlock *ReturnBB = 0; // Default to nothing live down here
278278
279279 // Recursively traverse successors of this basic block.
280 cfg::succ_iterator SI = cfg::succ_begin(BB), SE = cfg::succ_end(BB);
280 BasicBlock::succ_iterator SI = BB->succ_begin(), SE = BB->succ_end();
281281 for (; SI != SE; ++SI) {
282282 BasicBlock *RetBB = fixupCFG(*SI, VisitedBlocks, AliveBlocks);
283283 if (RetBB) {
3030 #include "llvm/iTerminators.h"
3131 #include "llvm/iOther.h"
3232 #include "llvm/Assembly/Writer.h"
33 #include "llvm/CFG.h"
3433 #include
35
36 using namespace cfg;
3734
3835 struct ConstPoolDCE {
3936 enum { EndOffs = 0 };
8178 // things in a basic block, if they are present.
8279 //
8380 static bool RemoveSingularPHIs(BasicBlock *BB) {
84 pred_iterator PI(pred_begin(BB));
85 if (PI == pred_end(BB) || ++PI != pred_end(BB))
81 BasicBlock::pred_iterator PI(BB->pred_begin());
82 if (PI == BB->pred_end() || ++PI != BB->pred_end())
8683 return false; // More than one predecessor...
8784
8885 Instruction *I = BB->front();
8986 if (!I->isPHINode()) return false; // No PHI nodes
9087
9188 //cerr << "Killing PHIs from " << BB;
92 //cerr << "Pred #0 = " << *pred_begin(BB);
89 //cerr << "Pred #0 = " << *BB->pred_begin();
9390
9491 //cerr << "Method == " << BB->getParent();
9592
127124 // If there is more than one predecessor, and there are PHI nodes in
128125 // the successor, then we need to add incoming edges for the PHI nodes
129126 //
130 const vector BBPreds(pred_begin(BB), pred_end(BB));
127 const vector BBPreds(BB->pred_begin(), BB->pred_end());
131128
132129 BasicBlock::iterator I = Succ->begin();
133130 do { // Loop over all of the PHI nodes in the successor BB
165162
166163
167164 // Remove basic blocks that have no predecessors... which are unreachable.
168 if (pred_begin(BB) == pred_end(BB) &&
165 if (BB->pred_begin() == BB->pred_end() &&
169166 !BB->hasConstantPoolReferences()) {
170167 //cerr << "Removing BB: \n" << BB;
171168
172169 // Loop through all of our successors and make sure they know that one
173170 // of their predecessors is going away.
174 for_each(succ_begin(BB), succ_end(BB),
171 for_each(BB->succ_begin(), BB->succ_end(),
175172 std::bind2nd(std::mem_fun(&BasicBlock::removePredecessor), BB));
176173
177174 while (!BB->empty()) {
192189
193190 // Check to see if this block has no instructions and only a single
194191 // successor. If so, replace block references with successor.
195 succ_iterator SI(succ_begin(BB));
196 if (SI != succ_end(BB) && ++SI == succ_end(BB)) { // One succ?
192 BasicBlock::succ_iterator SI(BB->succ_begin());
193 if (SI != BB->succ_end() && ++SI == BB->succ_end()) { // One succ?
197194 Instruction *I = BB->front();
198195 if (I->isTerminator()) { // Terminator is the only instruction!
199 BasicBlock *Succ = *succ_begin(BB); // There is exactly one successor
196 BasicBlock *Succ = *BB->succ_begin(); // There is exactly one successor
200197 //cerr << "Killing Trivial BB: \n" << BB;
201198
202199 if (Succ != BB) { // Arg, don't hurt infinite loops!
222219
223220 // Merge basic blocks into their predecessor if there is only one pred,
224221 // and if there is only one successor of the predecessor.
225 pred_iterator PI(pred_begin(BB));
226 if (PI != pred_end(BB) && *PI != BB && // Not empty? Not same BB?
227 ++PI == pred_end(BB) && !BB->hasConstantPoolReferences()) {
228 BasicBlock *Pred = *pred_begin(BB);
222 BasicBlock::pred_iterator PI(BB->pred_begin());
223 if (PI != BB->pred_end() && *PI != BB && // Not empty? Not same BB?
224 ++PI == BB->pred_end() && !BB->hasConstantPoolReferences()) {
225 BasicBlock *Pred = *BB->pred_begin();
229226 TerminatorInst *Term = Pred->getTerminator();
230227 assert(Term != 0 && "malformed basic block without terminator!");
231228
232229 // Does the predecessor block only have a single successor?
233 succ_iterator SI(succ_begin(Pred));
234 if (++SI == succ_end(Pred)) {
230 BasicBlock::succ_iterator SI(Pred->succ_begin());
231 if (++SI == Pred->succ_end()) {
235232 //cerr << "Merging: " << BB << "into: " << Pred;
236233
237234 // Delete the unconditianal branch from the predecessor...
2525 #include "llvm/Support/STLExtras.h"
2626 #include "llvm/SymbolTable.h"
2727 #include "llvm/iOther.h"
28 #include "llvm/CFG.h"
2928 #include
3029
3130 #include "llvm/Analysis/LoopDepth.h"
198197 // Figure out which predecessors I have to play with... there should be
199198 // exactly two... one of which is a loop predecessor, and one of which is not.
200199 //
201 cfg::pred_iterator PI = cfg::pred_begin(Header);
202 assert(PI != cfg::pred_end(Header) && "Header node should have 2 preds!");
200 BasicBlock::pred_iterator PI = Header->pred_begin();
201 assert(PI != Header->pred_end() && "Header node should have 2 preds!");
203202 BasicBlock *Pred1 = *PI; ++PI;
204 assert(PI != cfg::pred_end(Header) && "Header node should have 2 preds!");
203 assert(PI != Header->pred_end() && "Header node should have 2 preds!");
205204 BasicBlock *Pred2 = *PI;
206 assert(++PI == cfg::pred_end(Header) && "Header node should have 2 preds!");
205 assert(++PI == Header->pred_end() && "Header node should have 2 preds!");
207206
208207 // Make Pred1 be the loop entrance predecessor, Pred2 be the Loop predecessor
209208 if (Int->contains(Pred1)) swap(Pred1, Pred2);
99 #include "llvm/Method.h"
1010 #include "llvm/SymbolTable.h"
1111 #include "llvm/Type.h"
12 #include "llvm/CFG.h"
1312 #include "llvm/iOther.h"
1413 #include "llvm/CodeGen/MachineInstr.h"
1514
9089 // called while the predecessor still refers to this block.
9190 //
9291 void BasicBlock::removePredecessor(BasicBlock *Pred) {
93 using cfg::pred_begin; using cfg::pred_end; using cfg::pred_iterator;
94 assert(find(pred_begin(this), pred_end(this), Pred) != pred_end(this) &&
92 assert(find(pred_begin(), pred_end(), Pred) != pred_end() &&
9593 "removePredecessor: BB is not a predecessor!");
9694 if (!front()->isPHINode()) return; // Quick exit.
9795
98 pred_iterator PI(pred_begin(this)), EI(pred_end(this));
96 pred_iterator PI(pred_begin()), EI(pred_end());
9997 unsigned max_idx;
10098
10199 // Loop over the rest of the predecessors until we run out, or until we find
6262 df_iterator It = df_begin(M), End = df_end(M);
6363 for ( ; It != End; ++It) {
6464 const BasicBlock *BB = *It;
65 pred_const_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
65 BasicBlock::pred_const_iterator PI = BB->pred_begin(),
66 PEnd = BB->pred_end();
6667 if (PI != PEnd) { // Is there SOME predecessor?
6768 // Loop until we get to a predecessor that has had it's dom set filled
6869 // in at least once. We are guaranteed to have this because we are
113114 idf_iterator It = idf_begin(Root), End = idf_end(Root);
114115 for ( ; It != End; ++It) {
115116 const BasicBlock *BB = *It;
116 succ_const_iterator PI = succ_begin(BB), PEnd = succ_end(BB);
117 BasicBlock::succ_const_iterator PI = BB->succ_begin(),
118 PEnd = BB->succ_end();
117119 if (PI != PEnd) { // Is there SOME predecessor?
118120 // Loop until we get to a successor that has had it's dom set filled
119121 // in at least once. We are guaranteed to have this because we are
319321 const BasicBlock *BB = Node->getNode();
320322 DomSetType &S = Frontiers[BB]; // The new set to fill in...
321323
322 for (succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB);
323 SI != SE; ++SI) {
324 for (BasicBlock::succ_const_iterator SI = BB->succ_begin(),
325 SE = BB->succ_end(); SI != SE; ++SI) {
324326 // Does Node immediately dominate this successor?
325327 if (DT[*SI]->getIDom() != Node)
326328 S.insert(*SI);
353355 DomSetType &S = Frontiers[BB]; // The new set to fill in...
354356 if (!Root) return S;
355357
356 for (pred_const_iterator SI = pred_begin(BB), SE = pred_end(BB);
357 SI != SE; ++SI) {
358 for (BasicBlock::pred_const_iterator SI = BB->pred_begin(),
359 SE = BB->pred_end(); SI != SE; ++SI) {
358360 // Does Node immediately dominate this predeccessor?
359361 if (DT[*SI]->getIDom() != Node)
360362 S.insert(*SI);