llvm.org GIT mirror llvm / 455889a
* Pull BasicBlock::pred_* and BasicBlock::succ_* out of BasicBlock.h and into llvm/Support/CFG.h * Make pred & succ iterators for intervals global functions * Add #includes that are now neccesary because BasicBlock.h doesn't include InstrTypes.h anymore git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1750 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 18 years ago
21 changed file(s) with 99 addition(s) and 99 deletion(s). Raw diff Collapse all Expand all
1010 #include "llvm/DerivedTypes.h"
1111 #include "llvm/Module.h"
1212 #include "llvm/Method.h"
13 #include "llvm/Instruction.h"
1314 #include "llvm/Support/InstIterator.h"
1415
1516 AnalysisID FindUsedTypes::ID(AnalysisID::create());
66
77 #include "llvm/Analysis/Interval.h"
88 #include "llvm/BasicBlock.h"
9 #include "llvm/Support/CFG.h"
910
1011 //===----------------------------------------------------------------------===//
1112 // Interval Implementation
1617 bool cfg::Interval::isLoop() const {
1718 // There is a loop in this interval iff one of the predecessors of the header
1819 // node lives in the interval.
19 for (BasicBlock::pred_iterator I = HeaderNode->pred_begin(),
20 E = HeaderNode->pred_end(); I != E; ++I) {
20 for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
21 I != E; ++I) {
2122 if (contains(*I)) return true;
2223 }
2324 return false;
77 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
88 #include "llvm/CodeGen/MachineInstr.h"
99 #include "llvm/BasicBlock.h"
10 #include "llvm/Support/CFG.h"
1011 #include "Support/SetOperations.h"
1112
1213 /// BROKEN: Should not include sparc stuff directly into here
196197 //
197198 bool needAnotherIt = false;
198199
199 for (BasicBlock::pred_const_iterator PI = BB->pred_begin(),
200 PE = BB->pred_begin(); PI != PE ; ++PI) {
200 for (pred_const_iterator PI = pred_begin(BB), PE = pred_begin(BB);
201 PI != PE ; ++PI) {
201202 BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(*PI);
202203
203204 // do set union
6060
6161 // Scan the predecessors of BB, checking to see if BB dominates any of
6262 // them.
63 for (BasicBlock::pred_const_iterator I = BB->pred_begin(),
64 E = BB->pred_end(); I != E; ++I)
63 for (pred_const_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I)
6564 if (DS.dominates(BB, *I)) // If BB dominates it's predecessor...
6665 TodoStack.push_back(*I);
6766
7978 L->Blocks.push_back(X);
8079
8180 // Add all of the predecessors of X to the end of the work stack...
82 TodoStack.insert(TodoStack.end(), X->pred_begin(), X->pred_end());
81 TodoStack.insert(TodoStack.end(), pred_begin(X), pred_end(X));
8382 }
8483 }
8584
3636 //
3737 void cfg::DominatorSet::calcForwardDominatorSet(Method *M) {
3838 Root = M->getEntryNode();
39 assert(Root->pred_begin() == Root->pred_end() &&
39 assert(pred_begin(Root) == pred_end(Root) &&
4040 "Root node has predecessors in method!");
4141
4242 bool Changed;
4747 df_iterator It = df_begin(M), End = df_end(M);
4848 for ( ; It != End; ++It) {
4949 const BasicBlock *BB = *It;
50 BasicBlock::pred_const_iterator PI = BB->pred_begin(),
51 PEnd = BB->pred_end();
50 pred_const_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
5251 if (PI != PEnd) { // Is there SOME predecessor?
5352 // Loop until we get to a predecessor that has had it's dom set filled
5453 // in at least once. We are guaranteed to have this because we are
101100 idf_iterator It = idf_begin(Root), End = idf_end(Root);
102101 for ( ; It != End; ++It) {
103102 const BasicBlock *BB = *It;
104 BasicBlock::succ_const_iterator PI = BB->succ_begin(),
105 PEnd = BB->succ_end();
103 succ_const_iterator PI = succ_begin(BB), PEnd = succ_end(BB);
106104 if (PI != PEnd) { // Is there SOME predecessor?
107105 // Loop until we get to a successor that has had it's dom set filled
108106 // in at least once. We are guaranteed to have this because we are
336334 const BasicBlock *BB = Node->getNode();
337335 DomSetType &S = Frontiers[BB]; // The new set to fill in...
338336
339 for (BasicBlock::succ_const_iterator SI = BB->succ_begin(),
340 SE = BB->succ_end(); SI != SE; ++SI) {
337 for (succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB);
338 SI != SE; ++SI) {
341339 // Does Node immediately dominate this successor?
342340 if (DT[*SI]->getIDom() != Node)
343341 S.insert(*SI);
370368 DomSetType &S = Frontiers[BB]; // The new set to fill in...
371369 if (!Root) return S;
372370
373 for (BasicBlock::pred_const_iterator SI = BB->pred_begin(),
374 SE = BB->pred_end(); SI != SE; ++SI) {
371 for (pred_const_iterator SI = pred_begin(BB), SE = pred_end(BB);
372 SI != SE; ++SI) {
375373 // Does Node immediately dominate this predeccessor?
376374 if (DT[*SI]->getIDom() != Node)
377375 S.insert(*SI);
1616 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" // FIXME: Remove when AnalysisUsage sets can be symbolic!
1717 #include "llvm/Target/TargetMachine.h"
1818 #include "llvm/BasicBlock.h"
19 #include "llvm/Instruction.h"
1920 #include "SchedPriorities.h"
2021 #include
2122 #include
12861287 SchedGraph *graph)
12871288 {
12881289 const MachineInstrInfo& mii = S.getInstrInfo();
1289 const TerminatorInst *termInstr = bb->getTerminator();
1290 const Instruction *termInstr = (Instruction*)bb->getTerminator();
12901291 MachineCodeForInstruction &termMvec=MachineCodeForInstruction::get(termInstr);
12911292 vector delayNodeVec;
12921293 const MachineInstr* brInstr = NULL;
1293
1294 assert(termInstr->getOpcode() != Instruction::Call
1295 && "Call used as terminator?");
12961294
12971295 if (termInstr->getOpcode() != Instruction::Ret)
12981296 {
390390 // for .
391391 //
392392 template
393 class PredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
393 class SGPredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
394394 protected:
395395 _EdgeIter oi;
396396 public:
397 typedef PredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
398
399 inline PredIterator(_EdgeIter startEdge) : oi(startEdge) {}
397 typedef SGPredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
398
399 inline SGPredIterator(_EdgeIter startEdge) : oi(startEdge) {}
400400
401401 inline bool operator==(const _Self& x) const { return oi == x.oi; }
402402 inline bool operator!=(const _Self& x) const { return !operator==(x); }
419419 };
420420
421421 template
422 class SuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
422 class SGSuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
423423 protected:
424424 _EdgeIter oi;
425425 public:
426 typedef SuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
427
428 inline SuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
426 typedef SGSuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
427
428 inline SGSuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
429429
430430 inline bool operator==(const _Self& x) const { return oi == x.oi; }
431431 inline bool operator!=(const _Self& x) const { return !operator==(x); }
450450 // sg_pred_iterator
451451 // sg_pred_const_iterator
452452 //
453 typedef PredIterator
453 typedef SGPredIterator
454454 sg_pred_iterator;
455 typedef PredIterator
455 typedef SGPredIterator
456456 sg_pred_const_iterator;
457457
458458 inline sg_pred_iterator pred_begin( SchedGraphNode *N) {
473473 // sg_succ_iterator
474474 // sg_succ_const_iterator
475475 //
476 typedef SuccIterator
476 typedef SGSuccIterator
477477 sg_succ_iterator;
478 typedef SuccIterator
478 typedef SGSuccIterator
479479 sg_succ_const_iterator;
480480
481481 inline sg_succ_iterator succ_begin( SchedGraphNode *N) {
158158
159159 void InsertPhiElimInst(BasicBlock *BB, MachineInstr *CpMI) {
160160
161 TerminatorInst *TermInst = BB->getTerminator();
161 Instruction *TermInst = (Instruction*)BB->getTerminator();
162162 MachineCodeForInstruction &MC4Term = MachineCodeForInstruction::get(TermInst);
163163 MachineInstr *FirstMIOfTerm = *( MC4Term.begin() );
164164
1616 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" // FIXME: Remove when AnalysisUsage sets can be symbolic!
1717 #include "llvm/Target/TargetMachine.h"
1818 #include "llvm/BasicBlock.h"
19 #include "llvm/Instruction.h"
1920 #include "SchedPriorities.h"
2021 #include
2122 #include
12861287 SchedGraph *graph)
12871288 {
12881289 const MachineInstrInfo& mii = S.getInstrInfo();
1289 const TerminatorInst *termInstr = bb->getTerminator();
1290 const Instruction *termInstr = (Instruction*)bb->getTerminator();
12901291 MachineCodeForInstruction &termMvec=MachineCodeForInstruction::get(termInstr);
12911292 vector delayNodeVec;
12921293 const MachineInstr* brInstr = NULL;
1293
1294 assert(termInstr->getOpcode() != Instruction::Call
1295 && "Call used as terminator?");
12961294
12971295 if (termInstr->getOpcode() != Instruction::Ret)
12981296 {
390390 // for .
391391 //
392392 template
393 class PredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
393 class SGPredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
394394 protected:
395395 _EdgeIter oi;
396396 public:
397 typedef PredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
398
399 inline PredIterator(_EdgeIter startEdge) : oi(startEdge) {}
397 typedef SGPredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
398
399 inline SGPredIterator(_EdgeIter startEdge) : oi(startEdge) {}
400400
401401 inline bool operator==(const _Self& x) const { return oi == x.oi; }
402402 inline bool operator!=(const _Self& x) const { return !operator==(x); }
419419 };
420420
421421 template
422 class SuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
422 class SGSuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
423423 protected:
424424 _EdgeIter oi;
425425 public:
426 typedef SuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
427
428 inline SuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
426 typedef SGSuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
427
428 inline SGSuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
429429
430430 inline bool operator==(const _Self& x) const { return oi == x.oi; }
431431 inline bool operator!=(const _Self& x) const { return !operator==(x); }
450450 // sg_pred_iterator
451451 // sg_pred_const_iterator
452452 //
453 typedef PredIterator
453 typedef SGPredIterator
454454 sg_pred_iterator;
455 typedef PredIterator
455 typedef SGPredIterator
456456 sg_pred_const_iterator;
457457
458458 inline sg_pred_iterator pred_begin( SchedGraphNode *N) {
473473 // sg_succ_iterator
474474 // sg_succ_const_iterator
475475 //
476 typedef SuccIterator
476 typedef SGSuccIterator
477477 sg_succ_iterator;
478 typedef SuccIterator
478 typedef SGSuccIterator
479479 sg_succ_const_iterator;
480480
481481 inline sg_succ_iterator succ_begin( SchedGraphNode *N) {
158158
159159 void InsertPhiElimInst(BasicBlock *BB, MachineInstr *CpMI) {
160160
161 TerminatorInst *TermInst = BB->getTerminator();
161 Instruction *TermInst = (Instruction*)BB->getTerminator();
162162 MachineCodeForInstruction &MC4Term = MachineCodeForInstruction::get(TermInst);
163163 MachineInstr *FirstMIOfTerm = *( MC4Term.begin() );
164164
77 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
88 #include "llvm/CodeGen/MachineInstr.h"
99 #include "llvm/BasicBlock.h"
10 #include "llvm/Support/CFG.h"
1011 #include "Support/SetOperations.h"
1112
1213 /// BROKEN: Should not include sparc stuff directly into here
196197 //
197198 bool needAnotherIt = false;
198199
199 for (BasicBlock::pred_const_iterator PI = BB->pred_begin(),
200 PE = BB->pred_begin(); PI != PE ; ++PI) {
200 for (pred_const_iterator PI = pred_begin(BB), PE = pred_begin(BB);
201 PI != PE ; ++PI) {
201202 BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(*PI);
202203
203204 // do set union
8383
8484 void InsertPrologEpilogCode::InsertEpilogCode(Method* method)
8585 {
86 for (Method::iterator I=method->begin(), E=method->end(); I != E; ++I)
87 if ((*I)->getTerminator()->getOpcode() == Instruction::Ret)
86 for (Method::iterator I=method->begin(), E=method->end(); I != E; ++I) {
87 Instruction *TermInst = (Instruction*)(*I)->getTerminator();
88 if (TermInst->getOpcode() == Instruction::Ret)
8889 {
8990 BasicBlock* exitBB = *I;
9091 unsigned N = GetInstructionsForEpilog(exitBB, Target, minstrVec);
9192
9293 MachineCodeForBasicBlock& bbMvec = exitBB->getMachineInstrVec();
9394 MachineCodeForInstruction &termMvec =
94 MachineCodeForInstruction::get(exitBB->getTerminator());
95 MachineCodeForInstruction::get(TermInst);
9596
9697 // Remove the NOPs in the delay slots of the return instruction
9798 const MachineInstrInfo &mii = Target.getInstrInfo();
114115 // Append the epilog code to the end of the basic block.
115116 bbMvec.push_back(minstrVec[0]);
116117 }
118 }
117119 }
118120
119121
2121 #include "llvm/iMemory.h"
2222 #include "llvm/iTerminators.h"
2323 #include "llvm/iOther.h"
24 #include "llvm/Support/CFG.h"
2425 #include
2526 #include
2627 using std::vector;
354355 //
355356 static inline void RefactorPredecessor(BasicBlock *BB, BasicBlock *Pred) {
356357 Method *M = BB->getParent();
357 assert(find(BB->pred_begin(), BB->pred_end(), Pred) != BB->pred_end() &&
358 assert(find(pred_begin(BB), pred_end(BB), Pred) != pred_end(BB) &&
358359 "Pred is not a predecessor of BB!");
359360
360361 // Create a new basic block, adding it to the end of the method.
447448 Changed |= FixCastsAndPHIs(BB);
448449
449450 if (isa(BB->front())) {
450 const vector Preds(BB->pred_begin(), BB->pred_end());
451 const vector Preds(pred_begin(BB), pred_end(BB));
451452
452453 // Handle Problem #1. Sort the list of predecessors so that it is easy to
453454 // decide whether or not duplicate predecessors exist.
263263 }
264264
265265 // Recursively traverse successors of this basic block.
266 BasicBlock::succ_iterator SI = BB->succ_begin(), SE = BB->succ_end();
267 for (; SI != SE; ++SI) {
266 for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) {
268267 BasicBlock *Succ = *SI;
269268 BasicBlock *Repl = fixupCFG(Succ, VisitedBlocks, AliveBlocks);
270269 if (Repl && Repl != Succ) { // We have to replace the successor
277276 BasicBlock *ReturnBB = 0; // Default to nothing live down here
278277
279278 // Recursively traverse successors of this basic block.
280 BasicBlock::succ_iterator SI = BB->succ_begin(), SE = BB->succ_end();
281 for (; SI != SE; ++SI) {
279 for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) {
282280 BasicBlock *RetBB = fixupCFG(*SI, VisitedBlocks, AliveBlocks);
283281 if (RetBB) {
284282 assert(ReturnBB == 0 && "One one live child allowed!");
3030 #include "llvm/iTerminators.h"
3131 #include "llvm/iPHINode.h"
3232 #include "llvm/Assembly/Writer.h"
33 #include "llvm/Support/CFG.h"
3334 #include "Support/STLExtras.h"
3435 #include
3536
7273 // things in a basic block, if they are present.
7374 //
7475 static bool RemoveSingularPHIs(BasicBlock *BB) {
75 BasicBlock::pred_iterator PI(BB->pred_begin());
76 if (PI == BB->pred_end() || ++PI != BB->pred_end())
76 pred_iterator PI(pred_begin(BB));
77 if (PI == pred_end(BB) || ++PI != pred_end(BB))
7778 return false; // More than one predecessor...
7879
7980 Instruction *I = BB->front();
8081 if (!isa(I)) return false; // No PHI nodes
8182
8283 //cerr << "Killing PHIs from " << BB;
83 //cerr << "Pred #0 = " << *BB->pred_begin();
84 //cerr << "Pred #0 = " << *pred_begin(BB);
8485
8586 //cerr << "Method == " << BB->getParent();
8687
114115 // Assumption: Succ is the single successor for BB.
115116 //
116117 static bool PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
117 assert(*BB->succ_begin() == Succ && "Succ is not successor of BB!");
118 assert(*succ_begin(BB) == Succ && "Succ is not successor of BB!");
118119 assert(isa(Succ->front()) && "Only works on PHId BBs!");
119120
120121 // If there is more than one predecessor, and there are PHI nodes in
121122 // the successor, then we need to add incoming edges for the PHI nodes
122123 //
123 const std::vector BBPreds(BB->pred_begin(), BB->pred_end());
124 const std::vector BBPreds(pred_begin(BB), pred_end(BB));
124125
125126 // Check to see if one of the predecessors of BB is already a predecessor of
126127 // Succ. If so, we cannot do the transformation!
127128 //
128 for (BasicBlock::pred_iterator PI = Succ->pred_begin(), PE = Succ->pred_end();
129 PI != PE; ++PI) {
129 for (pred_iterator PI = pred_begin(Succ), PE = pred_end(Succ);
130 PI != PE; ++PI) {
130131 if (find(BBPreds.begin(), BBPreds.end(), *PI) != BBPreds.end())
131132 return true;
132133 }
168169
169170
170171 // Remove basic blocks that have no predecessors... which are unreachable.
171 if (BB->pred_begin() == BB->pred_end() &&
172 if (pred_begin(BB) == pred_end(BB) &&
172173 !BB->hasConstantReferences()) {
173174 //cerr << "Removing BB: \n" << BB;
174175
175176 // Loop through all of our successors and make sure they know that one
176177 // of their predecessors is going away.
177 for_each(BB->succ_begin(), BB->succ_end(),
178 for_each(succ_begin(BB), succ_end(BB),
178179 std::bind2nd(std::mem_fun(&BasicBlock::removePredecessor), BB));
179180
180181 while (!BB->empty()) {
195196
196197 // Check to see if this block has no instructions and only a single
197198 // successor. If so, replace block references with successor.
198 BasicBlock::succ_iterator SI(BB->succ_begin());
199 if (SI != BB->succ_end() && ++SI == BB->succ_end()) { // One succ?
199 succ_iterator SI(succ_begin(BB));
200 if (SI != succ_end(BB) && ++SI == succ_end(BB)) { // One succ?
200201 if (BB->front()->isTerminator()) { // Terminator is the only instruction!
201 BasicBlock *Succ = *BB->succ_begin(); // There is exactly one successor
202 BasicBlock *Succ = *succ_begin(BB); // There is exactly one successor
202203 //cerr << "Killing Trivial BB: \n" << BB;
203204
204205 if (Succ != BB) { // Arg, don't hurt infinite loops!
226227
227228 // Merge basic blocks into their predecessor if there is only one pred,
228229 // and if there is only one successor of the predecessor.
229 BasicBlock::pred_iterator PI(BB->pred_begin());
230 if (PI != BB->pred_end() && *PI != BB && // Not empty? Not same BB?
231 ++PI == BB->pred_end() && !BB->hasConstantReferences()) {
232 BasicBlock *Pred = *BB->pred_begin();
230 pred_iterator PI(pred_begin(BB));
231 if (PI != pred_end(BB) && *PI != BB && // Not empty? Not same BB?
232 ++PI == pred_end(BB) && !BB->hasConstantReferences()) {
233 BasicBlock *Pred = *pred_begin(BB);
233234 TerminatorInst *Term = Pred->getTerminator();
234235 assert(Term != 0 && "malformed basic block without terminator!");
235236
236237 // Does the predecessor block only have a single successor?
237 BasicBlock::succ_iterator SI(Pred->succ_begin());
238 if (++SI == Pred->succ_end()) {
238 succ_iterator SI(succ_begin(Pred));
239 if (++SI == succ_end(Pred)) {
239240 //cerr << "Merging: " << BB << "into: " << Pred;
240241
241242 // Delete the unconditianal branch from the predecessor...
1212 #include "llvm/Type.h"
1313 #include "llvm/BasicBlock.h"
1414 #include "llvm/ConstantVals.h"
15 #include "llvm/Support/CFG.h"
1516 #include "Support/STLExtras.h"
1617
1718 #if 0
8687
8788 // Figure out which block is incoming and which is the backedge for the loop
8889 BasicBlock *Incoming, *BackEdgeBlock;
89 BasicBlock::pred_iterator PI = Header->pred_begin();
90 assert(PI != Header->pred_end() && "Loop headers should have 2 preds!");
90 pred_iterator PI = pred_begin(Header);
91 assert(PI != pred_end(Header) && "Loop headers should have 2 preds!");
9192 if (Loop->contains(*PI)) { // First pred is back edge...
9293 BackEdgeBlock = *PI++;
9394 Incoming = *PI++;
9596 Incoming = *PI++;
9697 BackEdgeBlock = *PI++;
9798 }
98 assert(PI == Header->pred_end() && "Loop headers should have 2 preds!");
99 assert(PI == pred_end(Header) && "Loop headers should have 2 preds!");
99100
100101 // Add incoming values for the PHI node...
101102 PN->addIncoming(Constant::getNullConstant(Type::UIntTy), Incoming);
2626 #include "llvm/iPHINode.h"
2727 #include "llvm/Method.h"
2828 #include "llvm/BasicBlock.h"
29 #include "llvm/InstrTypes.h"
30 #include "llvm/Support/CFG.h"
2931 #include "Support/STLExtras.h"
3032 #include
3133 #include
196198 // Figure out which predecessors I have to play with... there should be
197199 // exactly two... one of which is a loop predecessor, and one of which is not.
198200 //
199 BasicBlock::pred_iterator PI = Header->pred_begin();
200 assert(PI != Header->pred_end() && "Header node should have 2 preds!");
201 pred_iterator PI = pred_begin(Header);
202 assert(PI != pred_end(Header) && "Header node should have 2 preds!");
201203 BasicBlock *Pred1 = *PI; ++PI;
202 assert(PI != Header->pred_end() && "Header node should have 2 preds!");
204 assert(PI != pred_end(Header) && "Header node should have 2 preds!");
203205 BasicBlock *Pred2 = *PI;
204 assert(++PI == Header->pred_end() && "Header node should have 2 preds!");
206 assert(++PI == pred_end(Header) && "Header node should have 2 preds!");
205207
206208 // Make Pred1 be the loop entrance predecessor, Pred2 be the Loop predecessor
207209 if (Int->contains(Pred1)) std::swap(Pred1, Pred2);
1717 #include "llvm/Transforms/Scalar/ConstantHandling.h"
1818 #include "llvm/Method.h"
1919 #include "llvm/iMemory.h"
20 #include "llvm/InstrTypes.h"
2021 #include "llvm/Support/InstIterator.h"
2122 #include "../TransformInternals.h"
2223
44 //===----------------------------------------------------------------------===//
55
66 #include "llvm/ValueHolderImpl.h"
7 #include "llvm/BasicBlock.h"
87 #include "llvm/iTerminators.h"
9 #include "llvm/Method.h"
108 #include "llvm/SymbolTable.h"
119 #include "llvm/Type.h"
10 #include "llvm/Support/CFG.h"
1211 #include "llvm/iPHINode.h"
1312 #include "llvm/CodeGen/MachineInstr.h"
1413
8988 // called while the predecessor still refers to this block.
9089 //
9190 void BasicBlock::removePredecessor(BasicBlock *Pred) {
92 assert(find(pred_begin(), pred_end(), Pred) != pred_end() &&
91 assert(find(pred_begin(this), pred_end(this), Pred) != pred_end(this) &&
9392 "removePredecessor: BB is not a predecessor!");
9493 if (!isa(front())) return; // Quick exit.
9594
96 pred_iterator PI(pred_begin()), EI(pred_end());
95 pred_iterator PI(pred_begin(this)), EI(pred_end(this));
9796 unsigned max_idx;
9897
9998 // Loop over the rest of the predecessors until we run out, or until we find
3636 //
3737 void cfg::DominatorSet::calcForwardDominatorSet(Method *M) {
3838 Root = M->getEntryNode();
39 assert(Root->pred_begin() == Root->pred_end() &&
39 assert(pred_begin(Root) == pred_end(Root) &&
4040 "Root node has predecessors in method!");
4141
4242 bool Changed;
4747 df_iterator It = df_begin(M), End = df_end(M);
4848 for ( ; It != End; ++It) {
4949 const BasicBlock *BB = *It;
50 BasicBlock::pred_const_iterator PI = BB->pred_begin(),
51 PEnd = BB->pred_end();
50 pred_const_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
5251 if (PI != PEnd) { // Is there SOME predecessor?
5352 // Loop until we get to a predecessor that has had it's dom set filled
5453 // in at least once. We are guaranteed to have this because we are
101100 idf_iterator It = idf_begin(Root), End = idf_end(Root);
102101 for ( ; It != End; ++It) {
103102 const BasicBlock *BB = *It;
104 BasicBlock::succ_const_iterator PI = BB->succ_begin(),
105 PEnd = BB->succ_end();
103 succ_const_iterator PI = succ_begin(BB), PEnd = succ_end(BB);
106104 if (PI != PEnd) { // Is there SOME predecessor?
107105 // Loop until we get to a successor that has had it's dom set filled
108106 // in at least once. We are guaranteed to have this because we are
336334 const BasicBlock *BB = Node->getNode();
337335 DomSetType &S = Frontiers[BB]; // The new set to fill in...
338336
339 for (BasicBlock::succ_const_iterator SI = BB->succ_begin(),
340 SE = BB->succ_end(); SI != SE; ++SI) {
337 for (succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB);
338 SI != SE; ++SI) {
341339 // Does Node immediately dominate this successor?
342340 if (DT[*SI]->getIDom() != Node)
343341 S.insert(*SI);
370368 DomSetType &S = Frontiers[BB]; // The new set to fill in...
371369 if (!Root) return S;
372370
373 for (BasicBlock::pred_const_iterator SI = BB->pred_begin(),
374 SE = BB->pred_end(); SI != SE; ++SI) {
371 for (pred_const_iterator SI = pred_begin(BB), SE = pred_end(BB);
372 SI != SE; ++SI) {
375373 // Does Node immediately dominate this predeccessor?
376374 if (DT[*SI]->getIDom() != Node)
377375 S.insert(*SI);