Add a new use_iterator::atEnd() method, which allows us to shrink

pred_iterator down to a single ivar.

llvm-svn: 42859
This commit is contained in:
Chris Lattner 2007-10-11 04:18:11 +00:00
parent f709a1495d
commit fc668d1233
2 changed files with 8 additions and 6 deletions

View File

@ -29,7 +29,6 @@ namespace llvm {
template <class _Ptr, class _USE_iterator> // Predecessor Iterator template <class _Ptr, class _USE_iterator> // Predecessor Iterator
class PredIterator : public forward_iterator<_Ptr, ptrdiff_t> { class PredIterator : public forward_iterator<_Ptr, ptrdiff_t> {
typedef forward_iterator<_Ptr, ptrdiff_t> super; typedef forward_iterator<_Ptr, ptrdiff_t> super;
_Ptr *BB;
_USE_iterator It; _USE_iterator It;
public: public:
typedef PredIterator<_Ptr,_USE_iterator> _Self; typedef PredIterator<_Ptr,_USE_iterator> _Self;
@ -37,26 +36,26 @@ public:
inline void advancePastNonTerminators() { inline void advancePastNonTerminators() {
// Loop to ignore non terminator uses (for example PHI nodes)... // Loop to ignore non terminator uses (for example PHI nodes)...
while (It != BB->use_end() && !isa<TerminatorInst>(*It)) while (!It.atEnd() && !isa<TerminatorInst>(*It))
++It; ++It;
} }
inline PredIterator(_Ptr *bb) : BB(bb), It(bb->use_begin()) { inline PredIterator(_Ptr *bb) : It(bb->use_begin()) {
advancePastNonTerminators(); advancePastNonTerminators();
} }
inline PredIterator(_Ptr *bb, bool) : BB(bb), It(bb->use_end()) {} inline PredIterator(_Ptr *bb, bool) : It(bb->use_end()) {}
inline bool operator==(const _Self& x) const { return It == x.It; } inline bool operator==(const _Self& x) const { return It == x.It; }
inline bool operator!=(const _Self& x) const { return !operator==(x); } inline bool operator!=(const _Self& x) const { return !operator==(x); }
inline pointer operator*() const { inline pointer operator*() const {
assert(It != BB->use_end() && "pred_iterator out of range!"); assert(!It.atEnd() && "pred_iterator out of range!");
return cast<TerminatorInst>(*It)->getParent(); return cast<TerminatorInst>(*It)->getParent();
} }
inline pointer *operator->() const { return &(operator*()); } inline pointer *operator->() const { return &(operator*()); }
inline _Self& operator++() { // Preincrement inline _Self& operator++() { // Preincrement
assert(It != BB->use_end() && "pred_iterator out of range!"); assert(!It.atEnd() && "pred_iterator out of range!");
++It; advancePastNonTerminators(); ++It; advancePastNonTerminators();
return *this; return *this;
} }

View File

@ -120,6 +120,9 @@ public:
bool operator!=(const _Self &x) const { bool operator!=(const _Self &x) const {
return !operator==(x); return !operator==(x);
} }
/// atEnd - return true if this iterator is equal to use_end() on the value.
bool atEnd() const { return U == 0; }
// Iterator traversal: forward iteration only // Iterator traversal: forward iteration only
_Self &operator++() { // Preincrement _Self &operator++() { // Preincrement