From f0604b84c7273fc2503454ecaa198eaee5b615bd Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 1 Oct 2001 13:19:53 +0000 Subject: [PATCH] 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 --- .../Analysis/LiveVar/FunctionLiveVarInfo.h | 3 +- include/llvm/BasicBlock.h | 143 +++++++++++++++-- include/llvm/CFG.h | 149 ------------------ include/llvm/CFGdecls.h | 144 ----------------- include/llvm/CodeGen/FunctionLiveVarInfo.h | 3 +- lib/Analysis/Interval.cpp | 8 +- lib/Analysis/LiveVar/BBLiveVar.cpp | 4 +- lib/Analysis/LiveVar/BBLiveVar.h | 3 +- lib/Analysis/PostDominators.cpp | 14 +- lib/Target/SparcV9/LiveVar/BBLiveVar.cpp | 4 +- lib/Target/SparcV9/LiveVar/BBLiveVar.h | 3 +- lib/Transforms/Scalar/ADCE.cpp | 4 +- lib/Transforms/Scalar/DCE.cpp | 33 ++-- lib/Transforms/Scalar/InductionVars.cpp | 9 +- lib/VMCore/BasicBlock.cpp | 6 +- lib/VMCore/Dominators.cpp | 14 +- 16 files changed, 176 insertions(+), 368 deletions(-) delete mode 100644 include/llvm/CFG.h delete mode 100644 include/llvm/CFGdecls.h diff --git a/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h b/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h index 0dca0fee99b..6283a45aa91 100644 --- a/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h +++ b/include/llvm/Analysis/LiveVar/FunctionLiveVarInfo.h @@ -1,4 +1,4 @@ -/* Title: MethodLiveVarInfo.h +/* Title: MethodLiveVarInfo.h -*- C++ -*- Author: Ruchira Sasanka Date: Jun 30, 01 Purpose: @@ -73,7 +73,6 @@ static const int DEBUG_LV = 0; #include "llvm/BasicBlock.h" #include "llvm/Instruction.h" #include "llvm/Method.h" -#include "llvm/CFG.h" #include "LiveVarMap.h" #include "BBLiveVar.h" diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index 50ec4c0fbdc..11c76a36472 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -22,11 +22,11 @@ #ifndef LLVM_BASICBLOCK_H #define LLVM_BASICBLOCK_H -#include "llvm/Value.h" // Get the definition of Value +#include "llvm/Value.h" #include "llvm/ValueHolder.h" #include "llvm/Support/GraphTraits.h" - -#include "llvm/CFGdecls.h" // TODO FIXME: remove +#include "llvm/InstrTypes.h" +#include class Instruction; class Method; @@ -34,6 +34,8 @@ class TerminatorInst; class MachineCodeForBasicBlock; class BasicBlock : public Value { // Basic blocks are data objects also + template class PredIterator; + template class SuccIterator; public: typedef ValueHolder InstListType; private : @@ -50,17 +52,22 @@ public: typedef reverse_iterator const_reverse_iterator; typedef reverse_iterator reverse_iterator; - typedef cfg::succ_iterator succ_iterator; // Include CFG.h to use these - typedef cfg::pred_iterator pred_iterator; - typedef cfg::succ_const_iterator succ_const_iterator; - typedef cfg::pred_const_iterator pred_const_iterator; + // Predecessor and successor iterators... + typedef PredIterator pred_iterator; + typedef PredIterator pred_const_iterator; + typedef SuccIterator succ_iterator; + typedef SuccIterator succ_const_iterator; + // Ctor, dtor BasicBlock(const string &Name = "", Method *Parent = 0); ~BasicBlock(); // Specialize setName to take care of symbol table majik virtual void setName(const string &name, SymbolTable *ST = 0); + // getParent - Return the enclosing method, or null if none const Method *getParent() const { return InstList.getParent(); } Method *getParent() { return InstList.getParent(); } @@ -70,7 +77,6 @@ public: // TerminatorInst *getTerminator(); const TerminatorInst *const getTerminator() const; - // Machine code accessor... inline MachineCodeForBasicBlock& getMachineInstrVec() const { @@ -79,6 +85,7 @@ public: //===--------------------------------------------------------------------===// // Instruction iterator methods + // inline iterator begin() { return InstList.begin(); } inline const_iterator begin() const { return InstList.begin(); } inline iterator end () { return InstList.end(); } @@ -140,9 +147,111 @@ public: // the basic block). // BasicBlock *splitBasicBlock(iterator I); + + + //===--------------------------------------------------------------------===// + // Predecessor and Successor Iterators + // + template // Predecessor Iterator + class PredIterator : public std::bidirectional_iterator<_Ptr, ptrdiff_t> { + _Ptr *BB; + _USE_iterator It; + public: + typedef PredIterator<_Ptr,_USE_iterator> _Self; + + inline void advancePastConstPool() { + // TODO: This is bad + // Loop to ignore constant pool references + while (It != BB->use_end() && + ((!(*It)->isInstruction()) || + !(((Instruction*)(*It))->isTerminator()))) + ++It; + } + + inline PredIterator(_Ptr *bb) : BB(bb), It(bb->use_begin()) { + advancePastConstPool(); + } + inline PredIterator(_Ptr *bb, bool) : BB(bb), It(bb->use_end()) {} + + inline bool operator==(const _Self& x) const { return It == x.It; } + inline bool operator!=(const _Self& x) const { return !operator==(x); } + + inline pointer operator*() const { + return (*It)->castInstructionAsserting()->getParent(); + } + inline pointer *operator->() const { return &(operator*()); } + + inline _Self& operator++() { // Preincrement + ++It; advancePastConstPool(); + return *this; + } + + inline _Self operator++(int) { // Postincrement + _Self tmp = *this; ++*this; return tmp; + } + + inline _Self& operator--() { --It; return *this; } // Predecrement + inline _Self operator--(int) { // Postdecrement + _Self tmp = *this; --*this; return tmp; + } + }; + + inline pred_iterator pred_begin() { return pred_iterator(this); } + inline pred_const_iterator pred_begin() const { + return pred_const_iterator(this); + } + inline pred_iterator pred_end() { return pred_iterator(this, true); } + inline pred_const_iterator pred_end() const { + return pred_const_iterator(this, true); + } + + template // Successor Iterator + class SuccIterator : public std::bidirectional_iterator<_BB, ptrdiff_t> { + const _Term Term; + unsigned idx; + public: + typedef SuccIterator<_Term, _BB> _Self; + // TODO: This can be random access iterator, need operator+ and stuff tho + + inline SuccIterator(_Term T) : Term(T), idx(0) { // begin iterator + assert(T && "getTerminator returned null!"); + } + inline SuccIterator(_Term T, bool) // end iterator + : Term(T), idx(Term->getNumSuccessors()) { + assert(T && "getTerminator returned null!"); + } + + inline bool operator==(const _Self& x) const { return idx == x.idx; } + inline bool operator!=(const _Self& x) const { return !operator==(x); } + + inline pointer operator*() const { return Term->getSuccessor(idx); } + inline pointer operator->() const { return operator*(); } + + inline _Self& operator++() { ++idx; return *this; } // Preincrement + inline _Self operator++(int) { // Postincrement + _Self tmp = *this; ++*this; return tmp; + } + + inline _Self& operator--() { --idx; return *this; } // Predecrement + inline _Self operator--(int) { // Postdecrement + _Self tmp = *this; --*this; return tmp; + } + }; + + inline succ_iterator succ_begin() { return succ_iterator(getTerminator()); } + inline succ_const_iterator succ_begin() const { + return succ_const_iterator(getTerminator()); + } + inline succ_iterator succ_end() {return succ_iterator(getTerminator(), true);} + inline succ_const_iterator succ_end() const { + return succ_const_iterator(getTerminator(), true); + } }; -#include "llvm/CFG.h" // TODO FIXME when succ iterators are in BB.h + +//===--------------------------------------------------------------------===// +// GraphTraits specializations for basic block graphs (CFGs) +//===--------------------------------------------------------------------===// // Provide specializations of GraphTraits to be able to treat a method as a // graph of basic blocks... @@ -153,10 +262,10 @@ template <> struct GraphTraits { static NodeType *getEntryNode(BasicBlock *BB) { return BB; } static inline ChildIteratorType child_begin(NodeType *N) { - return cfg::succ_begin(N); + return N->succ_begin(); } static inline ChildIteratorType child_end(NodeType *N) { - return cfg::succ_end(N); + return N->succ_end(); } }; @@ -167,10 +276,10 @@ template <> struct GraphTraits { static NodeType *getEntryNode(const BasicBlock *BB) { return BB; } static inline ChildIteratorType child_begin(NodeType *N) { - return cfg::succ_begin(N); + return N->succ_begin(); } static inline ChildIteratorType child_end(NodeType *N) { - return cfg::succ_end(N); + return N->succ_end(); } }; @@ -184,10 +293,10 @@ template <> struct GraphTraits > { typedef BasicBlock::pred_iterator ChildIteratorType; static NodeType *getEntryNode(Inverse G) { return G.Graph; } static inline ChildIteratorType child_begin(NodeType *N) { - return cfg::pred_begin(N); + return N->pred_begin(); } static inline ChildIteratorType child_end(NodeType *N) { - return cfg::pred_end(N); + return N->pred_end(); } }; @@ -198,10 +307,10 @@ template <> struct GraphTraits > { return G.Graph; } static inline ChildIteratorType child_begin(NodeType *N) { - return cfg::pred_begin(N); + return N->pred_begin(); } static inline ChildIteratorType child_end(NodeType *N) { - return cfg::pred_end(N); + return N->pred_end(); } }; diff --git a/include/llvm/CFG.h b/include/llvm/CFG.h deleted file mode 100644 index ad9cd949329..00000000000 --- a/include/llvm/CFG.h +++ /dev/null @@ -1,149 +0,0 @@ -//===-- llvm/CFG.h - CFG definitions and useful classes ----------*- C++ -*--=// -// -// This file contains the class definitions useful for operating on the control -// flow graph. -// -// Currently it contains functionality for these three applications: -// -// 1. Iterate over the predecessors of a basic block: -// pred_iterator, pred_const_iterator, pred_begin, pred_end -// 2. Iterate over the successors of a basic block: -// succ_iterator, succ_const_iterator, succ_begin, succ_end -// 3. Iterate over the basic blocks of a method in depth first ordering or -// reverse depth first order. df_iterator, df_const_iterator, -// df_begin, df_end. df_begin takes an arg to specify reverse or not. -// 4. Iterator over the basic blocks of a method in post order. -// 5. Iterator over a method in reverse post order. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CFG_H -#define LLVM_CFG_H - -#include "llvm/CFGdecls.h" // See this file for concise interface info -#include "llvm/BasicBlock.h" -#include "llvm/InstrTypes.h" -#include "llvm/Type.h" -#include - -namespace cfg { - -//===----------------------------------------------------------------------===// -// Implementation -//===----------------------------------------------------------------------===// - -//===----------------------------------------------------------------------===// -// Basic Block Predecessor Iterator -// - -template // Predecessor Iterator -class PredIterator : public std::bidirectional_iterator<_Ptr, ptrdiff_t> { - _Ptr *BB; - _USE_iterator It; -public: - typedef PredIterator<_Ptr,_USE_iterator> _Self; - - inline void advancePastConstPool() { - // TODO: This is bad - // Loop to ignore constant pool references - while (It != BB->use_end() && - ((!(*It)->isInstruction()) || - !(((Instruction*)(*It))->isTerminator()))) - ++It; - } - - inline PredIterator(_Ptr *bb) : BB(bb), It(bb->use_begin()) { - advancePastConstPool(); - } - inline PredIterator(_Ptr *bb, bool) : BB(bb), It(bb->use_end()) {} - - inline bool operator==(const _Self& x) const { return It == x.It; } - inline bool operator!=(const _Self& x) const { return !operator==(x); } - - inline pointer operator*() const { - return (*It)->castInstructionAsserting()->getParent(); - } - inline pointer *operator->() const { return &(operator*()); } - - inline _Self& operator++() { // Preincrement - ++It; advancePastConstPool(); - return *this; - } - - inline _Self operator++(int) { // Postincrement - _Self tmp = *this; ++*this; return tmp; - } - - inline _Self& operator--() { --It; return *this; } // Predecrement - inline _Self operator--(int) { // Postdecrement - _Self tmp = *this; --*this; return tmp; - } -}; - -inline pred_iterator pred_begin( BasicBlock *BB) { - return pred_iterator(BB); -} -inline pred_const_iterator pred_begin(const BasicBlock *BB) { - return pred_const_iterator(BB); -} -inline pred_iterator pred_end( BasicBlock *BB) { - return pred_iterator(BB,true); -} -inline pred_const_iterator pred_end(const BasicBlock *BB) { - return pred_const_iterator(BB,true); -} - - -//===----------------------------------------------------------------------===// -// Basic Block Successor Iterator -// - -template // Successor Iterator -class SuccIterator : public std::bidirectional_iterator<_BB, ptrdiff_t> { - const _Term Term; - unsigned idx; -public: - typedef SuccIterator<_Term, _BB> _Self; - // TODO: This can be random access iterator, need operator+ and stuff tho - - inline SuccIterator(_Term T) : Term(T), idx(0) { // begin iterator - assert(T && "getTerminator returned null!"); - } - inline SuccIterator(_Term T, bool) // end iterator - : Term(T), idx(Term->getNumSuccessors()) { - assert(T && "getTerminator returned null!"); - } - - inline bool operator==(const _Self& x) const { return idx == x.idx; } - inline bool operator!=(const _Self& x) const { return !operator==(x); } - - inline pointer operator*() const { return Term->getSuccessor(idx); } - inline pointer operator->() const { return operator*(); } - - inline _Self& operator++() { ++idx; return *this; } // Preincrement - inline _Self operator++(int) { // Postincrement - _Self tmp = *this; ++*this; return tmp; - } - - inline _Self& operator--() { --idx; return *this; } // Predecrement - inline _Self operator--(int) { // Postdecrement - _Self tmp = *this; --*this; return tmp; - } -}; - -inline succ_iterator succ_begin( BasicBlock *BB) { - return succ_iterator(BB->getTerminator()); -} -inline succ_const_iterator succ_begin(const BasicBlock *BB) { - return succ_const_iterator(BB->getTerminator()); -} -inline succ_iterator succ_end( BasicBlock *BB) { - return succ_iterator(BB->getTerminator(),true); -} -inline succ_const_iterator succ_end(const BasicBlock *BB) { - return succ_const_iterator(BB->getTerminator(),true); -} - -} // End namespace cfg - -#endif diff --git a/include/llvm/CFGdecls.h b/include/llvm/CFGdecls.h deleted file mode 100644 index 4ffe256f5e4..00000000000 --- a/include/llvm/CFGdecls.h +++ /dev/null @@ -1,144 +0,0 @@ -//===-- llvm/CFGdecls.h - CFG forward declarations ---------------*- C++ -*--=// -// -// This file contains forward declarations for CFG functions and data -// structures. This is used to reduce compile time dependencies among files. -// Any users of these functions must include CFG.h to get their full -// definitions. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CFG_DECLS_H -#define LLVM_CFG_DECLS_H - -#include "llvm/Value.h" -class TerminatorInst; -class BasicBlock; -class Method; - -//===----------------------------------------------------------------------===// -// Interface -//===----------------------------------------------------------------------===// - -namespace cfg { - -//===--------------------------------------------------------------------===// -// Predecessor iterator code -//===--------------------------------------------------------------------===// -// -// This is used to figure out what basic blocks we could be coming from. -// - -// Forward declare iterator class template... -template class PredIterator; - -typedef PredIterator pred_iterator; -typedef PredIterator pred_const_iterator; - -inline pred_iterator pred_begin( BasicBlock *BB); -inline pred_const_iterator pred_begin(const BasicBlock *BB); -inline pred_iterator pred_end ( BasicBlock *BB); -inline pred_const_iterator pred_end (const BasicBlock *BB); - - -//===--------------------------------------------------------------------===// -// Successor iterator code -//===--------------------------------------------------------------------===// -// -// This is used to figure out what basic blocks we could be going to... -// - -// Forward declare iterator class template... -template class SuccIterator; - -typedef SuccIterator succ_iterator; -typedef SuccIterator succ_const_iterator; - -inline succ_iterator succ_begin( BasicBlock *BB); -inline succ_const_iterator succ_begin(const BasicBlock *BB); -inline succ_iterator succ_end ( BasicBlock *BB); -inline succ_const_iterator succ_end (const BasicBlock *BB); - -#if 0 -//===--------------------------------------------------------------------===// -// Depth First CFG iterator code -//===--------------------------------------------------------------------===// -// -// This is used to visit basic blocks in a method in either depth first, or -// reverse depth first ordering, depending on the value passed to the df_begin -// method. -// -struct BasicBlockGraph; -struct ConstBasicBlockGraph; -struct InverseBasicBlockGraph; -struct ConstInverseBasicBlockGraph; -struct TypeGraph; - -// Forward declare iterator class template... -template class DFIterator; - -// Normal Depth First Iterator Definitions (Forward and Reverse) -typedef DFIterator< BasicBlockGraph> df_iterator; -typedef DFIterator df_const_iterator; - -inline df_iterator df_begin( Method *M, bool Reverse = false); -inline df_const_iterator df_begin(const Method *M, bool Reverse = false); -inline df_iterator df_end ( Method *M); -inline df_const_iterator df_end (const Method *M); - -inline df_iterator df_begin( BasicBlock *BB, bool Reverse = false); -inline df_const_iterator df_begin(const BasicBlock *BB, bool Reverse = false); -inline df_iterator df_end ( BasicBlock *BB); -inline df_const_iterator df_end (const BasicBlock *BB); - - -// Inverse Depth First Iterator Definitions (Forward and Reverse) - Traverse -// predecessors instead of successors... -// -typedef DFIterator< InverseBasicBlockGraph> idf_iterator; -typedef DFIterator idf_const_iterator; - -inline idf_iterator idf_begin( BasicBlock *BB, bool Reverse = false); -inline idf_const_iterator idf_begin(const BasicBlock *BB, bool Reverse = false); -inline idf_iterator idf_end ( BasicBlock *BB); -inline idf_const_iterator idf_end (const BasicBlock *BB); - - -// Depth First Iterator Definitions for Types. This lets you iterator over -// (possibly cyclic) type graphs in dfo -// -typedef DFIterator tdf_iterator; - -inline tdf_iterator tdf_begin(const Type *T, bool Reverse = false); -inline tdf_iterator tdf_end (const Type *T); - - -//===--------------------------------------------------------------------===// -// Post Order CFG iterator code -//===--------------------------------------------------------------------===// -// -// This is used to visit basic blocks in a method in standard post order. -// - -// Forward declare iterator class template... -template class POIterator; - -typedef POIterator po_iterator; -typedef POIterator po_const_iterator; - -inline po_iterator po_begin( Method *M); -inline po_const_iterator po_begin(const Method *M); -inline po_iterator po_end ( Method *M); -inline po_const_iterator po_end (const Method *M); - -inline po_iterator po_begin( BasicBlock *BB); -inline po_const_iterator po_begin(const BasicBlock *BB); -inline po_iterator po_end ( BasicBlock *BB); -inline po_const_iterator po_end (const BasicBlock *BB); -#endif - -} // End namespace cfg - -#endif diff --git a/include/llvm/CodeGen/FunctionLiveVarInfo.h b/include/llvm/CodeGen/FunctionLiveVarInfo.h index 0dca0fee99b..6283a45aa91 100644 --- a/include/llvm/CodeGen/FunctionLiveVarInfo.h +++ b/include/llvm/CodeGen/FunctionLiveVarInfo.h @@ -1,4 +1,4 @@ -/* Title: MethodLiveVarInfo.h +/* Title: MethodLiveVarInfo.h -*- C++ -*- Author: Ruchira Sasanka Date: Jun 30, 01 Purpose: @@ -73,7 +73,6 @@ static const int DEBUG_LV = 0; #include "llvm/BasicBlock.h" #include "llvm/Instruction.h" #include "llvm/Method.h" -#include "llvm/CFG.h" #include "LiveVarMap.h" #include "BBLiveVar.h" diff --git a/lib/Analysis/Interval.cpp b/lib/Analysis/Interval.cpp index 97fa34ea7ae..5c68be9c2e2 100644 --- a/lib/Analysis/Interval.cpp +++ b/lib/Analysis/Interval.cpp @@ -8,19 +8,17 @@ #include "llvm/Analysis/Interval.h" #include "llvm/BasicBlock.h" -using namespace cfg; - //===----------------------------------------------------------------------===// // Interval Implementation //===----------------------------------------------------------------------===// // isLoop - Find out if there is a back edge in this interval... // -bool Interval::isLoop() const { +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 = pred_begin(HeaderNode), - E = pred_end(HeaderNode); I != E; ++I) { + for (BasicBlock::pred_iterator I = HeaderNode->pred_begin(), + E = HeaderNode->pred_end(); I != E; ++I) { if (contains(*I)) return true; } return false; diff --git a/lib/Analysis/LiveVar/BBLiveVar.cpp b/lib/Analysis/LiveVar/BBLiveVar.cpp index 210a24bd095..80fde4e1571 100644 --- a/lib/Analysis/LiveVar/BBLiveVar.cpp +++ b/lib/Analysis/LiveVar/BBLiveVar.cpp @@ -162,9 +162,9 @@ bool BBLiveVar::applyFlowFunc(BBToBBLiveVarMapType LVMap) // whose POId is lower - cfg::pred_const_iterator PredBBI = cfg::pred_begin(BaseBB); + BasicBlock::pred_const_iterator PredBBI = BaseBB->pred_begin(); - for( ; PredBBI != cfg::pred_end(BaseBB) ; PredBBI++) { + for( ; PredBBI != BaseBB->pred_end() ; PredBBI++) { assert( *PredBBI ); // assert that the predecessor is valid BBLiveVar *PredLVBB = LVMap[*PredBBI]; diff --git a/lib/Analysis/LiveVar/BBLiveVar.h b/lib/Analysis/LiveVar/BBLiveVar.h index e4d5804489d..55a6c3abd51 100644 --- a/lib/Analysis/LiveVar/BBLiveVar.h +++ b/lib/Analysis/LiveVar/BBLiveVar.h @@ -1,4 +1,4 @@ -/* Title: BBLiveVar.h +/* Title: BBLiveVar.h -*- C++ -*- Author: Ruchira Sasanka Date: Jun 30, 01 Purpose: This is a wrapper class for BasicBlock which is used by live @@ -13,7 +13,6 @@ #include "llvm/BasicBlock.h" #include "llvm/Instruction.h" -#include "llvm/CFG.h" #include "llvm/Type.h" #include "llvm/iOther.h" diff --git a/lib/Analysis/PostDominators.cpp b/lib/Analysis/PostDominators.cpp index 03721415051..c241646b636 100644 --- a/lib/Analysis/PostDominators.cpp +++ b/lib/Analysis/PostDominators.cpp @@ -63,7 +63,8 @@ void cfg::DominatorSet::calcForwardDominatorSet(const Method *M) { df_iterator It = df_begin(M), End = df_end(M); for ( ; It != End; ++It) { const BasicBlock *BB = *It; - pred_const_iterator PI = pred_begin(BB), PEnd = pred_end(BB); + BasicBlock::pred_const_iterator PI = BB->pred_begin(), + PEnd = BB->pred_end(); 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 @@ -114,7 +115,8 @@ cfg::DominatorSet::DominatorSet(Method *M, bool PostDomSet) idf_iterator It = idf_begin(Root), End = idf_end(Root); for ( ; It != End; ++It) { const BasicBlock *BB = *It; - succ_const_iterator PI = succ_begin(BB), PEnd = succ_end(BB); + BasicBlock::succ_const_iterator PI = BB->succ_begin(), + PEnd = BB->succ_end(); 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 @@ -320,8 +322,8 @@ cfg::DominanceFrontier::calcDomFrontier(const DominatorTree &DT, const BasicBlock *BB = Node->getNode(); DomSetType &S = Frontiers[BB]; // The new set to fill in... - for (succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB); - SI != SE; ++SI) { + for (BasicBlock::succ_const_iterator SI = BB->succ_begin(), + SE = BB->succ_end(); SI != SE; ++SI) { // Does Node immediately dominate this successor? if (DT[*SI]->getIDom() != Node) S.insert(*SI); @@ -354,8 +356,8 @@ cfg::DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT, DomSetType &S = Frontiers[BB]; // The new set to fill in... if (!Root) return S; - for (pred_const_iterator SI = pred_begin(BB), SE = pred_end(BB); - SI != SE; ++SI) { + for (BasicBlock::pred_const_iterator SI = BB->pred_begin(), + SE = BB->pred_end(); SI != SE; ++SI) { // Does Node immediately dominate this predeccessor? if (DT[*SI]->getIDom() != Node) S.insert(*SI); diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp index 210a24bd095..80fde4e1571 100644 --- a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp +++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp @@ -162,9 +162,9 @@ bool BBLiveVar::applyFlowFunc(BBToBBLiveVarMapType LVMap) // whose POId is lower - cfg::pred_const_iterator PredBBI = cfg::pred_begin(BaseBB); + BasicBlock::pred_const_iterator PredBBI = BaseBB->pred_begin(); - for( ; PredBBI != cfg::pred_end(BaseBB) ; PredBBI++) { + for( ; PredBBI != BaseBB->pred_end() ; PredBBI++) { assert( *PredBBI ); // assert that the predecessor is valid BBLiveVar *PredLVBB = LVMap[*PredBBI]; diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.h b/lib/Target/SparcV9/LiveVar/BBLiveVar.h index e4d5804489d..55a6c3abd51 100644 --- a/lib/Target/SparcV9/LiveVar/BBLiveVar.h +++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.h @@ -1,4 +1,4 @@ -/* Title: BBLiveVar.h +/* Title: BBLiveVar.h -*- C++ -*- Author: Ruchira Sasanka Date: Jun 30, 01 Purpose: This is a wrapper class for BasicBlock which is used by live @@ -13,7 +13,6 @@ #include "llvm/BasicBlock.h" #include "llvm/Instruction.h" -#include "llvm/CFG.h" #include "llvm/Type.h" #include "llvm/iOther.h" diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index 446b95afe09..480a2696b56 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -264,7 +264,7 @@ BasicBlock *ADCE::fixupCFG(BasicBlock *BB, set &VisitedBlocks, } // Recursively traverse successors of this basic block. - cfg::succ_iterator SI = cfg::succ_begin(BB), SE = cfg::succ_end(BB); + BasicBlock::succ_iterator SI = BB->succ_begin(), SE = BB->succ_end(); for (; SI != SE; ++SI) { BasicBlock *Succ = *SI; BasicBlock *Repl = fixupCFG(Succ, VisitedBlocks, AliveBlocks); @@ -278,7 +278,7 @@ BasicBlock *ADCE::fixupCFG(BasicBlock *BB, set &VisitedBlocks, BasicBlock *ReturnBB = 0; // Default to nothing live down here // Recursively traverse successors of this basic block. - cfg::succ_iterator SI = cfg::succ_begin(BB), SE = cfg::succ_end(BB); + BasicBlock::succ_iterator SI = BB->succ_begin(), SE = BB->succ_end(); for (; SI != SE; ++SI) { BasicBlock *RetBB = fixupCFG(*SI, VisitedBlocks, AliveBlocks); if (RetBB) { diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index 119f92bae4b..ba3db99279f 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/lib/Transforms/Scalar/DCE.cpp @@ -31,11 +31,8 @@ #include "llvm/iTerminators.h" #include "llvm/iOther.h" #include "llvm/Assembly/Writer.h" -#include "llvm/CFG.h" #include -using namespace cfg; - struct ConstPoolDCE { enum { EndOffs = 0 }; static bool isDCEable(const ConstPoolVal *CPV) { @@ -82,15 +79,15 @@ static bool RemoveUnusedDefs(Container &Vals, DCEController DCEControl) { // things in a basic block, if they are present. // static bool RemoveSingularPHIs(BasicBlock *BB) { - pred_iterator PI(pred_begin(BB)); - if (PI == pred_end(BB) || ++PI != pred_end(BB)) + BasicBlock::pred_iterator PI(BB->pred_begin()); + if (PI == BB->pred_end() || ++PI != BB->pred_end()) return false; // More than one predecessor... Instruction *I = BB->front(); if (!I->isPHINode()) return false; // No PHI nodes //cerr << "Killing PHIs from " << BB; - //cerr << "Pred #0 = " << *pred_begin(BB); + //cerr << "Pred #0 = " << *BB->pred_begin(); //cerr << "Method == " << BB->getParent(); @@ -128,7 +125,7 @@ static void PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) { // 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 vector BBPreds(pred_begin(BB), pred_end(BB)); + const vector BBPreds(BB->pred_begin(), BB->pred_end()); BasicBlock::iterator I = Succ->begin(); do { // Loop over all of the PHI nodes in the successor BB @@ -166,13 +163,13 @@ bool opt::SimplifyCFG(Method::iterator &BBIt) { // Remove basic blocks that have no predecessors... which are unreachable. - if (pred_begin(BB) == pred_end(BB) && + if (BB->pred_begin() == BB->pred_end() && !BB->hasConstantPoolReferences()) { //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(succ_begin(BB), succ_end(BB), + for_each(BB->succ_begin(), BB->succ_end(), std::bind2nd(std::mem_fun(&BasicBlock::removePredecessor), BB)); while (!BB->empty()) { @@ -193,11 +190,11 @@ bool opt::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. - succ_iterator SI(succ_begin(BB)); - if (SI != succ_end(BB) && ++SI == succ_end(BB)) { // One succ? + BasicBlock::succ_iterator SI(BB->succ_begin()); + if (SI != BB->succ_end() && ++SI == BB->succ_end()) { // One succ? Instruction *I = BB->front(); if (I->isTerminator()) { // Terminator is the only instruction! - BasicBlock *Succ = *succ_begin(BB); // There is exactly one successor + BasicBlock *Succ = *BB->succ_begin(); // There is exactly one successor //cerr << "Killing Trivial BB: \n" << BB; if (Succ != BB) { // Arg, don't hurt infinite loops! @@ -223,16 +220,16 @@ bool opt::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. - pred_iterator PI(pred_begin(BB)); - if (PI != pred_end(BB) && *PI != BB && // Not empty? Not same BB? - ++PI == pred_end(BB) && !BB->hasConstantPoolReferences()) { - BasicBlock *Pred = *pred_begin(BB); + BasicBlock::pred_iterator PI(BB->pred_begin()); + if (PI != BB->pred_end() && *PI != BB && // Not empty? Not same BB? + ++PI == BB->pred_end() && !BB->hasConstantPoolReferences()) { + BasicBlock *Pred = *BB->pred_begin(); TerminatorInst *Term = Pred->getTerminator(); assert(Term != 0 && "malformed basic block without terminator!"); // Does the predecessor block only have a single successor? - succ_iterator SI(succ_begin(Pred)); - if (++SI == succ_end(Pred)) { + BasicBlock::succ_iterator SI(Pred->succ_begin()); + if (++SI == Pred->succ_end()) { //cerr << "Merging: " << BB << "into: " << Pred; // Delete the unconditianal branch from the predecessor... diff --git a/lib/Transforms/Scalar/InductionVars.cpp b/lib/Transforms/Scalar/InductionVars.cpp index b78eab8ad2e..69521d6c8b3 100644 --- a/lib/Transforms/Scalar/InductionVars.cpp +++ b/lib/Transforms/Scalar/InductionVars.cpp @@ -26,7 +26,6 @@ #include "llvm/Support/STLExtras.h" #include "llvm/SymbolTable.h" #include "llvm/iOther.h" -#include "llvm/CFG.h" #include #include "llvm/Analysis/LoopDepth.h" @@ -199,12 +198,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. // - cfg::pred_iterator PI = cfg::pred_begin(Header); - assert(PI != cfg::pred_end(Header) && "Header node should have 2 preds!"); + BasicBlock::pred_iterator PI = Header->pred_begin(); + assert(PI != Header->pred_end() && "Header node should have 2 preds!"); BasicBlock *Pred1 = *PI; ++PI; - assert(PI != cfg::pred_end(Header) && "Header node should have 2 preds!"); + assert(PI != Header->pred_end() && "Header node should have 2 preds!"); BasicBlock *Pred2 = *PI; - assert(++PI == cfg::pred_end(Header) && "Header node should have 2 preds!"); + assert(++PI == Header->pred_end() && "Header node should have 2 preds!"); // Make Pred1 be the loop entrance predecessor, Pred2 be the Loop predecessor if (Int->contains(Pred1)) swap(Pred1, Pred2); diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index 4c480db631c..7d97c85f7de 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -10,7 +10,6 @@ #include "llvm/Method.h" #include "llvm/SymbolTable.h" #include "llvm/Type.h" -#include "llvm/CFG.h" #include "llvm/iOther.h" #include "llvm/CodeGen/MachineInstr.h" @@ -91,12 +90,11 @@ bool BasicBlock::hasConstantPoolReferences() const { // called while the predecessor still refers to this block. // void BasicBlock::removePredecessor(BasicBlock *Pred) { - using cfg::pred_begin; using cfg::pred_end; using cfg::pred_iterator; - assert(find(pred_begin(this), pred_end(this), Pred) != pred_end(this) && + assert(find(pred_begin(), pred_end(), Pred) != pred_end() && "removePredecessor: BB is not a predecessor!"); if (!front()->isPHINode()) return; // Quick exit. - pred_iterator PI(pred_begin(this)), EI(pred_end(this)); + pred_iterator PI(pred_begin()), EI(pred_end()); unsigned max_idx; // Loop over the rest of the predecessors until we run out, or until we find diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp index 03721415051..c241646b636 100644 --- a/lib/VMCore/Dominators.cpp +++ b/lib/VMCore/Dominators.cpp @@ -63,7 +63,8 @@ void cfg::DominatorSet::calcForwardDominatorSet(const Method *M) { df_iterator It = df_begin(M), End = df_end(M); for ( ; It != End; ++It) { const BasicBlock *BB = *It; - pred_const_iterator PI = pred_begin(BB), PEnd = pred_end(BB); + BasicBlock::pred_const_iterator PI = BB->pred_begin(), + PEnd = BB->pred_end(); 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 @@ -114,7 +115,8 @@ cfg::DominatorSet::DominatorSet(Method *M, bool PostDomSet) idf_iterator It = idf_begin(Root), End = idf_end(Root); for ( ; It != End; ++It) { const BasicBlock *BB = *It; - succ_const_iterator PI = succ_begin(BB), PEnd = succ_end(BB); + BasicBlock::succ_const_iterator PI = BB->succ_begin(), + PEnd = BB->succ_end(); 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 @@ -320,8 +322,8 @@ cfg::DominanceFrontier::calcDomFrontier(const DominatorTree &DT, const BasicBlock *BB = Node->getNode(); DomSetType &S = Frontiers[BB]; // The new set to fill in... - for (succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB); - SI != SE; ++SI) { + for (BasicBlock::succ_const_iterator SI = BB->succ_begin(), + SE = BB->succ_end(); SI != SE; ++SI) { // Does Node immediately dominate this successor? if (DT[*SI]->getIDom() != Node) S.insert(*SI); @@ -354,8 +356,8 @@ cfg::DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT, DomSetType &S = Frontiers[BB]; // The new set to fill in... if (!Root) return S; - for (pred_const_iterator SI = pred_begin(BB), SE = pred_end(BB); - SI != SE; ++SI) { + for (BasicBlock::pred_const_iterator SI = BB->pred_begin(), + SE = BB->pred_end(); SI != SE; ++SI) { // Does Node immediately dominate this predeccessor? if (DT[*SI]->getIDom() != Node) S.insert(*SI);