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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_LIB_IR_SYMBOLTABLELISTTRAITSIMPL_H
|
|
|
|
#define LLVM_LIB_IR_SYMBOLTABLELISTTRAITSIMPL_H
|
2002-06-25 16:13:24 +00:00
|
|
|
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/SymbolTableListTraits.h"
|
|
|
|
#include "llvm/IR/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) {
|
2014-04-28 04:05:08 +00:00
|
|
|
assert(!V->getParent() && "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) {
|
2014-04-28 04:05:08 +00:00
|
|
|
V->setParent(nullptr);
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 09:49:53 +00:00
|
|
|
} // End llvm namespace
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2002-06-25 16:13:24 +00:00
|
|
|
#endif
|