2002-06-25 16:13:24 +00:00
|
|
|
//===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===//
|
2005-04-21 23:48:37 +00:00
|
|
|
//
|
2003-10-21 15:17:13 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:48:37 +00:00
|
|
|
//
|
2003-10-21 15:17:13 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-06-25 16:13:24 +00:00
|
|
|
//
|
|
|
|
// This file implements the stickier parts of the SymbolTableListTraits class,
|
|
|
|
// and is explicitly instantiated where needed to avoid defining all this code
|
|
|
|
// in a widely used header.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
|
|
|
|
#define LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
|
|
|
|
|
|
|
|
#include "llvm/SymbolTableListTraits.h"
|
2007-02-05 20:47:22 +00:00
|
|
|
#include "llvm/ValueSymbolTable.h"
|
2002-06-25 16:13:24 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2007-04-17 03:26:42 +00:00
|
|
|
/// setSymTabObject - This is called when (f.e.) the parent of a basic block
|
|
|
|
/// changes. This requires us to remove all the instruction symtab entries from
|
|
|
|
/// the current function and reinsert them into the new function.
|
|
|
|
template<typename ValueSubClass, typename ItemParentClass>
|
|
|
|
template<typename TPtr>
|
|
|
|
void SymbolTableListTraits<ValueSubClass,ItemParentClass>
|
|
|
|
::setSymTabObject(TPtr *Dest, TPtr Src) {
|
|
|
|
// Get the old symtab and value list before doing the assignment.
|
2007-04-17 04:04:14 +00:00
|
|
|
ValueSymbolTable *OldST = TraitsClass::getSymTab(getListOwner());
|
2002-06-25 16:13:24 +00:00
|
|
|
|
2007-04-17 03:26:42 +00:00
|
|
|
// Do it.
|
|
|
|
*Dest = Src;
|
|
|
|
|
|
|
|
// Get the new SymTab object.
|
2007-04-17 04:04:14 +00:00
|
|
|
ValueSymbolTable *NewST = TraitsClass::getSymTab(getListOwner());
|
2007-04-17 03:26:42 +00:00
|
|
|
|
|
|
|
// If there is nothing to do, quick exit.
|
|
|
|
if (OldST == NewST) return;
|
|
|
|
|
|
|
|
// Move all the elements from the old symtab to the new one.
|
2007-04-17 04:04:14 +00:00
|
|
|
iplist<ValueSubClass> &ItemList = TraitsClass::getList(getListOwner());
|
2007-04-17 03:26:42 +00:00
|
|
|
if (ItemList.empty()) return;
|
|
|
|
|
|
|
|
if (OldST) {
|
|
|
|
// Remove all entries from the previous symtab.
|
|
|
|
for (typename iplist<ValueSubClass>::iterator I = ItemList.begin();
|
|
|
|
I != ItemList.end(); ++I)
|
|
|
|
if (I->hasName())
|
|
|
|
OldST->removeValueName(I->getValueName());
|
2002-06-25 16:13:24 +00:00
|
|
|
}
|
|
|
|
|
2007-04-17 03:26:42 +00:00
|
|
|
if (NewST) {
|
|
|
|
// Add all of the items to the new symtab.
|
|
|
|
for (typename iplist<ValueSubClass>::iterator I = ItemList.begin();
|
|
|
|
I != ItemList.end(); ++I)
|
|
|
|
if (I->hasName())
|
|
|
|
NewST->reinsertValue(I);
|
2002-06-25 16:13:24 +00:00
|
|
|
}
|
2007-04-17 03:26:42 +00:00
|
|
|
|
2002-06-25 16:13:24 +00:00
|
|
|
}
|
|
|
|
|
2007-04-17 03:26:42 +00:00
|
|
|
template<typename ValueSubClass, typename ItemParentClass>
|
|
|
|
void SymbolTableListTraits<ValueSubClass,ItemParentClass>
|
2002-06-25 16:13:24 +00:00
|
|
|
::addNodeToList(ValueSubClass *V) {
|
|
|
|
assert(V->getParent() == 0 && "Value already in a container!!");
|
2007-04-17 04:04:14 +00:00
|
|
|
ItemParentClass *Owner = getListOwner();
|
|
|
|
V->setParent(Owner);
|
2007-04-17 03:26:42 +00:00
|
|
|
if (V->hasName())
|
2007-04-17 04:04:14 +00:00
|
|
|
if (ValueSymbolTable *ST = TraitsClass::getSymTab(Owner))
|
2007-04-17 03:26:42 +00:00
|
|
|
ST->reinsertValue(V);
|
2002-06-25 16:13:24 +00:00
|
|
|
}
|
|
|
|
|
2007-04-17 03:26:42 +00:00
|
|
|
template<typename ValueSubClass, typename ItemParentClass>
|
|
|
|
void SymbolTableListTraits<ValueSubClass,ItemParentClass>
|
2002-06-25 16:13:24 +00:00
|
|
|
::removeNodeFromList(ValueSubClass *V) {
|
|
|
|
V->setParent(0);
|
2007-04-17 03:26:42 +00:00
|
|
|
if (V->hasName())
|
2007-04-17 04:04:14 +00:00
|
|
|
if (ValueSymbolTable *ST = TraitsClass::getSymTab(getListOwner()))
|
2007-04-17 03:26:42 +00:00
|
|
|
ST->removeValueName(V->getValueName());
|
2002-06-25 16:13:24 +00:00
|
|
|
}
|
|
|
|
|
2007-04-17 03:26:42 +00:00
|
|
|
template<typename ValueSubClass, typename ItemParentClass>
|
|
|
|
void SymbolTableListTraits<ValueSubClass,ItemParentClass>
|
2008-07-28 21:51:04 +00:00
|
|
|
::transferNodesFromList(ilist_traits<ValueSubClass> &L2,
|
2002-06-25 16:13:24 +00:00
|
|
|
ilist_iterator<ValueSubClass> first,
|
|
|
|
ilist_iterator<ValueSubClass> last) {
|
2003-10-10 17:54:14 +00:00
|
|
|
// We only have to do work here if transferring instructions between BBs
|
2007-04-17 04:04:14 +00:00
|
|
|
ItemParentClass *NewIP = getListOwner(), *OldIP = L2.getListOwner();
|
2002-06-25 16:13:24 +00:00
|
|
|
if (NewIP == OldIP) return; // No work to do at all...
|
|
|
|
|
2003-10-10 17:54:14 +00:00
|
|
|
// We only have to update symbol table entries if we are transferring the
|
2002-06-25 16:13:24 +00:00
|
|
|
// instructions to a different symtab object...
|
2007-04-17 04:04:14 +00:00
|
|
|
ValueSymbolTable *NewST = TraitsClass::getSymTab(NewIP);
|
2007-04-17 03:26:42 +00:00
|
|
|
ValueSymbolTable *OldST = TraitsClass::getSymTab(OldIP);
|
|
|
|
if (NewST != OldST) {
|
2002-06-25 16:13:24 +00:00
|
|
|
for (; first != last; ++first) {
|
|
|
|
ValueSubClass &V = *first;
|
|
|
|
bool HasName = V.hasName();
|
2007-04-17 03:26:42 +00:00
|
|
|
if (OldST && HasName)
|
|
|
|
OldST->removeValueName(V.getValueName());
|
2002-06-25 16:13:24 +00:00
|
|
|
V.setParent(NewIP);
|
2007-04-17 03:26:42 +00:00
|
|
|
if (NewST && HasName)
|
|
|
|
NewST->reinsertValue(&V);
|
2002-06-25 16:13:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-10-10 17:54:14 +00:00
|
|
|
// Just transferring between blocks in the same function, simply update the
|
2002-06-25 16:13:24 +00:00
|
|
|
// parent fields in the instructions...
|
|
|
|
for (; first != last; ++first)
|
|
|
|
first->setParent(NewIP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-06-25 16:13:24 +00:00
|
|
|
#endif
|