Fixes for BB iterators, additional methods added for DCE pass

llvm-svn: 8
This commit is contained in:
Chris Lattner 2001-06-07 16:58:36 +00:00
parent 2cafe60b3b
commit e358b22776
5 changed files with 44 additions and 18 deletions

View File

@ -148,7 +148,16 @@ public:
typedef bidirectional_iterator_tag iterator_category;
typedef _Ptr pointer;
inline PredIterator(_Ptr BB) : ThisBB(BB), It(BB->use_begin()) {}
inline void advancePastConstPool() {
// Loop to ignore constant pool references
while (It != ThisBB->use_end() &&
((*It)->getValueType() != Value::InstructionVal))
++It;
}
inline PredIterator(_Ptr BB) : ThisBB(BB), It(BB->use_begin()) {
advancePastConstPool();
}
inline PredIterator(_Ptr BB, bool) : ThisBB(BB), It(BB->use_end()) {}
inline bool operator==(const _Self& x) const { return It == x.It; }
@ -161,13 +170,7 @@ public:
inline pointer *operator->() const { return &(operator*()); }
inline _Self& operator++() { // Preincrement
do { // Loop to ignore constant pool references
++It;
} while (It != ThisBB->use_end() &&
((*It)->getValueType() != Value::ConstantVal));
// DOES THIS WORK???
//((*It)->getValueType() != Value::BasicBlockVal));
++It; advancePastConstPool();
return *this;
}

View File

@ -65,7 +65,7 @@ public:
typedef list<User*>::iterator use_iterator;
typedef list<User*>::const_iterator use_const_iterator;
inline bool use_size() const { return Uses.size(); }
inline unsigned use_size() const { return Uses.size(); }
inline bool use_empty() const { return Uses.empty(); }
inline use_iterator use_begin() { return Uses.begin(); }
inline use_const_iterator use_begin() const { return Uses.begin(); }

View File

@ -65,10 +65,9 @@ public:
inline const_iterator end() const { return ValueList.end(); }
void delete_all() { // Delete all removes and deletes all elements
// TODO: REMOVE FROM END OF VECTOR!!!
while (begin() != end()) {
iterator I = begin();
delete remove(I); // Delete all instructions...
while (!empty()) {
iterator it = end();
delete remove(--it); // Delete all instructions...
}
}
@ -76,8 +75,9 @@ public:
// specified by the iterator, and leaves the iterator pointing to the element
// that used to follow the element deleted.
//
ValueSubclass *remove(iterator &DI); // Defined in ValueHolderImpl.h
void remove(ValueSubclass *D); // Defined in ValueHolderImpl.h
ValueSubclass *remove(iterator &DI); // Defined in ValueHolderImpl.h
ValueSubclass *remove(const iterator &DI); // Defined in ValueHolderImpl.h
void remove(ValueSubclass *D); // Defined in ValueHolderImpl.h
inline void push_front(ValueSubclass *Inst); // Defined in ValueHolderImpl.h
inline void push_back(ValueSubclass *Inst); // Defined in ValueHolderImpl.h

View File

@ -50,7 +50,12 @@ public:
virtual bool setOperand(unsigned i, Value *Val);
virtual string getOpcode() const { return "phi"; }
// addIncoming - Add an incoming value to the end of the PHI list
void addIncoming(Value *D);
// removeIncomingValue - Remove an incoming value. This is useful if a
// predecessor basic block is deleted. The value removed is returned.
Value *removeIncomingValue(unsigned idx);
};

View File

@ -38,9 +38,9 @@ void ValueHolder<ValueSubclass,ItemParentType>::remove(ValueSubclass *D) {
remove(I);
}
// ValueHolder::remove(iterator &) this removes the element at the location specified
// by the iterator, and leaves the iterator pointing to the element that used to follow
// the element deleted.
// ValueHolder::remove(iterator &) this removes the element at the location
// specified by the iterator, and leaves the iterator pointing to the element
// that used to follow the element deleted.
//
template<class ValueSubclass, class ItemParentType>
ValueSubclass *ValueHolder<ValueSubclass,ItemParentType>::remove(iterator &DI) {
@ -59,6 +59,24 @@ ValueSubclass *ValueHolder<ValueSubclass,ItemParentType>::remove(iterator &DI) {
return i;
}
template<class ValueSubclass, class ItemParentType>
ValueSubclass *ValueHolder<ValueSubclass,ItemParentType>
::remove(const iterator &DI) {
assert(DI != ValueList.end() &&
"Trying to remove the end of the def list!!!");
ValueSubclass *i = *DI;
ValueList.erase(DI);
i->setParent(0); // I don't own you anymore... byebye...
// You don't get to be in the symbol table anymore... byebye
if (i->hasName() && Parent)
Parent->getSymbolTable()->remove(i);
return i;
}
template<class ValueSubclass, class ItemParentType>
void ValueHolder<ValueSubclass,ItemParentType>::push_front(ValueSubclass *Inst) {
assert(Inst->getParent() == 0 && "Value already has parent!");