Reverting back to original 1.8 version so I can manually merge in patch.
[llvm-complete.git] / lib / VMCore / SymbolTableListTraitsImpl.h
blob6d70401c89f732df7a4c031dcb7ba347bfb4efff
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
17 #define LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
19 #include "llvm/SymbolTableListTraits.h"
20 #include "llvm/SymbolTable.h"
22 namespace llvm {
24 template<typename ValueSubClass, typename ItemParentClass,typename SymTabClass,
25 typename SubClass>
26 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
27 ::setParent(SymTabClass *STO) {
28 iplist<ValueSubClass> &List = SubClass::getList(ItemParent);
30 // Remove all of the items from the old symtab..
31 if (SymTabObject && !List.empty()) {
32 SymbolTable &SymTab = SymTabObject->getSymbolTable();
33 for (typename iplist<ValueSubClass>::iterator I = List.begin();
34 I != List.end(); ++I)
35 if (I->hasName()) SymTab.remove(I);
38 SymTabObject = STO;
40 // Add all of the items to the new symtab...
41 if (SymTabObject && !List.empty()) {
42 SymbolTable &SymTab = SymTabObject->getSymbolTable();
43 for (typename iplist<ValueSubClass>::iterator I = List.begin();
44 I != List.end(); ++I)
45 if (I->hasName()) SymTab.insert(I);
49 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
50 typename SubClass>
51 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
52 ::addNodeToList(ValueSubClass *V) {
53 assert(V->getParent() == 0 && "Value already in a container!!");
54 V->setParent(ItemParent);
55 if (V->hasName() && SymTabObject)
56 SymTabObject->getSymbolTable().insert(V);
59 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
60 typename SubClass>
61 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
62 ::removeNodeFromList(ValueSubClass *V) {
63 V->setParent(0);
64 if (V->hasName() && SymTabObject)
65 SymTabObject->getSymbolTable().remove(V);
68 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
69 typename SubClass>
70 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
71 ::transferNodesFromList(iplist<ValueSubClass, ilist_traits<ValueSubClass> > &L2,
72 ilist_iterator<ValueSubClass> first,
73 ilist_iterator<ValueSubClass> last) {
74 // We only have to do work here if transferring instructions between BBs
75 ItemParentClass *NewIP = ItemParent, *OldIP = L2.ItemParent;
76 if (NewIP == OldIP) return; // No work to do at all...
78 // We only have to update symbol table entries if we are transferring the
79 // instructions to a different symtab object...
80 SymTabClass *NewSTO = SymTabObject, *OldSTO = L2.SymTabObject;
81 if (NewSTO != OldSTO) {
82 for (; first != last; ++first) {
83 ValueSubClass &V = *first;
84 bool HasName = V.hasName();
85 if (OldSTO && HasName)
86 OldSTO->getSymbolTable().remove(&V);
87 V.setParent(NewIP);
88 if (NewSTO && HasName)
89 NewSTO->getSymbolTable().insert(&V);
91 } else {
92 // Just transferring between blocks in the same function, simply update the
93 // parent fields in the instructions...
94 for (; first != last; ++first)
95 first->setParent(NewIP);
99 } // End llvm namespace
101 #endif