Fixes for BB iterators, additional methods added for DCE pass
authorChris Lattner <sabre@nondot.org>
Thu, 7 Jun 2001 16:58:36 +0000 (16:58 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 7 Jun 2001 16:58:36 +0000 (16:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/BasicBlock.h
include/llvm/Value.h
include/llvm/ValueHolder.h
include/llvm/iOther.h
lib/VMCore/ValueHolderImpl.h

index 6873ef2deb73ce231634915083243e52a9d527cb..5230e87d8df42cb80d7d5f289c8b9fdf8c5beaaf 100644 (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; 
     }
 
index d751eb1c6a8e960b689b895efe3f3b7d58013cb7..b10ea95b1847d7a146218cd5d38467f1879ce74a 100644 (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(); }
index 318419f139e4ddf41286e03a6fcaae5332752be1..8e18fc7ffdaafe4876a90ac8f29adf379295ef08 100644 (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
index 4c06b4fdd8944e897b510485f8e95eb09e9c37a3..b66e4d4217cce3bdf78bbb1273fe90f97a40b20b 100644 (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);
 };
 
 
index ecafd470f188a2f726c4a740aefa5a5558584414..9ca5d949267343dcd7a98d48f8f588d77564d241 100644 (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!");