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