2002-06-26 00:13:24 +08:00
|
|
|
//===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===//
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2003-10-21 23:17:13 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2003-10-21 23:17:13 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-06-26 00:13:24 +08: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-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_IR_SYMBOLTABLELISTTRAITSIMPL_H
|
|
|
|
#define LLVM_LIB_IR_SYMBOLTABLELISTTRAITSIMPL_H
|
2002-06-26 00:13:24 +08:00
|
|
|
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/SymbolTableListTraits.h"
|
|
|
|
#include "llvm/IR/ValueSymbolTable.h"
|
2002-06-26 00:13:24 +08:00
|
|
|
|
2003-11-12 06:41:34 +08:00
|
|
|
namespace llvm {
|
|
|
|
|
2007-04-17 11:26:42 +08: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.
|
2015-10-08 04:05:10 +08:00
|
|
|
template <typename ValueSubClass>
|
|
|
|
template <typename TPtr>
|
|
|
|
void SymbolTableListTraits<ValueSubClass>::setSymTabObject(TPtr *Dest,
|
|
|
|
TPtr Src) {
|
2007-04-17 11:26:42 +08:00
|
|
|
// Get the old symtab and value list before doing the assignment.
|
2015-10-07 05:31:07 +08:00
|
|
|
ValueSymbolTable *OldST = getSymTab(getListOwner());
|
2002-06-26 00:13:24 +08:00
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
// Do it.
|
|
|
|
*Dest = Src;
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
// Get the new SymTab object.
|
2015-10-07 05:31:07 +08:00
|
|
|
ValueSymbolTable *NewST = getSymTab(getListOwner());
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
// If there is nothing to do, quick exit.
|
|
|
|
if (OldST == NewST) return;
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
// Move all the elements from the old symtab to the new one.
|
2015-10-08 04:05:10 +08:00
|
|
|
ListTy &ItemList = getList(getListOwner());
|
2007-04-17 11:26:42 +08:00
|
|
|
if (ItemList.empty()) return;
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
if (OldST) {
|
|
|
|
// Remove all entries from the previous symtab.
|
2015-10-07 06:37:47 +08:00
|
|
|
for (auto I = ItemList.begin(); I != ItemList.end(); ++I)
|
2007-04-17 11:26:42 +08:00
|
|
|
if (I->hasName())
|
|
|
|
OldST->removeValueName(I->getValueName());
|
2002-06-26 00:13:24 +08:00
|
|
|
}
|
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
if (NewST) {
|
|
|
|
// Add all of the items to the new symtab.
|
2015-10-07 06:37:47 +08:00
|
|
|
for (auto I = ItemList.begin(); I != ItemList.end(); ++I)
|
2007-04-17 11:26:42 +08:00
|
|
|
if (I->hasName())
|
2015-10-09 07:49:46 +08:00
|
|
|
NewST->reinsertValue(&*I);
|
2002-06-26 00:13:24 +08:00
|
|
|
}
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2002-06-26 00:13:24 +08:00
|
|
|
}
|
|
|
|
|
2015-10-08 04:05:10 +08:00
|
|
|
template <typename ValueSubClass>
|
|
|
|
void SymbolTableListTraits<ValueSubClass>::addNodeToList(ValueSubClass *V) {
|
2014-04-28 12:05:08 +08:00
|
|
|
assert(!V->getParent() && "Value already in a container!!");
|
2007-04-17 12:04:14 +08:00
|
|
|
ItemParentClass *Owner = getListOwner();
|
|
|
|
V->setParent(Owner);
|
2007-04-17 11:26:42 +08:00
|
|
|
if (V->hasName())
|
2015-10-07 05:31:07 +08:00
|
|
|
if (ValueSymbolTable *ST = getSymTab(Owner))
|
2007-04-17 11:26:42 +08:00
|
|
|
ST->reinsertValue(V);
|
2002-06-26 00:13:24 +08:00
|
|
|
}
|
|
|
|
|
2015-10-08 04:05:10 +08:00
|
|
|
template <typename ValueSubClass>
|
|
|
|
void SymbolTableListTraits<ValueSubClass>::removeNodeFromList(
|
|
|
|
ValueSubClass *V) {
|
2014-04-28 12:05:08 +08:00
|
|
|
V->setParent(nullptr);
|
2007-04-17 11:26:42 +08:00
|
|
|
if (V->hasName())
|
2015-10-07 05:31:07 +08:00
|
|
|
if (ValueSymbolTable *ST = getSymTab(getListOwner()))
|
2007-04-17 11:26:42 +08:00
|
|
|
ST->removeValueName(V->getValueName());
|
2002-06-26 00:13:24 +08:00
|
|
|
}
|
|
|
|
|
2015-10-08 04:05:10 +08:00
|
|
|
template <typename ValueSubClass>
|
|
|
|
void SymbolTableListTraits<ValueSubClass>::transferNodesFromList(
|
2016-09-03 09:22:56 +08:00
|
|
|
SymbolTableListTraits &L2, iterator first, iterator last) {
|
2003-10-11 01:54:14 +08:00
|
|
|
// We only have to do work here if transferring instructions between BBs
|
2007-04-17 12:04:14 +08:00
|
|
|
ItemParentClass *NewIP = getListOwner(), *OldIP = L2.getListOwner();
|
2016-08-31 02:00:45 +08:00
|
|
|
assert(NewIP != OldIP && "Expected different list owners");
|
2002-06-26 00:13:24 +08:00
|
|
|
|
2003-10-11 01:54:14 +08:00
|
|
|
// We only have to update symbol table entries if we are transferring the
|
2002-06-26 00:13:24 +08:00
|
|
|
// instructions to a different symtab object...
|
2015-10-07 05:31:07 +08:00
|
|
|
ValueSymbolTable *NewST = getSymTab(NewIP);
|
|
|
|
ValueSymbolTable *OldST = getSymTab(OldIP);
|
2007-04-17 11:26:42 +08:00
|
|
|
if (NewST != OldST) {
|
2002-06-26 00:13:24 +08:00
|
|
|
for (; first != last; ++first) {
|
|
|
|
ValueSubClass &V = *first;
|
|
|
|
bool HasName = V.hasName();
|
2007-04-17 11:26:42 +08:00
|
|
|
if (OldST && HasName)
|
|
|
|
OldST->removeValueName(V.getValueName());
|
2002-06-26 00:13:24 +08:00
|
|
|
V.setParent(NewIP);
|
2007-04-17 11:26:42 +08:00
|
|
|
if (NewST && HasName)
|
|
|
|
NewST->reinsertValue(&V);
|
2002-06-26 00:13:24 +08:00
|
|
|
}
|
|
|
|
} else {
|
2003-10-11 01:54:14 +08:00
|
|
|
// Just transferring between blocks in the same function, simply update the
|
2002-06-26 00:13:24 +08:00
|
|
|
// parent fields in the instructions...
|
|
|
|
for (; first != last; ++first)
|
|
|
|
first->setParent(NewIP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 17:49:53 +08:00
|
|
|
} // End llvm namespace
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2002-06-26 00:13:24 +08:00
|
|
|
#endif
|