From bb063f38fa8dcfd9b639411fe02b1024c0e4e91f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 1 Apr 2002 17:52:16 +0000 Subject: Add a new replaceWith method useful for replacing instructions git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2088 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/ValueHolderImpl.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/VMCore/ValueHolderImpl.h b/lib/VMCore/ValueHolderImpl.h index 411e2b4466..cbc3e5f558 100644 --- a/lib/VMCore/ValueHolderImpl.h +++ b/lib/VMCore/ValueHolderImpl.h @@ -82,7 +82,7 @@ template ValueSubclass *ValueHolder ::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 return i; } +template +ValueSubclass *ValueHolder +::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 void ValueHolder ::push_front(ValueSubclass *Inst) { -- cgit v1.2.3-70-g09d2