LLVM API Documentation

SymbolTableListTraitsImpl.h

Go to the documentation of this file.
00001 //===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the stickier parts of the SymbolTableListTraits class,
00011 // and is explicitly instantiated where needed to avoid defining all this code
00012 // in a widely used header.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
00017 #define LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
00018 
00019 #include "llvm/SymbolTableListTraits.h"
00020 #include "llvm/SymbolTable.h"
00021 
00022 namespace llvm {
00023 
00024 template<typename ValueSubClass, typename ItemParentClass,typename SymTabClass,
00025          typename SubClass>
00026 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
00027 ::setParent(SymTabClass *STO) {
00028   iplist<ValueSubClass> &List = SubClass::getList(ItemParent);
00029 
00030   // Remove all of the items from the old symtab..
00031   if (SymTabObject && !List.empty()) {
00032     SymbolTable &SymTab = SymTabObject->getSymbolTable();
00033     for (typename iplist<ValueSubClass>::iterator I = List.begin();
00034          I != List.end(); ++I)
00035       if (I->hasName()) SymTab.remove(I);
00036   }
00037 
00038   SymTabObject = STO;
00039 
00040   // Add all of the items to the new symtab...
00041   if (SymTabObject && !List.empty()) {
00042     SymbolTable &SymTab = SymTabObject->getSymbolTable();
00043     for (typename iplist<ValueSubClass>::iterator I = List.begin();
00044          I != List.end(); ++I)
00045       if (I->hasName()) SymTab.insert(I);
00046   }
00047 }
00048 
00049 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
00050          typename SubClass>
00051 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
00052 ::addNodeToList(ValueSubClass *V) {
00053   assert(V->getParent() == 0 && "Value already in a container!!");
00054   V->setParent(ItemParent);
00055   if (V->hasName() && SymTabObject)
00056     SymTabObject->getSymbolTable().insert(V);
00057 }
00058 
00059 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
00060          typename SubClass>
00061 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
00062 ::removeNodeFromList(ValueSubClass *V) {
00063   V->setParent(0);
00064   if (V->hasName() && SymTabObject)
00065     SymTabObject->getSymbolTable().remove(V);
00066 }
00067 
00068 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
00069          typename SubClass>
00070 void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
00071 ::transferNodesFromList(iplist<ValueSubClass, ilist_traits<ValueSubClass> > &L2,
00072                         ilist_iterator<ValueSubClass> first,
00073                         ilist_iterator<ValueSubClass> last) {
00074   // We only have to do work here if transferring instructions between BBs
00075   ItemParentClass *NewIP = ItemParent, *OldIP = L2.ItemParent;
00076   if (NewIP == OldIP) return;  // No work to do at all...
00077 
00078   // We only have to update symbol table entries if we are transferring the
00079   // instructions to a different symtab object...
00080   SymTabClass *NewSTO = SymTabObject, *OldSTO = L2.SymTabObject;
00081   if (NewSTO != OldSTO) {
00082     for (; first != last; ++first) {
00083       ValueSubClass &V = *first;
00084       bool HasName = V.hasName();
00085       if (OldSTO && HasName)
00086         OldSTO->getSymbolTable().remove(&V);
00087       V.setParent(NewIP);
00088       if (NewSTO && HasName)
00089         NewSTO->getSymbolTable().insert(&V);
00090     }
00091   } else {
00092     // Just transferring between blocks in the same function, simply update the
00093     // parent fields in the instructions...
00094     for (; first != last; ++first)
00095       first->setParent(NewIP);
00096   }
00097 }
00098 
00099 } // End llvm namespace
00100 
00101 #endif