* Pull BasicBlock::pred_* and BasicBlock::succ_* out of BasicBlock.h and into
authorChris Lattner <sabre@nondot.org>
Tue, 12 Feb 2002 22:39:50 +0000 (22:39 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 12 Feb 2002 22:39:50 +0000 (22:39 +0000)
  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

21 files changed:
lib/Analysis/IPA/FindUsedTypes.cpp
lib/Analysis/Interval.cpp
lib/Analysis/LiveVar/BBLiveVar.cpp
lib/Analysis/LoopInfo.cpp
lib/Analysis/PostDominators.cpp
lib/CodeGen/InstrSched/InstrScheduling.cpp
lib/CodeGen/InstrSched/SchedGraph.h
lib/CodeGen/InstrSelection/InstrSelection.cpp
lib/Target/SparcV9/InstrSched/InstrScheduling.cpp
lib/Target/SparcV9/InstrSched/SchedGraph.h
lib/Target/SparcV9/InstrSelection/InstrSelection.cpp
lib/Target/SparcV9/LiveVar/BBLiveVar.cpp
lib/Target/SparcV9/SparcV9TargetMachine.cpp
lib/Transforms/IPO/DeadTypeElimination.cpp
lib/Transforms/Scalar/ADCE.cpp
lib/Transforms/Scalar/DCE.cpp
lib/Transforms/Scalar/IndVarSimplify.cpp
lib/Transforms/Scalar/InductionVars.cpp
lib/Transforms/Scalar/InstructionCombining.cpp
lib/VMCore/BasicBlock.cpp
lib/VMCore/Dominators.cpp

index e02429ab9771db479eb2c5718427f03cc246b3cc..e67fe322f713856cdc9826afd0937057525ac7e0 100644 (file)
@@ -11,6 +11,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/Method.h"
+#include "llvm/Instruction.h"
 #include "llvm/Support/InstIterator.h"
 
 AnalysisID FindUsedTypes::ID(AnalysisID::create<FindUsedTypes>());
index 5c68be9c2e2207365d804bf0ab77050a8a0f86ea..de5d57f85e7deae144d78e0b04b609fa4eb1dd45 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "llvm/Analysis/Interval.h"
 #include "llvm/BasicBlock.h"
+#include "llvm/Support/CFG.h"
 
 //===----------------------------------------------------------------------===//
 // Interval Implementation
@@ -17,8 +18,8 @@
 bool cfg::Interval::isLoop() const {
   // There is a loop in this interval iff one of the predecessors of the header
   // node lives in the interval.
-  for (BasicBlock::pred_iterator I = HeaderNode->pred_begin(), 
-                                 E = HeaderNode->pred_end(); I != E; ++I) {
+  for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
+       I != E; ++I) {
     if (contains(*I)) return true;
   }
   return false;
index 84adecda6d0833c9bbc246ef6d6e30f89714435a..1468301dfcef3720188fd3d35e4c7e4387abd4a2 100644 (file)
@@ -8,6 +8,7 @@
 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/BasicBlock.h"
+#include "llvm/Support/CFG.h"
 #include "Support/SetOperations.h"
 
 /// BROKEN: Should not include sparc stuff directly into here
@@ -197,8 +198,8 @@ bool BBLiveVar::applyFlowFunc() {
   //
   bool needAnotherIt = false;  
 
-  for (BasicBlock::pred_const_iterator PI = BB->pred_begin(),
-         PE = BB->pred_begin(); PI != PE ; ++PI) {
+  for (pred_const_iterator PI = pred_begin(BB), PE = pred_begin(BB);
+       PI != PE ; ++PI) {
     BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(*PI);
 
     // do set union
index 876161d34fc9199555a353ee2a4ef25ab59adf65..344e3a446bfbee2803ede27cbc10f6443418e109 100644 (file)
@@ -61,8 +61,7 @@ cfg::Loop *cfg::LoopInfo::ConsiderForLoop(const BasicBlock *BB,
 
   // Scan the predecessors of BB, checking to see if BB dominates any of
   // them.
-  for (BasicBlock::pred_const_iterator I = BB->pred_begin(),
-        E = BB->pred_end(); I != E; ++I)
+  for (pred_const_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I)
     if (DS.dominates(BB, *I))   // If BB dominates it's predecessor...
       TodoStack.push_back(*I);
 
@@ -80,7 +79,7 @@ cfg::Loop *cfg::LoopInfo::ConsiderForLoop(const BasicBlock *BB,
       L->Blocks.push_back(X);
 
       // Add all of the predecessors of X to the end of the work stack...
-      TodoStack.insert(TodoStack.end(), X->pred_begin(), X->pred_end());
+      TodoStack.insert(TodoStack.end(), pred_begin(X), pred_end(X));
     }
   }
 
index 33e14e9fc583e1058af861de42e4a689cad465b2..48cc86fcaf542dc3612e1f1d6046112ad84ce7a2 100644 (file)
@@ -37,7 +37,7 @@ bool cfg::DominatorSet::runOnMethod(Method *M) {
 //
 void cfg::DominatorSet::calcForwardDominatorSet(Method *M) {
   Root = M->getEntryNode();
-  assert(Root->pred_begin() == Root->pred_end() &&
+  assert(pred_begin(Root) == pred_end(Root) &&
         "Root node has predecessors in method!");
 
   bool Changed;
@@ -48,8 +48,7 @@ void cfg::DominatorSet::calcForwardDominatorSet(Method *M) {
     df_iterator<Method*> It = df_begin(M), End = df_end(M);
     for ( ; It != End; ++It) {
       const BasicBlock *BB = *It;
-      BasicBlock::pred_const_iterator PI = BB->pred_begin(),
-                                      PEnd = BB->pred_end();
+      pred_const_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
       if (PI != PEnd) {                // Is there SOME predecessor?
        // Loop until we get to a predecessor that has had it's dom set filled
        // in at least once.  We are guaranteed to have this because we are
@@ -102,8 +101,7 @@ void cfg::DominatorSet::calcPostDominatorSet(Method *M) {
     idf_iterator<BasicBlock*> It = idf_begin(Root), End = idf_end(Root);
     for ( ; It != End; ++It) {
       const BasicBlock *BB = *It;
-      BasicBlock::succ_const_iterator PI = BB->succ_begin(),
-                                      PEnd = BB->succ_end();
+      succ_const_iterator PI = succ_begin(BB), PEnd = succ_end(BB);
       if (PI != PEnd) {                // Is there SOME predecessor?
        // Loop until we get to a successor that has had it's dom set filled
        // in at least once.  We are guaranteed to have this because we are
@@ -337,8 +335,8 @@ cfg::DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
   const BasicBlock *BB = Node->getNode();
   DomSetType &S = Frontiers[BB];       // The new set to fill in...
 
-  for (BasicBlock::succ_const_iterator SI = BB->succ_begin(),
-                                       SE = BB->succ_end(); SI != SE; ++SI) {
+  for (succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB);
+       SI != SE; ++SI) {
     // Does Node immediately dominate this successor?
     if (DT[*SI]->getIDom() != Node)
       S.insert(*SI);
@@ -371,8 +369,8 @@ cfg::DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT,
   DomSetType &S = Frontiers[BB];       // The new set to fill in...
   if (!Root) return S;
 
-  for (BasicBlock::pred_const_iterator SI = BB->pred_begin(),
-                                       SE = BB->pred_end(); SI != SE; ++SI) {
+  for (pred_const_iterator SI = pred_begin(BB), SE = pred_end(BB);
+       SI != SE; ++SI) {
     // Does Node immediately dominate this predeccessor?
     if (DT[*SI]->getIDom() != Node)
       S.insert(*SI);
index 6e6d14c7c892e1ec94653b13bd6a0712c6fc492d..edf84d4cadc9c7a344639a20ce71c5d23dd02d51 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" // FIXME: Remove when AnalysisUsage sets can be symbolic!
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/BasicBlock.h"
+#include "llvm/Instruction.h"
 #include "SchedPriorities.h"
 #include <ext/hash_set>
 #include <algorithm>
@@ -1287,14 +1288,11 @@ ChooseInstructionsForDelaySlots(SchedulingManager& S,
                                SchedGraph *graph)
 {
   const MachineInstrInfo& mii = S.getInstrInfo();
-  const TerminatorInst *termInstr = bb->getTerminator();
+  const Instruction *termInstr = (Instruction*)bb->getTerminator();
   MachineCodeForInstruction &termMvec=MachineCodeForInstruction::get(termInstr);
   vector<SchedGraphNode*> delayNodeVec;
   const MachineInstr* brInstr = NULL;
   
-  assert(termInstr->getOpcode() != Instruction::Call
-         && "Call used as terminator?");
-  
   if (termInstr->getOpcode() != Instruction::Ret)
     {
       // To find instructions that need delay slots without searching the full
index 80355e498606b5fc87947efda3e6bb7e19035696..fb6087c44d9055bc0c11786e8b3a1cbd80e668be 100644 (file)
@@ -391,13 +391,13 @@ private:
 // for <const SchedGraphNode, SchedGraphNode::const_iterator>.
 // 
 template <class _NodeType, class _EdgeType, class _EdgeIter>
-class PredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
+class SGPredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
 protected:
   _EdgeIter oi;
 public:
-  typedef PredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
+  typedef SGPredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
   
-  inline PredIterator(_EdgeIter startEdge) : oi(startEdge) {}
+  inline SGPredIterator(_EdgeIter startEdge) : oi(startEdge) {}
   
   inline bool operator==(const _Self& x) const { return oi == x.oi; }
   inline bool operator!=(const _Self& x) const { return !operator==(x); }
@@ -420,13 +420,13 @@ public:
 };
 
 template <class _NodeType, class _EdgeType, class _EdgeIter>
-class SuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
+class SGSuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
 protected:
   _EdgeIter oi;
 public:
-  typedef SuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
+  typedef SGSuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
   
-  inline SuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
+  inline SGSuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
   
   inline bool operator==(const _Self& x) const { return oi == x.oi; }
   inline bool operator!=(const _Self& x) const { return !operator==(x); }
@@ -451,9 +451,9 @@ public:
 // sg_pred_iterator
 // sg_pred_const_iterator
 //
-typedef PredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
+typedef SGPredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
     sg_pred_iterator;
-typedef PredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
+typedef SGPredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
     sg_pred_const_iterator;
 
 inline sg_pred_iterator       pred_begin(      SchedGraphNode *N) {
@@ -474,9 +474,9 @@ inline sg_pred_const_iterator pred_end(  const SchedGraphNode *N) {
 // sg_succ_iterator
 // sg_succ_const_iterator
 //
-typedef SuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
+typedef SGSuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
     sg_succ_iterator;
-typedef SuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
+typedef SGSuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
     sg_succ_const_iterator;
 
 inline sg_succ_iterator       succ_begin(      SchedGraphNode *N) {
index cd0ca6645acb0773e5cd19284c43aa256d281c32..af02e57616d4a7565d578073d184b3d0f58a0270 100644 (file)
@@ -159,7 +159,7 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
 
 void InsertPhiElimInst(BasicBlock *BB, MachineInstr *CpMI) { 
 
-  TerminatorInst *TermInst = BB->getTerminator();
+  Instruction *TermInst = (Instruction*)BB->getTerminator();
   MachineCodeForInstruction &MC4Term = MachineCodeForInstruction::get(TermInst);
   MachineInstr *FirstMIOfTerm = *( MC4Term.begin() );
 
index 6e6d14c7c892e1ec94653b13bd6a0712c6fc492d..edf84d4cadc9c7a344639a20ce71c5d23dd02d51 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" // FIXME: Remove when AnalysisUsage sets can be symbolic!
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/BasicBlock.h"
+#include "llvm/Instruction.h"
 #include "SchedPriorities.h"
 #include <ext/hash_set>
 #include <algorithm>
@@ -1287,14 +1288,11 @@ ChooseInstructionsForDelaySlots(SchedulingManager& S,
                                SchedGraph *graph)
 {
   const MachineInstrInfo& mii = S.getInstrInfo();
-  const TerminatorInst *termInstr = bb->getTerminator();
+  const Instruction *termInstr = (Instruction*)bb->getTerminator();
   MachineCodeForInstruction &termMvec=MachineCodeForInstruction::get(termInstr);
   vector<SchedGraphNode*> delayNodeVec;
   const MachineInstr* brInstr = NULL;
   
-  assert(termInstr->getOpcode() != Instruction::Call
-         && "Call used as terminator?");
-  
   if (termInstr->getOpcode() != Instruction::Ret)
     {
       // To find instructions that need delay slots without searching the full
index 80355e498606b5fc87947efda3e6bb7e19035696..fb6087c44d9055bc0c11786e8b3a1cbd80e668be 100644 (file)
@@ -391,13 +391,13 @@ private:
 // for <const SchedGraphNode, SchedGraphNode::const_iterator>.
 // 
 template <class _NodeType, class _EdgeType, class _EdgeIter>
-class PredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
+class SGPredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
 protected:
   _EdgeIter oi;
 public:
-  typedef PredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
+  typedef SGPredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
   
-  inline PredIterator(_EdgeIter startEdge) : oi(startEdge) {}
+  inline SGPredIterator(_EdgeIter startEdge) : oi(startEdge) {}
   
   inline bool operator==(const _Self& x) const { return oi == x.oi; }
   inline bool operator!=(const _Self& x) const { return !operator==(x); }
@@ -420,13 +420,13 @@ public:
 };
 
 template <class _NodeType, class _EdgeType, class _EdgeIter>
-class SuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
+class SGSuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
 protected:
   _EdgeIter oi;
 public:
-  typedef SuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
+  typedef SGSuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
   
-  inline SuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
+  inline SGSuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
   
   inline bool operator==(const _Self& x) const { return oi == x.oi; }
   inline bool operator!=(const _Self& x) const { return !operator==(x); }
@@ -451,9 +451,9 @@ public:
 // sg_pred_iterator
 // sg_pred_const_iterator
 //
-typedef PredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
+typedef SGPredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
     sg_pred_iterator;
-typedef PredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
+typedef SGPredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
     sg_pred_const_iterator;
 
 inline sg_pred_iterator       pred_begin(      SchedGraphNode *N) {
@@ -474,9 +474,9 @@ inline sg_pred_const_iterator pred_end(  const SchedGraphNode *N) {
 // sg_succ_iterator
 // sg_succ_const_iterator
 //
-typedef SuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
+typedef SGSuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
     sg_succ_iterator;
-typedef SuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
+typedef SGSuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
     sg_succ_const_iterator;
 
 inline sg_succ_iterator       succ_begin(      SchedGraphNode *N) {
index cd0ca6645acb0773e5cd19284c43aa256d281c32..af02e57616d4a7565d578073d184b3d0f58a0270 100644 (file)
@@ -159,7 +159,7 @@ SelectInstructionsForMethod(Method* method, TargetMachine &target)
 
 void InsertPhiElimInst(BasicBlock *BB, MachineInstr *CpMI) { 
 
-  TerminatorInst *TermInst = BB->getTerminator();
+  Instruction *TermInst = (Instruction*)BB->getTerminator();
   MachineCodeForInstruction &MC4Term = MachineCodeForInstruction::get(TermInst);
   MachineInstr *FirstMIOfTerm = *( MC4Term.begin() );
 
index 84adecda6d0833c9bbc246ef6d6e30f89714435a..1468301dfcef3720188fd3d35e4c7e4387abd4a2 100644 (file)
@@ -8,6 +8,7 @@
 #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/BasicBlock.h"
+#include "llvm/Support/CFG.h"
 #include "Support/SetOperations.h"
 
 /// BROKEN: Should not include sparc stuff directly into here
@@ -197,8 +198,8 @@ bool BBLiveVar::applyFlowFunc() {
   //
   bool needAnotherIt = false;  
 
-  for (BasicBlock::pred_const_iterator PI = BB->pred_begin(),
-         PE = BB->pred_begin(); PI != PE ; ++PI) {
+  for (pred_const_iterator PI = pred_begin(BB), PE = pred_begin(BB);
+       PI != PE ; ++PI) {
     BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(*PI);
 
     // do set union
index b026ccd67a0d58fd21558cdf2b7991b5e6865ecc..a4556d161d0187a1baa92a18346f9bb995db64dd 100644 (file)
@@ -84,15 +84,16 @@ void InsertPrologEpilogCode::InsertPrologCode(Method* method)
 
 void InsertPrologEpilogCode::InsertEpilogCode(Method* method)
 {
-  for (Method::iterator I=method->begin(), E=method->end(); I != E; ++I)
-    if ((*I)->getTerminator()->getOpcode() == Instruction::Ret)
+  for (Method::iterator I=method->begin(), E=method->end(); I != E; ++I) {
+    Instruction *TermInst = (Instruction*)(*I)->getTerminator();
+    if (TermInst->getOpcode() == Instruction::Ret)
       {
         BasicBlock* exitBB = *I;
         unsigned N = GetInstructionsForEpilog(exitBB, Target, minstrVec);
         
         MachineCodeForBasicBlock& bbMvec = exitBB->getMachineInstrVec();
         MachineCodeForInstruction &termMvec =
-          MachineCodeForInstruction::get(exitBB->getTerminator());
+          MachineCodeForInstruction::get(TermInst);
         
         // Remove the NOPs in the delay slots of the return instruction
         const MachineInstrInfo &mii = Target.getInstrInfo();
@@ -115,6 +116,7 @@ void InsertPrologEpilogCode::InsertEpilogCode(Method* method)
         // Append the epilog code to the end of the basic block.
         bbMvec.push_back(minstrVec[0]);
       }
+  }
 }
 
 
index 297eaddfba5696f538f552a7c82a81b0da6e9575..7ec2b6faa83cde56b8068110519b7a336f1fa425 100644 (file)
@@ -22,6 +22,7 @@
 #include "llvm/iMemory.h"
 #include "llvm/iTerminators.h"
 #include "llvm/iOther.h"
+#include "llvm/Support/CFG.h"
 #include <algorithm>
 #include <iostream>
 using std::vector;
@@ -355,7 +356,7 @@ static inline bool FixCastsAndPHIs(BasicBlock *BB) {
 //
 static inline void RefactorPredecessor(BasicBlock *BB, BasicBlock *Pred) {
   Method *M = BB->getParent();
-  assert(find(BB->pred_begin(), BB->pred_end(), Pred) != BB->pred_end() &&
+  assert(find(pred_begin(BB), pred_end(BB), Pred) != pred_end(BB) &&
          "Pred is not a predecessor of BB!");
 
   // Create a new basic block, adding it to the end of the method.
@@ -448,7 +449,7 @@ static bool fixLocalProblems(Method *M) {
     Changed |= FixCastsAndPHIs(BB);
 
     if (isa<PHINode>(BB->front())) {
-      const vector<BasicBlock*> Preds(BB->pred_begin(), BB->pred_end());
+      const vector<BasicBlock*> Preds(pred_begin(BB), pred_end(BB));
 
       // Handle Problem #1.  Sort the list of predecessors so that it is easy to
       // decide whether or not duplicate predecessors exist.
index 7f71cf18504a0717bda3248ef5b842b28de84ac5..91bed41f6c338ce932d2fb98e783c9d6dfb5b6a1 100644 (file)
@@ -264,8 +264,7 @@ BasicBlock *ADCE::fixupCFG(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks,
     }
 
     // Recursively traverse successors of this basic block.  
-    BasicBlock::succ_iterator SI = BB->succ_begin(), SE = BB->succ_end();
-    for (; SI != SE; ++SI) {
+    for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) {
       BasicBlock *Succ = *SI;
       BasicBlock *Repl = fixupCFG(Succ, VisitedBlocks, AliveBlocks);
       if (Repl && Repl != Succ) {          // We have to replace the successor
@@ -278,8 +277,7 @@ BasicBlock *ADCE::fixupCFG(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks,
     BasicBlock *ReturnBB = 0;              // Default to nothing live down here
     
     // Recursively traverse successors of this basic block.  
-    BasicBlock::succ_iterator SI = BB->succ_begin(), SE = BB->succ_end();
-    for (; SI != SE; ++SI) {
+    for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) {
       BasicBlock *RetBB = fixupCFG(*SI, VisitedBlocks, AliveBlocks);
       if (RetBB) {
        assert(ReturnBB == 0 && "One one live child allowed!");
index 89cf45aa7e603cffaaf270f7b46f44e4f93b3ff7..8f351a1431ccd4a974ffbace01f3b63a9f5cbf8f 100644 (file)
@@ -31,6 +31,7 @@
 #include "llvm/iTerminators.h"
 #include "llvm/iPHINode.h"
 #include "llvm/Assembly/Writer.h"
+#include "llvm/Support/CFG.h"
 #include "Support/STLExtras.h"
 #include <algorithm>
 
@@ -73,15 +74,15 @@ bool DeadInstElimination::runOnBasicBlock(BasicBlock *BB) {
 // things in a basic block, if they are present.
 //
 static bool RemoveSingularPHIs(BasicBlock *BB) {
-  BasicBlock::pred_iterator PI(BB->pred_begin());
-  if (PI == BB->pred_end() || ++PI != BB->pred_end()) 
+  pred_iterator PI(pred_begin(BB));
+  if (PI == pred_end(BB) || ++PI != pred_end(BB)) 
     return false;   // More than one predecessor...
 
   Instruction *I = BB->front();
   if (!isa<PHINode>(I)) return false;  // No PHI nodes
 
   //cerr << "Killing PHIs from " << BB;
-  //cerr << "Pred #0 = " << *BB->pred_begin();
+  //cerr << "Pred #0 = " << *pred_begin(BB);
 
   //cerr << "Method == " << BB->getParent();
 
@@ -115,19 +116,19 @@ static void ReplaceUsesWithConstant(Instruction *I) {
 // Assumption: Succ is the single successor for BB.
 //
 static bool PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
-  assert(*BB->succ_begin() == Succ && "Succ is not successor of BB!");
+  assert(*succ_begin(BB) == Succ && "Succ is not successor of BB!");
   assert(isa<PHINode>(Succ->front()) && "Only works on PHId BBs!");
 
   // If there is more than one predecessor, and there are PHI nodes in
   // the successor, then we need to add incoming edges for the PHI nodes
   //
-  const std::vector<BasicBlock*> BBPreds(BB->pred_begin(), BB->pred_end());
+  const std::vector<BasicBlock*> BBPreds(pred_begin(BB), pred_end(BB));
 
   // Check to see if one of the predecessors of BB is already a predecessor of
   // Succ.  If so, we cannot do the transformation!
   //
-  for (BasicBlock::pred_iterator PI = Succ->pred_begin(), PE = Succ->pred_end();
-         PI != PE; ++PI) {
+  for (pred_iterator PI = pred_begin(Succ), PE = pred_end(Succ);
+       PI != PE; ++PI) {
     if (find(BBPreds.begin(), BBPreds.end(), *PI) != BBPreds.end())
       return true;
   }
@@ -169,13 +170,13 @@ bool SimplifyCFG(Method::iterator &BBIt) {
 
 
   // Remove basic blocks that have no predecessors... which are unreachable.
-  if (BB->pred_begin() == BB->pred_end() &&
+  if (pred_begin(BB) == pred_end(BB) &&
       !BB->hasConstantReferences()) {
     //cerr << "Removing BB: \n" << BB;
 
     // Loop through all of our successors and make sure they know that one
     // of their predecessors is going away.
-    for_each(BB->succ_begin(), BB->succ_end(),
+    for_each(succ_begin(BB), succ_end(BB),
             std::bind2nd(std::mem_fun(&BasicBlock::removePredecessor), BB));
 
     while (!BB->empty()) {
@@ -196,10 +197,10 @@ bool SimplifyCFG(Method::iterator &BBIt) {
 
   // Check to see if this block has no instructions and only a single 
   // successor.  If so, replace block references with successor.
-  BasicBlock::succ_iterator SI(BB->succ_begin());
-  if (SI != BB->succ_end() && ++SI == BB->succ_end()) {  // One succ?
+  succ_iterator SI(succ_begin(BB));
+  if (SI != succ_end(BB) && ++SI == succ_end(BB)) {  // One succ?
     if (BB->front()->isTerminator()) {   // Terminator is the only instruction!
-      BasicBlock *Succ = *BB->succ_begin(); // There is exactly one successor
+      BasicBlock *Succ = *succ_begin(BB); // There is exactly one successor
       //cerr << "Killing Trivial BB: \n" << BB;
       
       if (Succ != BB) {   // Arg, don't hurt infinite loops!
@@ -227,16 +228,16 @@ bool SimplifyCFG(Method::iterator &BBIt) {
 
   // Merge basic blocks into their predecessor if there is only one pred, 
   // and if there is only one successor of the predecessor. 
-  BasicBlock::pred_iterator PI(BB->pred_begin());
-  if (PI != BB->pred_end() && *PI != BB &&    // Not empty?  Not same BB?
-      ++PI == BB->pred_end() && !BB->hasConstantReferences()) {
-    BasicBlock *Pred = *BB->pred_begin();
+  pred_iterator PI(pred_begin(BB));
+  if (PI != pred_end(BB) && *PI != BB &&    // Not empty?  Not same BB?
+      ++PI == pred_end(BB) && !BB->hasConstantReferences()) {
+    BasicBlock *Pred = *pred_begin(BB);
     TerminatorInst *Term = Pred->getTerminator();
     assert(Term != 0 && "malformed basic block without terminator!");
     
     // Does the predecessor block only have a single successor?
-    BasicBlock::succ_iterator SI(Pred->succ_begin());
-    if (++SI == Pred->succ_end()) {
+    succ_iterator SI(succ_begin(Pred));
+    if (++SI == succ_end(Pred)) {
       //cerr << "Merging: " << BB << "into: " << Pred;
       
       // Delete the unconditianal branch from the predecessor...
index 59442ea2773488ade7b345c741758cf5d2ccb1ff..692fcacb7e3b2723334d9245d4e685c0c79a021b 100644 (file)
@@ -13,6 +13,7 @@
 #include "llvm/Type.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/ConstantVals.h"
+#include "llvm/Support/CFG.h"
 #include "Support/STLExtras.h"
 
 #if 0
@@ -87,8 +88,8 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) {
 
     // Figure out which block is incoming and which is the backedge for the loop
     BasicBlock *Incoming, *BackEdgeBlock;
-    BasicBlock::pred_iterator PI = Header->pred_begin();
-    assert(PI != Header->pred_end() && "Loop headers should have 2 preds!");
+    pred_iterator PI = pred_begin(Header);
+    assert(PI != pred_end(Header) && "Loop headers should have 2 preds!");
     if (Loop->contains(*PI)) {  // First pred is back edge...
       BackEdgeBlock = *PI++;
       Incoming      = *PI++;
@@ -96,7 +97,7 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) {
       Incoming      = *PI++;
       BackEdgeBlock = *PI++;
     }
-    assert(PI == Header->pred_end() && "Loop headers should have 2 preds!");
+    assert(PI == pred_end(Header) && "Loop headers should have 2 preds!");
     
     // Add incoming values for the PHI node...
     PN->addIncoming(Constant::getNullConstant(Type::UIntTy), Incoming);
index bc130f0faf5932e2c1f74cf8477a7990a934e41e..617c08695b7bca79b6f94995ab0185e1888a2961 100644 (file)
@@ -27,6 +27,8 @@
 #include "llvm/iPHINode.h"
 #include "llvm/Method.h"
 #include "llvm/BasicBlock.h"
+#include "llvm/InstrTypes.h"
+#include "llvm/Support/CFG.h"
 #include "Support/STLExtras.h"
 #include <algorithm>
 #include <iostream>
@@ -197,12 +199,12 @@ static PHINode *InjectSimpleInductionVariable(cfg::Interval *Int) {
   // Figure out which predecessors I have to play with... there should be
   // exactly two... one of which is a loop predecessor, and one of which is not.
   //
-  BasicBlock::pred_iterator PI = Header->pred_begin();
-  assert(PI != Header->pred_end() && "Header node should have 2 preds!");
+  pred_iterator PI = pred_begin(Header);
+  assert(PI != pred_end(Header) && "Header node should have 2 preds!");
   BasicBlock *Pred1 = *PI; ++PI;
-  assert(PI != Header->pred_end() && "Header node should have 2 preds!");
+  assert(PI != pred_end(Header) && "Header node should have 2 preds!");
   BasicBlock *Pred2 = *PI;
-  assert(++PI == Header->pred_end() && "Header node should have 2 preds!");
+  assert(++PI == pred_end(Header) && "Header node should have 2 preds!");
 
   // Make Pred1 be the loop entrance predecessor, Pred2 be the Loop predecessor
   if (Int->contains(Pred1)) std::swap(Pred1, Pred2);
index 962ca97dec59bcd88b4344adf9b0013c38800cee..316925025556e60c6fd1cda1b9281454e56334d5 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/Transforms/Scalar/ConstantHandling.h"
 #include "llvm/Method.h"
 #include "llvm/iMemory.h"
+#include "llvm/InstrTypes.h"
 #include "llvm/Support/InstIterator.h"
 #include "../TransformInternals.h"
 
index df999b84bffd3072e7182042e476c89c57a0a008..222bb140193b8b7c7c2358c65675786389116516 100644 (file)
@@ -5,11 +5,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/ValueHolderImpl.h"
-#include "llvm/BasicBlock.h"
 #include "llvm/iTerminators.h"
-#include "llvm/Method.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/Type.h"
+#include "llvm/Support/CFG.h"
 #include "llvm/iPHINode.h"
 #include "llvm/CodeGen/MachineInstr.h"
 
@@ -90,11 +89,11 @@ bool BasicBlock::hasConstantReferences() const {
 // called while the predecessor still refers to this block.
 //
 void BasicBlock::removePredecessor(BasicBlock *Pred) {
-  assert(find(pred_begin(), pred_end(), Pred) != pred_end() &&
+  assert(find(pred_begin(this), pred_end(this), Pred) != pred_end(this) &&
         "removePredecessor: BB is not a predecessor!");
   if (!isa<PHINode>(front())) return;   // Quick exit.
 
-  pred_iterator PI(pred_begin()), EI(pred_end());
+  pred_iterator PI(pred_begin(this)), EI(pred_end(this));
   unsigned max_idx;
 
   // Loop over the rest of the predecessors until we run out, or until we find
index 33e14e9fc583e1058af861de42e4a689cad465b2..48cc86fcaf542dc3612e1f1d6046112ad84ce7a2 100644 (file)
@@ -37,7 +37,7 @@ bool cfg::DominatorSet::runOnMethod(Method *M) {
 //
 void cfg::DominatorSet::calcForwardDominatorSet(Method *M) {
   Root = M->getEntryNode();
-  assert(Root->pred_begin() == Root->pred_end() &&
+  assert(pred_begin(Root) == pred_end(Root) &&
         "Root node has predecessors in method!");
 
   bool Changed;
@@ -48,8 +48,7 @@ void cfg::DominatorSet::calcForwardDominatorSet(Method *M) {
     df_iterator<Method*> It = df_begin(M), End = df_end(M);
     for ( ; It != End; ++It) {
       const BasicBlock *BB = *It;
-      BasicBlock::pred_const_iterator PI = BB->pred_begin(),
-                                      PEnd = BB->pred_end();
+      pred_const_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
       if (PI != PEnd) {                // Is there SOME predecessor?
        // Loop until we get to a predecessor that has had it's dom set filled
        // in at least once.  We are guaranteed to have this because we are
@@ -102,8 +101,7 @@ void cfg::DominatorSet::calcPostDominatorSet(Method *M) {
     idf_iterator<BasicBlock*> It = idf_begin(Root), End = idf_end(Root);
     for ( ; It != End; ++It) {
       const BasicBlock *BB = *It;
-      BasicBlock::succ_const_iterator PI = BB->succ_begin(),
-                                      PEnd = BB->succ_end();
+      succ_const_iterator PI = succ_begin(BB), PEnd = succ_end(BB);
       if (PI != PEnd) {                // Is there SOME predecessor?
        // Loop until we get to a successor that has had it's dom set filled
        // in at least once.  We are guaranteed to have this because we are
@@ -337,8 +335,8 @@ cfg::DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
   const BasicBlock *BB = Node->getNode();
   DomSetType &S = Frontiers[BB];       // The new set to fill in...
 
-  for (BasicBlock::succ_const_iterator SI = BB->succ_begin(),
-                                       SE = BB->succ_end(); SI != SE; ++SI) {
+  for (succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB);
+       SI != SE; ++SI) {
     // Does Node immediately dominate this successor?
     if (DT[*SI]->getIDom() != Node)
       S.insert(*SI);
@@ -371,8 +369,8 @@ cfg::DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT,
   DomSetType &S = Frontiers[BB];       // The new set to fill in...
   if (!Root) return S;
 
-  for (BasicBlock::pred_const_iterator SI = BB->pred_begin(),
-                                       SE = BB->pred_end(); SI != SE; ++SI) {
+  for (pred_const_iterator SI = pred_begin(BB), SE = pred_end(BB);
+       SI != SE; ++SI) {
     // Does Node immediately dominate this predeccessor?
     if (DT[*SI]->getIDom() != Node)
       S.insert(*SI);