From: Chris Lattner Date: Tue, 12 Feb 2002 22:35:06 +0000 (+0000) Subject: Pull BasicBlock::pred_* and BasicBlock::succ_* out of BasicBlock.h and into X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=d16aa16cb131267bd866388fba3ca8a0b59be49b;p=oota-llvm.git Pull BasicBlock::pred_* and BasicBlock::succ_* out of BasicBlock.h and into llvm/Support/CFG.h git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1747 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index bcaf1cfc82d..c535f784b78 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -21,17 +21,16 @@ #define LLVM_BASICBLOCK_H #include "llvm/ValueHolder.h" -#include "llvm/InstrTypes.h" -#include +#include "llvm/Value.h" class Instruction; class Method; class TerminatorInst; class MachineCodeForBasicBlock; +template class SuccIterator; // Successor Iterator +template class PredIterator; class BasicBlock : public Value { // Basic blocks are data objects also - template class PredIterator; - template class SuccIterator; public: typedef ValueHolder InstListType; private : @@ -48,14 +47,6 @@ public: typedef std::reverse_iterator const_reverse_iterator; typedef std::reverse_iterator reverse_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 std::string &Name = "", Method *Parent = 0); ~BasicBlock(); @@ -78,6 +69,16 @@ public: inline MachineCodeForBasicBlock& getMachineInstrVec() const { return *machineInstrVec; } + + // Provide a scoped predecessor and successor iterator + typedef PredIterator pred_iterator; + typedef PredIterator pred_const_iterator; + + typedef SuccIterator succ_iterator; + typedef SuccIterator succ_const_iterator; + //===--------------------------------------------------------------------===// // Instruction iterator methods @@ -149,105 +150,6 @@ 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 advancePastConstants() { - // TODO: This is bad - // Loop to ignore constant pool references - while (It != BB->use_end() && !isa(*It)) - ++It; - } - - inline PredIterator(_Ptr *bb) : BB(bb), It(bb->use_begin()) { - advancePastConstants(); - } - 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 { - assert(It != BB->use_end() && "pred_iterator out of range!"); - return cast(*It)->getParent(); - } - inline pointer *operator->() const { return &(operator*()); } - - inline _Self& operator++() { // Preincrement - assert(It != BB->use_end() && "pred_iterator out of range!"); - ++It; advancePastConstants(); - 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); - } }; #endif