aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-02-05 20:47:22 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-02-05 20:47:22 +0000
commitef9b9a793949469cdaa4ab6d0173136229dcab7b (patch)
tree137b30d24ba219e5e745a11abb3807a9c4964aaa /lib/VMCore
parent15468bfc22302b4f79300252425d74cd6865f8b1 (diff)
For PR411:
This patch replaces the SymbolTable class with ValueSymbolTable which does not support types planes. This means that all symbol names in LLVM must now be unique. The patch addresses the necessary changes to deal with this and removes code no longer needed as a result. This completes the bulk of the changes for this PR. Some cleanup patches will follow. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33918 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/AsmWriter.cpp2
-rw-r--r--lib/VMCore/Constants.cpp2
-rw-r--r--lib/VMCore/Function.cpp6
-rw-r--r--lib/VMCore/Globals.cpp1
-rw-r--r--lib/VMCore/Instruction.cpp1
-rw-r--r--lib/VMCore/Module.cpp112
-rw-r--r--lib/VMCore/SymbolTable.cpp336
-rw-r--r--lib/VMCore/SymbolTableListTraitsImpl.h6
-rw-r--r--lib/VMCore/Type.cpp1
-rw-r--r--lib/VMCore/Value.cpp15
-rw-r--r--lib/VMCore/ValueSymbolTable.cpp27
-rw-r--r--lib/VMCore/Verifier.cpp30
12 files changed, 58 insertions, 481 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index f13a140b63..e834c53db3 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -24,7 +24,7 @@
#include "llvm/Instruction.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/ValueSymbolTable.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h"
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 79673f034d..8a6e11de3a 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -16,7 +16,6 @@
#include "llvm/DerivedTypes.h"
#include "llvm/GlobalValue.h"
#include "llvm/Instructions.h"
-#include "llvm/SymbolTable.h"
#include "llvm/Module.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Compiler.h"
@@ -24,6 +23,7 @@
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MathExtras.h"
#include <algorithm>
+#include <map>
using namespace llvm;
//===----------------------------------------------------------------------===//
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index cf8fcdec6a..cc0cefad66 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -7,8 +7,7 @@
//
//===----------------------------------------------------------------------===//
//
-// This file implements the Function & GlobalVariable classes for the VMCore
-// library.
+// This file implements the Function class for the VMCore library.
//
//===----------------------------------------------------------------------===//
@@ -82,7 +81,7 @@ Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
BasicBlocks.setParent(this);
ArgumentList.setItemParent(this);
ArgumentList.setParent(this);
- SymTab = new SymbolTable();
+ SymTab = new ValueSymbolTable();
assert((getReturnType()->isFirstClassType() ||getReturnType() == Type::VoidTy)
&& "LLVM functions cannot return aggregate values!");
@@ -138,7 +137,6 @@ void Function::eraseFromParent() {
getParent()->getFunctionList().erase(this);
}
-
// dropAllReferences() - This function causes all the subinstructions to "let
// go" of all references that they are maintaining. This allows one to
// 'delete' a whole class at a time, even though there may be circular
diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp
index e49f47766f..327e2ad9aa 100644
--- a/lib/VMCore/Globals.cpp
+++ b/lib/VMCore/Globals.cpp
@@ -15,7 +15,6 @@
#include "llvm/GlobalVariable.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
-#include "llvm/SymbolTable.h"
#include "llvm/Support/LeakDetector.h"
using namespace llvm;
diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp
index b2eb87d49e..6b2babaecc 100644
--- a/lib/VMCore/Instruction.cpp
+++ b/lib/VMCore/Instruction.cpp
@@ -14,7 +14,6 @@
#include "llvm/Type.h"
#include "llvm/Instructions.h"
#include "llvm/Function.h"
-#include "llvm/SymbolTable.h"
#include "llvm/Support/LeakDetector.h"
using namespace llvm;
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index efa6e6c7c0..163d8d2ac1 100644
--- a/lib/VMCore/Module.cpp
+++ b/lib/VMCore/Module.cpp
@@ -69,7 +69,7 @@ Module::Module(const std::string &MID)
FunctionList.setParent(this);
GlobalList.setItemParent(this);
GlobalList.setParent(this);
- ValSymTab = new SymbolTable();
+ ValSymTab = new ValueSymbolTable();
TypeSymTab = new TypeSymbolTable();
}
@@ -132,15 +132,19 @@ Module::PointerSize Module::getPointerSize() const {
// Methods for easy access to the functions in the module.
//
+// getOrInsertFunction - Look up the specified function in the module symbol
+// table. If it does not exist, add a prototype for the function and return
+// it. This is nice because it allows most passes to get away with not handling
+// the symbol table directly for this common task.
+//
Constant *Module::getOrInsertFunction(const std::string &Name,
const FunctionType *Ty) {
- SymbolTable &SymTab = getValueSymbolTable();
+ ValueSymbolTable &SymTab = getValueSymbolTable();
- // See if we have a definitions for the specified function already.
- Function *F =
- dyn_cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name));
+ // See if we have a definition for the specified function already.
+ Function *F = dyn_cast_or_null<Function>(SymTab.lookup(Name));
if (F == 0) {
- // Nope, add it.
+ // Nope, add it
Function *New = new Function(Ty, GlobalVariable::ExternalLinkage, Name);
FunctionList.push_back(New);
return New; // Return the new prototype.
@@ -149,7 +153,7 @@ Constant *Module::getOrInsertFunction(const std::string &Name,
// Okay, the function exists. Does it have externally visible linkage?
if (F->hasInternalLinkage()) {
// Rename the function.
- F->setName(SymTab.getUniqueName(F->getType(), F->getName()));
+ F->setName(SymTab.getUniqueName(F->getName()));
// Retry, now there won't be a conflict.
return getOrInsertFunction(Name, Ty);
}
@@ -188,73 +192,9 @@ Constant *Module::getOrInsertFunction(const std::string &Name,
// getFunction - Look up the specified function in the module symbol table.
// If it does not exist, return null.
//
-Function *Module::getFunction(const std::string &Name, const FunctionType *Ty) {
- SymbolTable &SymTab = getValueSymbolTable();
- return cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name));
-}
-
-
-/// getMainFunction - This function looks up main efficiently. This is such a
-/// common case, that it is a method in Module. If main cannot be found, a
-/// null pointer is returned.
-///
-Function *Module::getMainFunction() {
- std::vector<const Type*> Params;
-
- // int main(void)...
- if (Function *F = getFunction("main", FunctionType::get(Type::Int32Ty,
- Params, false)))
- return F;
-
- // void main(void)...
- if (Function *F = getFunction("main", FunctionType::get(Type::VoidTy,
- Params, false)))
- return F;
-
- Params.push_back(Type::Int32Ty);
-
- // int main(int argc)...
- if (Function *F = getFunction("main", FunctionType::get(Type::Int32Ty,
- Params, false)))
- return F;
-
- // void main(int argc)...
- if (Function *F = getFunction("main", FunctionType::get(Type::VoidTy,
- Params, false)))
- return F;
-
- for (unsigned i = 0; i != 2; ++i) { // Check argv and envp
- Params.push_back(PointerType::get(PointerType::get(Type::Int8Ty)));
-
- // int main(int argc, char **argv)...
- if (Function *F = getFunction("main", FunctionType::get(Type::Int32Ty,
- Params, false)))
- return F;
-
- // void main(int argc, char **argv)...
- if (Function *F = getFunction("main", FunctionType::get(Type::VoidTy,
- Params, false)))
- return F;
- }
-
- // Ok, try to find main the hard way...
- return getNamedFunction("main");
-}
-
-/// getNamedFunction - Return the first function in the module with the
-/// specified name, of arbitrary type. This method returns null if a function
-/// with the specified name is not found.
-///
-Function *Module::getNamedFunction(const std::string &Name) const {
- // Loop over all of the functions, looking for the function desired
- const Function *Found = 0;
- for (const_iterator I = begin(), E = end(); I != E; ++I)
- if (I->getName() == Name)
- if (I->isDeclaration())
- Found = I;
- else
- return const_cast<Function*>(&(*I));
- return const_cast<Function*>(Found); // Non-external function not found...
+Function *Module::getFunction(const std::string &Name) const {
+ const ValueSymbolTable &SymTab = getValueSymbolTable();
+ return dyn_cast_or_null<Function>(SymTab.lookup(Name));
}
//===----------------------------------------------------------------------===//
@@ -269,31 +209,15 @@ Function *Module::getNamedFunction(const std::string &Name) const {
/// have InternalLinkage. By default, these types are not returned.
///
GlobalVariable *Module::getGlobalVariable(const std::string &Name,
- const Type *Ty, bool AllowInternal) {
- if (Value *V = getValueSymbolTable().lookup(PointerType::get(Ty), Name)) {
- GlobalVariable *Result = cast<GlobalVariable>(V);
- if (AllowInternal || !Result->hasInternalLinkage())
+ bool AllowInternal) const {
+ if (Value *V = ValSymTab->lookup(Name)) {
+ GlobalVariable *Result = dyn_cast<GlobalVariable>(V);
+ if (Result && (AllowInternal || !Result->hasInternalLinkage()))
return Result;
}
return 0;
}
-/// getNamedGlobal - Return the first global variable in the module with the
-/// specified name, of arbitrary type. This method returns null if a global
-/// with the specified name is not found.
-///
-GlobalVariable *Module::getNamedGlobal(const std::string &Name) const {
- // FIXME: This would be much faster with a symbol table that doesn't
- // discriminate based on type!
- for (const_global_iterator I = global_begin(), E = global_end();
- I != E; ++I)
- if (I->getName() == Name)
- return const_cast<GlobalVariable*>(&(*I));
- return 0;
-}
-
-
-
//===----------------------------------------------------------------------===//
// Methods for easy access to the types in the module.
//
diff --git a/lib/VMCore/SymbolTable.cpp b/lib/VMCore/SymbolTable.cpp
deleted file mode 100644
index 2edd3eb875..0000000000
--- a/lib/VMCore/SymbolTable.cpp
+++ /dev/null
@@ -1,336 +0,0 @@
-//===-- SymbolTable.cpp - Implement the SymbolTable class -----------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file was developed by the LLVM research group and revised by Reid
-// Spencer. It is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the SymbolTable class for the VMCore library.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/SymbolTable.h"
-#include "llvm/DerivedTypes.h"
-#include "llvm/Module.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/Support/Debug.h"
-#include <algorithm>
-using namespace llvm;
-
-#define DEBUG_SYMBOL_TABLE 0
-#define DEBUG_ABSTYPE 0
-
-SymbolTable::~SymbolTable() {
- // TODO: FIXME: BIG ONE: This doesn't unreference abstract types for the
- // planes that could still have entries!
-
-#ifndef NDEBUG // Only do this in -g mode...
- bool LeftoverValues = true;
- for (plane_iterator PI = pmap.begin(); PI != pmap.end(); ++PI) {
- for (value_iterator VI = PI->second.begin(); VI != PI->second.end(); ++VI)
- if (!isa<Constant>(VI->second) ) {
- DOUT << "Value still in symbol table! Type = '"
- << PI->first->getDescription() << "' Name = '"
- << VI->first << "'\n";
- LeftoverValues = false;
- }
- }
-
- assert(LeftoverValues && "Values remain in symbol table!");
-#endif
-}
-
-// getUniqueName - Given a base name, return a string that is either equal to
-// it (or derived from it) that does not already occur in the symbol table for
-// the specified type.
-//
-std::string SymbolTable::getUniqueName(const Type *Ty,
- const std::string &BaseName) const {
- // Find the plane
- plane_const_iterator PI = pmap.find(Ty);
- if (PI == pmap.end()) return BaseName;
-
- std::string TryName = BaseName;
- const ValueMap& vmap = PI->second;
- value_const_iterator End = vmap.end();
-
- // See if the name exists
- while (vmap.find(TryName) != End) // Loop until we find a free
- TryName = BaseName + utostr(++LastUnique); // name in the symbol table
- return TryName;
-}
-
-
-// lookup a value - Returns null on failure...
-Value *SymbolTable::lookup(const Type *Ty, const std::string &Name) const {
- plane_const_iterator PI = pmap.find(Ty);
- if (PI != pmap.end()) { // We have symbols in that plane.
- value_const_iterator VI = PI->second.find(Name);
- if (VI != PI->second.end()) // and the name is in our hash table.
- return VI->second;
- }
- return 0;
-}
-
-
-/// changeName - Given a value with a non-empty name, remove its existing entry
-/// from the symbol table and insert a new one for Name. This is equivalent to
-/// doing "remove(V), V->Name = Name, insert(V)", but is faster, and will not
-/// temporarily remove the symbol table plane if V is the last value in the
-/// symtab with that name (which could invalidate iterators to that plane).
-void SymbolTable::changeName(Value *V, const std::string &name) {
- assert(!V->getName().empty() && !name.empty() && V->getName() != name &&
- "Illegal use of this method!");
-
- plane_iterator PI = pmap.find(V->getType());
- assert(PI != pmap.end() && "Value doesn't have an entry in this table?");
- ValueMap &VM = PI->second;
-
- value_iterator VI = VM.find(V->getName());
- assert(VI != VM.end() && "Value does have an entry in this table?");
-
- // Remove the old entry.
- VM.erase(VI);
-
- // See if we can insert the new name.
- VI = VM.lower_bound(name);
-
- // Is there a naming conflict?
- if (VI != VM.end() && VI->first == name) {
- V->Name = getUniqueName(V->getType(), name);
- VM.insert(make_pair(V->Name, V));
- } else {
- V->Name = name;
- VM.insert(VI, make_pair(name, V));
- }
-}
-
-// Remove a value
-void SymbolTable::remove(Value *N) {
- assert(N->hasName() && "Value doesn't have name!");
-
- plane_iterator PI = pmap.find(N->getType());
- assert(PI != pmap.end() &&
- "Trying to remove a value that doesn't have a type plane yet!");
- ValueMap &VM = PI->second;
- value_iterator Entry = VM.find(N->getName());
- assert(Entry != VM.end() && "Invalid entry to remove!");
-
-#if DEBUG_SYMBOL_TABLE
- dump();
- DOUT << " Removing Value: " << Entry->second->getName() << "\n";
-#endif
-
- // Remove the value from the plane...
- VM.erase(Entry);
-
- // If the plane is empty, remove it now!
- if (VM.empty()) {
- // If the plane represented an abstract type that we were interested in,
- // unlink ourselves from this plane.
- //
- if (N->getType()->isAbstract()) {
-#if DEBUG_ABSTYPE
- DOUT << "Plane Empty: Removing type: "
- << N->getType()->getDescription() << "\n";
-#endif
- cast<DerivedType>(N->getType())->removeAbstractTypeUser(this);
- }
-
- pmap.erase(PI);
- }
-}
-
-
-// insertEntry - Insert a value into the symbol table with the specified name.
-void SymbolTable::insertEntry(const std::string &Name, const Type *VTy,
- Value *V) {
- plane_iterator PI = pmap.find(VTy); // Plane iterator
- value_iterator VI; // Actual value iterator
- ValueMap *VM; // The plane we care about.
-
-#if DEBUG_SYMBOL_TABLE
- dump();
- DOUT << " Inserting definition: " << Name << ": "
- << VTy->getDescription() << "\n";
-#endif
-
- if (PI == pmap.end()) { // Not in collection yet... insert dummy entry
- // Insert a new empty element. I points to the new elements.
- VM = &pmap.insert(make_pair(VTy, ValueMap())).first->second;
- VI = VM->end();
-
- // Check to see if the type is abstract. If so, it might be refined in the
- // future, which would cause the plane of the old type to get merged into
- // a new type plane.
- //
- if (VTy->isAbstract()) {
- cast<DerivedType>(VTy)->addAbstractTypeUser(this);
-#if DEBUG_ABSTYPE
- DOUT << "Added abstract type value: " << VTy->getDescription()
- << "\n";
-#endif
- }
-
- } else {
- // Check to see if there is a naming conflict. If so, rename this value!
- VM = &PI->second;
- VI = VM->lower_bound(Name);
- if (VI != VM->end() && VI->first == Name) {
- V->Name = getUniqueName(VTy, Name);
- VM->insert(make_pair(V->Name, V));
- return;
- }
- }
-
- VM->insert(VI, make_pair(Name, V));
-}
-
-
-
-// Strip the symbol table of its names.
-bool SymbolTable::strip() {
- bool RemovedSymbol = false;
- for (plane_iterator I = pmap.begin(); I != pmap.end();) {
- // Removing items from the plane can cause the plane itself to get deleted.
- // If this happens, make sure we incremented our plane iterator already!
- ValueMap &Plane = (I++)->second;
- value_iterator B = Plane.begin(), Bend = Plane.end();
- while (B != Bend) { // Found nonempty type plane!
- Value *V = B->second;
- ++B;
- if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasInternalLinkage()) {
- // Set name to "", removing from symbol table!
- V->setName("");
- RemovedSymbol = true;
- }
- }
- }
-
- return RemovedSymbol;
-}
-
-
-// This function is called when one of the types in the type plane are refined
-void SymbolTable::refineAbstractType(const DerivedType *OldType,
- const Type *NewType) {
-
- // Search to see if we have any values of the type Oldtype. If so, we need to
- // move them into the newtype plane...
- plane_iterator PI = pmap.find(OldType);
- if (PI != pmap.end()) {
- // Get a handle to the new type plane...
- plane_iterator NewTypeIt = pmap.find(NewType);
- if (NewTypeIt == pmap.end()) { // If no plane exists, add one
- NewTypeIt = pmap.insert(make_pair(NewType, ValueMap())).first;
-
- if (NewType->isAbstract()) {
- cast<DerivedType>(NewType)->addAbstractTypeUser(this);
-#if DEBUG_ABSTYPE
- DOUT << "[Added] refined to abstype: " << NewType->getDescription()
- << "\n";
-#endif
- }
- }
-
- ValueMap &NewPlane = NewTypeIt->second;
- ValueMap &OldPlane = PI->second;
- while (!OldPlane.empty()) {
- std::pair<const std::string, Value*> V = *OldPlane.begin();
-
- // Check to see if there is already a value in the symbol table that this
- // would collide with.
- value_iterator VI = NewPlane.find(V.first);
- if (VI != NewPlane.end() && VI->second == V.second) {
- // No action
-
- } else if (VI != NewPlane.end()) {
- // The only thing we are allowing for now is two external global values
- // folded into one.
- //
- GlobalValue *ExistGV = dyn_cast<GlobalValue>(VI->second);
- GlobalValue *NewGV = dyn_cast<GlobalValue>(V.second);
-
- if (ExistGV && NewGV) {
- assert((ExistGV->isDeclaration() || NewGV->isDeclaration()) &&
- "Two planes folded together with overlapping value names!");
-
- // Make sure that ExistGV is the one we want to keep!
- if (!NewGV->isDeclaration())
- std::swap(NewGV, ExistGV);
-
- // Ok we have two external global values. Make all uses of the new
- // one use the old one...
- NewGV->uncheckedReplaceAllUsesWith(ExistGV);
-
- // Update NewGV's name, we're about the remove it from the symbol
- // table.
- NewGV->Name = "";
-
- // Now we can remove this global from the module entirely...
- Module *M = NewGV->getParent();
- if (Function *F = dyn_cast<Function>(NewGV))
- M->getFunctionList().remove(F);
- else
- M->getGlobalList().remove(cast<GlobalVariable>(NewGV));
- delete NewGV;
- } else {
- // If they are not global values, they must be just random values who
- // happen to conflict now that types have been resolved. If this is
- // the case, reinsert the value into the new plane, allowing it to get
- // renamed.
- assert(V.second->getType() == NewType &&"Type resolution is broken!");
- insert(V.second);
- }
- } else {
- insertEntry(V.first, NewType, V.second);
- }
- // Remove the item from the old type plane
- OldPlane.erase(OldPlane.begin());
- }
-
- // Ok, now we are not referencing the type anymore... take me off your user
- // list please!
-#if DEBUG_ABSTYPE
- DOUT << "Removing type " << OldType->getDescription() << "\n";
-#endif
- OldType->removeAbstractTypeUser(this);
-
- // Remove the plane that is no longer used
- pmap.erase(PI);
- }
-}
-
-
-// Handle situation where type becomes Concreate from Abstract
-void SymbolTable::typeBecameConcrete(const DerivedType *AbsTy) {
- plane_iterator PI = pmap.find(AbsTy);
-
- // If there are any values in the symbol table of this type, then the type
- // plane is a use of the abstract type which must be dropped.
- if (PI != pmap.end())
- AbsTy->removeAbstractTypeUser(this);
-}
-
-static void DumpVal(const std::pair<const std::string, Value *> &V) {
- DOUT << " '" << V.first << "' = ";
- V.second->dump();
- DOUT << "\n";
-}
-
-static void DumpPlane(const std::pair<const Type *,
- std::map<const std::string, Value *> >&P){
- P.first->dump();
- DOUT << "\n";
- for_each(P.second.begin(), P.second.end(), DumpVal);
-}
-
-void SymbolTable::dump() const {
- DOUT << "Symbol table dump:\n Plane:";
- for_each(pmap.begin(), pmap.end(), DumpPlane);
-}
-
-// vim: sw=2 ai
diff --git a/lib/VMCore/SymbolTableListTraitsImpl.h b/lib/VMCore/SymbolTableListTraitsImpl.h
index 81849dd031..f4ee13f108 100644
--- a/lib/VMCore/SymbolTableListTraitsImpl.h
+++ b/lib/VMCore/SymbolTableListTraitsImpl.h
@@ -17,7 +17,7 @@
#define LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
#include "llvm/SymbolTableListTraits.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/ValueSymbolTable.h"
namespace llvm {
@@ -29,7 +29,7 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
// Remove all of the items from the old symtab..
if (SymTabObject && !List.empty()) {
- SymbolTable &SymTab = SymTabObject->getValueSymbolTable();
+ ValueSymbolTable &SymTab = SymTabObject->getValueSymbolTable();
for (typename iplist<ValueSubClass>::iterator I = List.begin();
I != List.end(); ++I)
if (I->hasName()) SymTab.remove(I);
@@ -39,7 +39,7 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
// Add all of the items to the new symtab...
if (SymTabObject && !List.empty()) {
- SymbolTable &SymTab = SymTabObject->getValueSymbolTable();
+ ValueSymbolTable &SymTab = SymTabObject->getValueSymbolTable();
for (typename iplist<ValueSubClass>::iterator I = List.begin();
I != List.end(); ++I)
if (I->hasName()) SymTab.insert(I);
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index 3733d2a7ba..a6e57971bd 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -13,7 +13,6 @@
#include "llvm/AbstractTypeUser.h"
#include "llvm/DerivedTypes.h"
-#include "llvm/SymbolTable.h"
#include "llvm/Constants.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/StringExtras.h"
diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp
index 94c03b834a..0218e5798f 100644
--- a/lib/VMCore/Value.cpp
+++ b/lib/VMCore/Value.cpp
@@ -15,7 +15,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/InstrTypes.h"
#include "llvm/Module.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/ValueSymbolTable.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/LeakDetector.h"
#include <algorithm>
@@ -97,17 +97,20 @@ void Value::setName(const std::string &name) {
if (Name == name) return; // Name is already set.
// Get the symbol table to update for this object.
- SymbolTable *ST = 0;
+ ValueSymbolTable *ST = 0;
if (Instruction *I = dyn_cast<Instruction>(this)) {
if (BasicBlock *P = I->getParent())
if (Function *PP = P->getParent())
ST = &PP->getValueSymbolTable();
} else if (BasicBlock *BB = dyn_cast<BasicBlock>(this)) {
- if (Function *P = BB->getParent()) ST = &P->getValueSymbolTable();
+ if (Function *P = BB->getParent())
+ ST = &P->getValueSymbolTable();
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(this)) {
- if (Module *P = GV->getParent()) ST = &P->getValueSymbolTable();
+ if (Module *P = GV->getParent())
+ ST = &P->getValueSymbolTable();
} else if (Argument *A = dyn_cast<Argument>(this)) {
- if (Function *P = A->getParent()) ST = &P->getValueSymbolTable();
+ if (Function *P = A->getParent())
+ ST = &P->getValueSymbolTable();
} else {
assert(isa<Constant>(this) && "Unknown value type!");
return; // no name is setable for this.
@@ -117,7 +120,7 @@ void Value::setName(const std::string &name) {
Name = name;
else if (hasName()) {
if (!name.empty()) { // Replacing name.
- ST->changeName(this, name);
+ ST->rename(this, name);
} else { // Transitioning from hasName -> noname.
ST->remove(this);
Name.clear();
diff --git a/lib/VMCore/ValueSymbolTable.cpp b/lib/VMCore/ValueSymbolTable.cpp
index 6efb998387..51197b6bf3 100644
--- a/lib/VMCore/ValueSymbolTable.cpp
+++ b/lib/VMCore/ValueSymbolTable.cpp
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#define DEBUG_TYPE "valuesymtab"
#include "llvm/GlobalValue.h"
#include "llvm/Type.h"
#include "llvm/ValueSymbolTable.h"
@@ -19,18 +20,15 @@
#include <algorithm>
using namespace llvm;
-#define DEBUG_SYMBOL_TABLE 0
-#define DEBUG_ABSTYPE 0
-
// Class destructor
ValueSymbolTable::~ValueSymbolTable() {
#ifndef NDEBUG // Only do this in -g mode...
bool LeftoverValues = true;
for (iterator VI = vmap.begin(), VE = vmap.end(); VI != VE; ++VI)
if (!isa<Constant>(VI->second) ) {
- DOUT << "Value still in symbol table! Type = '"
+ DEBUG(DOUT << "Value still in symbol table! Type = '"
<< VI->second->getType()->getDescription() << "' Name = '"
- << VI->first << "'\n";
+ << VI->first << "'\n");
LeftoverValues = false;
}
assert(LeftoverValues && "Values remain in symbol table!");
@@ -83,29 +81,24 @@ void ValueSymbolTable::insert(Value* V) {
assert(V && "Can't insert null Value into symbol table!");
assert(V->hasName() && "Can't insert nameless Value into symbol table");
- // Check to see if there is a naming conflict. If so, rename this type!
+ // Check to see if there is a naming conflict. If so, rename this value
std::string UniqueName = getUniqueName(V->getName());
-#if DEBUG_SYMBOL_TABLE
- dump();
- DOUT << " Inserting value: " << UniqueName << ": " << V->dump() << "\n";
-#endif
+ DEBUG(DOUT << " Inserting value: " << UniqueName << ": " << *V << "\n");
// Insert the vmap entry
- vmap.insert(make_pair(UniqueName, V));
+ V->Name = UniqueName;
+ vmap.insert(make_pair(V->Name, V));
}
// Remove a value
-bool ValueSymbolTable::erase(Value *V) {
+bool ValueSymbolTable::remove(Value *V) {
assert(V->hasName() && "Value doesn't have name!");
iterator Entry = vmap.find(V->getName());
if (Entry == vmap.end())
return false;
-#if DEBUG_SYMBOL_TABLE
- dump();
- DOUT << " Removing Value: " << Entry->second->getName() << "\n";
-#endif
+ DEBUG(DOUT << " Removing Value: " << Entry->second->getName() << "\n");
// Remove the value from the plane...
vmap.erase(Entry);
@@ -143,7 +136,7 @@ bool ValueSymbolTable::rename(Value *V, const std::string &name) {
vmap.insert(make_pair(V->Name, V));
} else {
V->Name = name;
- vmap.insert(VI, make_pair(name, V));
+ vmap.insert(VI, make_pair(V->Name, V));
}
return true;
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index 9dc892e5ae..f5b0550d88 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -51,7 +51,7 @@
#include "llvm/Instructions.h"
#include "llvm/Intrinsics.h"
#include "llvm/PassManager.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/ValueSymbolTable.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/InstVisitor.h"
@@ -175,7 +175,7 @@ namespace { // Anonymous namespace for class
// Verification methods...
void verifyTypeSymbolTable(TypeSymbolTable &ST);
- void verifyValueSymbolTable(SymbolTable &ST);
+ void verifyValueSymbolTable(ValueSymbolTable &ST);
void visitGlobalValue(GlobalValue &GV);
void visitGlobalVariable(GlobalVariable &GV);
void visitFunction(Function &F);
@@ -307,20 +307,18 @@ void Verifier::verifyTypeSymbolTable(TypeSymbolTable &ST) {
// verifySymbolTable - Verify that a function or module symbol table is ok
//
-void Verifier::verifyValueSymbolTable(SymbolTable &ST) {
-
- // Loop over all of the values in all type planes in the symbol table.
- for (SymbolTable::plane_const_iterator PI = ST.plane_begin(),
- PE = ST.plane_end(); PI != PE; ++PI)
- for (SymbolTable::value_const_iterator VI = PI->second.begin(),
- VE = PI->second.end(); VI != VE; ++VI) {
- Value *V = VI->second;
- // Check that there are no void typed values in the symbol table. Values
- // with a void type cannot be put into symbol tables because they cannot
- // have names!
- Assert1(V->getType() != Type::VoidTy,
- "Values with void type are not allowed to have names!", V);
- }
+void Verifier::verifyValueSymbolTable(ValueSymbolTable &ST) {
+
+ // Loop over all of the values in the symbol table.
+ for (ValueSymbolTable::const_iterator VI = ST.begin(), VE = ST.end();
+ VI != VE; ++VI) {
+ Value *V = VI->second;
+ // Check that there are no void typed values in the symbol table. Values
+ // with a void type cannot be put into symbol tables because they cannot
+ // have names!
+ Assert1(V->getType() != Type::VoidTy,
+ "Values with void type are not allowed to have names!", V);
+ }
}
// visitFunction - Verify that a function is ok.