Add a new replaceWith method useful for replacing instructions
authorChris Lattner <sabre@nondot.org>
Mon, 1 Apr 2002 17:52:16 +0000 (17:52 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 1 Apr 2002 17:52:16 +0000 (17:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2088 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ValueHolder.h
lib/VMCore/ValueHolderImpl.h

index 905b2ad326a4f78f7163c908e6fb764adcd9c341..6e251ff5c17aa6583637dd8fc9e0aa0d9fd8ade2 100644 (file)
@@ -90,6 +90,12 @@ public:
   void           remove(ValueSubclass *D);     // Defined in ValueHolderImpl.h
   ValueSubclass *pop_back();                   // Defined in ValueHolderImpl.h
 
+  // replaceWith - This removes the element pointed to by 'Where', and inserts
+  // NewValue in it's place.  The old value is returned.  'Where' must be a
+  // valid iterator!
+  //
+  ValueSubclass *replaceWith(iterator &Where, ValueSubclass *NewValue);
+
   // delete_span - Remove the elements from begin to end, deleting them as we
   // go.  This leaves the iterator pointing to the element that used to be end.
   //
index 411e2b446649f8778a547fc63c89702c532628a6..cbc3e5f55886dc6f54feeaf16a1e206787708d16 100644 (file)
@@ -82,7 +82,7 @@ template<class ValueSubclass, class ItemParentType, class SymTabType>
 ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType>
 ::remove(const iterator &DI) {
   assert(DI != ValueList.end() && 
-         "Trying to remove the end of the def list!!!");
+         "Trying to remove the end of the value holder list!!!");
   
   ValueSubclass *i = *DI;
   ValueList.erase(DI);
@@ -96,6 +96,32 @@ ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType>
   return i;
 }
 
+template<class ValueSubclass, class ItemParentType, class SymTabType>
+ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType>
+::replaceWith(iterator &DI, ValueSubclass *NewVal) {
+  assert(DI != ValueList.end() && 
+         "Trying to replace the end of the value holder list!!!");
+
+  // Remove the value from the current container...
+  ValueSubclass *Ret = *DI;
+  Ret->setParent(0);  // I don't own you anymore... byebye...
+  
+  // You don't get to be in the symbol table anymore... byebye
+  if (Ret->hasName() && Parent)
+    Parent->getSymbolTable()->remove(Ret);
+
+  // Insert the new value into the container...
+  assert(NewVal->getParent() == 0 && "Value already has parent!");
+  NewVal->setParent(ItemParent);
+  *DI = NewVal;
+  if (NewVal->hasName() && Parent)
+    Parent->getSymbolTableSure()->insert(NewVal);
+  return Ret;
+}
+
+
 template<class ValueSubclass, class ItemParentType, class SymTabType>
 void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
 ::push_front(ValueSubclass *Inst) {