1 //===-- llvm/ValueHolderImpl.h - Implement ValueHolder template --*- C++ -*--=//
3 // This file implements the ValueHolder class. This is kept out of line because
4 // it tends to pull in a lot of dependencies on other headers and most files
5 // don't need all that crud.
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_VALUEHOLDER_IMPL_H
10 #define LLVM_VALUEHOLDER_IMPL_H
12 #include "llvm/ValueHolder.h"
13 #include "llvm/SymbolTable.h"
16 template<class ValueSubclass, class ItemParentType, class SymTabType>
17 void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
18 ::setParent(SymTabType *P) {
19 if (Parent) { // Remove all of the items from the old symbol table..
20 SymbolTable *SymTab = Parent->getSymbolTable();
21 for (iterator I = begin(); I != end(); ++I)
22 if ((*I)->hasName()) SymTab->remove(*I);
27 if (Parent) { // Remove all of the items from the old symbol table..
28 SymbolTable *SymTab = Parent->getSymbolTableSure();
29 for (iterator I = begin(); I != end(); ++I)
30 if ((*I)->hasName()) SymTab->insert(*I);
35 template<class ValueSubclass, class ItemParentType, class SymTabType>
36 void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
37 ::remove(ValueSubclass *D) {
38 iterator I(find(begin(), end(), D));
39 assert(I != end() && "Value not in ValueHolder!!");
43 // ValueHolder::remove(iterator &) this removes the element at the location
44 // specified by the iterator, and leaves the iterator pointing to the element
45 // that used to follow the element deleted.
47 template<class ValueSubclass, class ItemParentType, class SymTabType>
48 ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType>
49 ::remove(iterator &DI) {
50 assert(DI != ValueList.end() &&
51 "Trying to remove the end of the value list!!!");
53 ValueSubclass *i = *DI;
54 DI = ValueList.erase(DI);
56 i->setParent(0); // I don't own you anymore... byebye...
58 // You don't get to be in the symbol table anymore... byebye
59 if (i->hasName() && Parent)
60 Parent->getSymbolTable()->remove(i);
65 template<class ValueSubclass, class ItemParentType, class SymTabType>
66 ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType>
68 assert(!ValueList.empty() && "Can't pop_back an empty valuelist!");
69 ValueSubclass *i = ValueList.back();
71 i->setParent(0); // I don't own you anymore... byebye...
73 // You don't get to be in the symbol table anymore... byebye
74 if (i->hasName() && Parent)
75 Parent->getSymbolTable()->remove(i);
81 template<class ValueSubclass, class ItemParentType, class SymTabType>
82 ValueSubclass *ValueHolder<ValueSubclass,ItemParentType,SymTabType>
83 ::remove(const iterator &DI) {
84 assert(DI != ValueList.end() &&
85 "Trying to remove the end of the def list!!!");
87 ValueSubclass *i = *DI;
90 i->setParent(0); // I don't own you anymore... byebye...
92 // You don't get to be in the symbol table anymore... byebye
93 if (i->hasName() && Parent)
94 Parent->getSymbolTable()->remove(i);
99 template<class ValueSubclass, class ItemParentType, class SymTabType>
100 void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
101 ::push_front(ValueSubclass *Inst) {
102 assert(Inst->getParent() == 0 && "Value already has parent!");
103 Inst->setParent(ItemParent);
105 //ValueList.push_front(Inst);
106 ValueList.insert(ValueList.begin(), Inst);
108 if (Inst->hasName() && Parent)
109 Parent->getSymbolTableSure()->insert(Inst);
112 template<class ValueSubclass, class ItemParentType, class SymTabType>
113 void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
114 ::push_back(ValueSubclass *Inst) {
115 assert(Inst->getParent() == 0 && "Value already has parent!");
116 Inst->setParent(ItemParent);
118 ValueList.push_back(Inst);
120 if (Inst->hasName() && Parent)
121 Parent->getSymbolTableSure()->insert(Inst);
124 // ValueHolder::insert - This method inserts the specified value *BEFORE* the
125 // indicated iterator position, and returns an interator to the newly inserted
128 template<class ValueSubclass, class ItemParentType, class SymTabType>
129 ValueHolder<ValueSubclass,ItemParentType,SymTabType>::iterator
130 ValueHolder<ValueSubclass,ItemParentType,SymTabType>
131 ::insert(iterator Pos, ValueSubclass *Inst) {
132 assert(Inst->getParent() == 0 && "Value already has parent!");
133 Inst->setParent(ItemParent);
135 iterator I = ValueList.insert(Pos, Inst);
136 if (Inst->hasName() && Parent)
137 Parent->getSymbolTableSure()->insert(Inst);
141 // ValueHolder::insert - This method inserts the specified _range_ of values
142 // before the 'Pos' iterator, and returns an iterator to the first newly
143 // inserted element. This currently only works for vector iterators...
145 // FIXME: This is not generic so that the code does not have to be around
146 // to be used... is this ok?
148 template<class ValueSubclass, class ItemParentType, class SymTabType>
149 void ValueHolder<ValueSubclass,ItemParentType,SymTabType>
150 ::insert(iterator Pos, // Where to insert
151 iterator First, iterator Last) { // Vector to read insts from
153 // Check to make sure that the values are not already in some valueholder...
155 for (iterator X = First; X != Last; ++X) {
156 assert((*X)->getParent() == 0 &&
157 "Cannot insert into valueholder, value already has a parent!");
158 (*X)->setParent(ItemParent);
161 // Add all of the values to the value holder...
162 ValueList.insert(Pos, First, Last);
164 // Insert all of the instructions in the symbol table...
166 for (;First != Last; ++First)
167 if ((*First)->hasName())
168 Parent->getSymbolTableSure()->insert(*First);