Add an insert method to VAlueHolder to allow batch insertion
authorChris Lattner <sabre@nondot.org>
Fri, 29 Mar 2002 05:49:37 +0000 (05:49 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 29 Mar 2002 05:49:37 +0000 (05:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2038 91177308-0d34-0410-b5e6-96231b3b80d8

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

index b75d243a3d4521f8c79e2c6a406bf130967e011f..905b2ad326a4f78f7163c908e6fb764adcd9c341 100644 (file)
@@ -111,6 +111,16 @@ public:
   // value.
   //
   iterator insert(iterator Pos, ValueSubclass *Inst);
+
+  // ValueHolder::insert - This method inserts the specified _range_ of values
+  // before the 'Pos' iterator.  This currently only works for vector
+  // iterators...
+  //
+  // FIXME: This is not generic so that the code does not have to be around
+  // to be used... is this ok?
+  //
+  void insert(iterator Pos,                     // Where to insert
+              iterator First, iterator Last);   // Vector to read insts from
 };
 
 #endif
index fff88fd53b98767d0c9e186f8be0de598571d303..411e2b446649f8778a547fc63c89702c532628a6 100644 (file)
@@ -138,4 +138,34 @@ ValueHolder<ValueSubclass,ItemParentType,SymTabType>
   return I;
 }
 
+// ValueHolder::insert - This method inserts the specified _range_ of values
+// before the 'Pos' iterator, and returns an iterator to the first newly
+// inserted element.  This currently only works for vector iterators...
+//
+// FIXME: This is not generic so that the code does not have to be around
+// to be used... is this ok?
+//
+template<class ValueSubclass, class ItemParentType, class SymTabType>
+void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
+::insert(iterator Pos,                     // Where to insert
+         iterator First, iterator Last) {   // Vector to read insts from
+
+  // Check to make sure that the values are not already in some valueholder...
+  
+  for (iterator X = First; X != Last; ++X) {
+    assert((*X)->getParent() == 0 &&
+           "Cannot insert into valueholder, value already has a parent!");
+    (*X)->setParent(ItemParent);
+  }
+
+  // Add all of the values to the value holder...
+  ValueList.insert(Pos, First, Last);
+
+  // Insert all of the instructions in the symbol table...
+  if (Parent)
+    for (;First != Last; ++First)
+      if ((*First)->hasName())
+        Parent->getSymbolTableSure()->insert(*First);
+}
+
 #endif