Add a bunch of new Alpha Intrinsics for Rahul Joshi
[oota-llvm.git] / lib / VMCore / SymbolTableListTraitsImpl.h
1 //===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===//
2 //
3 // This file implements the stickier parts of the SymbolTableListTraits class,
4 // and is explicitly instantiated where needed to avoid defining all this code
5 // in a widely used header.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
10 #define LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
11
12 #include "llvm/SymbolTableListTraits.h"
13 #include "llvm/SymbolTable.h"
14
15 template<typename ValueSubClass, typename ItemParentClass,typename SymTabClass,
16          typename SubClass>
17 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
18 ::setParent(SymTabClass *STO) {
19   iplist<ValueSubClass> &List = SubClass::getList(ItemParent);
20
21   // Remove all of the items from the old symtab..
22   if (SymTabObject && !List.empty()) {
23     SymbolTable &SymTab = SymTabObject->getSymbolTable();
24     for (typename iplist<ValueSubClass>::iterator I = List.begin();
25          I != List.end(); ++I)
26       if (I->hasName()) SymTab.remove(I);
27   }
28
29   SymTabObject = STO;
30
31   // Add all of the items to the new symtab...
32   if (SymTabObject && !List.empty()) {
33     SymbolTable &SymTab = SymTabObject->getSymbolTable();
34     for (typename iplist<ValueSubClass>::iterator I = List.begin();
35          I != List.end(); ++I)
36       if (I->hasName()) SymTab.insert(I);
37   }
38 }
39
40 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
41          typename SubClass>
42 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
43 ::addNodeToList(ValueSubClass *V) {
44   assert(V->getParent() == 0 && "Value already in a container!!");
45   V->setParent(ItemParent);
46   if (V->hasName() && SymTabObject)
47     SymTabObject->getSymbolTable().insert(V);
48 }
49
50 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
51          typename SubClass>
52 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
53 ::removeNodeFromList(ValueSubClass *V) {
54   V->setParent(0);
55   if (V->hasName() && SymTabObject)
56     SymTabObject->getSymbolTable().remove(V);
57 }
58
59 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
60          typename SubClass>
61 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
62 ::transferNodesFromList(iplist<ValueSubClass, ilist_traits<ValueSubClass> > &L2,
63                         ilist_iterator<ValueSubClass> first,
64                         ilist_iterator<ValueSubClass> last) {
65   // We only have to do work here if transfering instructions between BB's
66   ItemParentClass *NewIP = ItemParent, *OldIP = L2.ItemParent;
67   if (NewIP == OldIP) return;  // No work to do at all...
68
69   // We only have to update symbol table entries if we are transfering the
70   // instructions to a different symtab object...
71   SymTabClass *NewSTO = SymTabObject, *OldSTO = L2.SymTabObject;
72   if (NewSTO != OldSTO) {
73     for (; first != last; ++first) {
74       ValueSubClass &V = *first;
75       bool HasName = V.hasName();
76       if (OldSTO && HasName)
77         OldSTO->getSymbolTable().remove(&V);
78       V.setParent(NewIP);
79       if (NewSTO && HasName)
80         NewSTO->getSymbolTable().insert(&V);
81     }
82   } else {
83     // Just transfering between blocks in the same function, simply update the
84     // parent fields in the instructions...
85     for (; first != last; ++first)
86       first->setParent(NewIP);
87   }
88 }
89
90 #endif