diff options
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 28 | ||||
-rw-r--r-- | lib/VMCore/Function.cpp | 4 | ||||
-rw-r--r-- | lib/VMCore/Module.cpp | 27 | ||||
-rw-r--r-- | lib/VMCore/SymbolTable.cpp | 110 | ||||
-rw-r--r-- | lib/VMCore/SymbolTableListTraitsImpl.h | 12 | ||||
-rw-r--r-- | lib/VMCore/TypeSymbolTable.cpp | 8 | ||||
-rw-r--r-- | lib/VMCore/Value.cpp | 8 | ||||
-rw-r--r-- | lib/VMCore/Verifier.cpp | 12 |
8 files changed, 55 insertions, 154 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index f5b2484429..64cac8c518 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -25,6 +25,7 @@ #include "llvm/Instructions.h" #include "llvm/Module.h" #include "llvm/SymbolTable.h" +#include "llvm/TypeSymbolTable.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/CFG.h" @@ -216,9 +217,9 @@ static std::string getLLVMName(const std::string &Name, static void fillTypeNameTable(const Module *M, std::map<const Type *, std::string> &TypeNames) { if (!M) return; - const SymbolTable &ST = M->getSymbolTable(); - SymbolTable::type_const_iterator TI = ST.type_begin(); - for (; TI != ST.type_end(); ++TI) { + const TypeSymbolTable &ST = M->getTypeSymbolTable(); + TypeSymbolTable::const_iterator TI = ST.begin(); + for (; TI != ST.end(); ++TI) { // As a heuristic, don't insert pointer to primitive types, because // they are used too often to have a single useful name. // @@ -666,7 +667,8 @@ public: private: void printModule(const Module *M); - void printSymbolTable(const SymbolTable &ST); + void printTypeSymbolTable(const TypeSymbolTable &ST); + void printValueSymbolTable(const SymbolTable &ST); void printConstant(const Constant *CPV); void printGlobal(const GlobalVariable *GV); void printFunction(const Function *F); @@ -818,7 +820,8 @@ void AssemblyWriter::printModule(const Module *M) { } // Loop over the symbol table, emitting all named constants. - printSymbolTable(M->getSymbolTable()); + printTypeSymbolTable(M->getTypeSymbolTable()); + printValueSymbolTable(M->getValueSymbolTable()); for (Module::const_global_iterator I = M->global_begin(), E = M->global_end(); I != E; ++I) @@ -873,14 +876,10 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) { Out << "\n"; } - -// printSymbolTable - Run through symbol table looking for constants -// and types. Emit their declarations. -void AssemblyWriter::printSymbolTable(const SymbolTable &ST) { - +void AssemblyWriter::printTypeSymbolTable(const TypeSymbolTable &ST) { // Print the types. - for (SymbolTable::type_const_iterator TI = ST.type_begin(); - TI != ST.type_end(); ++TI) { + for (TypeSymbolTable::const_iterator TI = ST.begin(), TE = ST.end(); + TI != TE; ++TI) { Out << "\t" << getLLVMName(TI->first) << " = type "; // Make sure we print out at least one level of the type structure, so @@ -888,6 +887,11 @@ void AssemblyWriter::printSymbolTable(const SymbolTable &ST) { // printTypeAtLeastOneLevel(TI->second) << "\n"; } +} + +// printSymbolTable - Run through symbol table looking for constants +// and types. Emit their declarations. +void AssemblyWriter::printValueSymbolTable(const SymbolTable &ST) { // Print the constants, in type plane order. for (SymbolTable::plane_const_iterator PI = ST.plane_begin(); diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index e8bbd86590..4bc93dbb2c 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -144,8 +144,8 @@ void Function::eraseFromParent() { /// required before printing out to a textual form, to ensure that there is no /// ambiguity when parsing. void Function::renameLocalSymbols() { - SymbolTable &LST = getSymbolTable(); // Local Symtab - SymbolTable &GST = getParent()->getSymbolTable(); // Global Symtab + SymbolTable &LST = getValueSymbolTable(); // Local Symtab + SymbolTable &GST = getParent()->getValueSymbolTable(); // Global Symtab for (SymbolTable::plane_iterator LPI = LST.plane_begin(), E = LST.plane_end(); LPI != E; ++LPI) diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 6897a4f92d..98faff1d33 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/Support/LeakDetector.h" #include "SymbolTableListTraitsImpl.h" +#include "llvm/TypeSymbolTable.h" #include <algorithm> #include <cstdarg> #include <cstdlib> @@ -68,7 +69,8 @@ Module::Module(const std::string &MID) FunctionList.setParent(this); GlobalList.setItemParent(this); GlobalList.setParent(this); - SymTab = new SymbolTable(); + ValSymTab = new SymbolTable(); + TypeSymTab = new TypeSymbolTable(); } Module::~Module() { @@ -78,7 +80,8 @@ Module::~Module() { FunctionList.clear(); FunctionList.setParent(0); LibraryList.clear(); - delete SymTab; + delete ValSymTab; + delete TypeSymTab; } // Module::dump() - Allow printing from debugger @@ -156,7 +159,7 @@ void Module::setPointerSize(PointerSize PS) { // Function *Module::getOrInsertFunction(const std::string &Name, const FunctionType *Ty) { - SymbolTable &SymTab = getSymbolTable(); + SymbolTable &SymTab = getValueSymbolTable(); // See if we have a definitions for the specified function already... if (Value *V = SymTab.lookup(PointerType::get(Ty), Name)) { @@ -194,7 +197,7 @@ Function *Module::getOrInsertFunction(const std::string &Name, // If it does not exist, return null. // Function *Module::getFunction(const std::string &Name, const FunctionType *Ty) { - SymbolTable &SymTab = getSymbolTable(); + SymbolTable &SymTab = getValueSymbolTable(); return cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name)); } @@ -275,7 +278,7 @@ Function *Module::getNamedFunction(const std::string &Name) const { /// GlobalVariable *Module::getGlobalVariable(const std::string &Name, const Type *Ty, bool AllowInternal) { - if (Value *V = getSymbolTable().lookup(PointerType::get(Ty), Name)) { + if (Value *V = getValueSymbolTable().lookup(PointerType::get(Ty), Name)) { GlobalVariable *Result = cast<GlobalVariable>(V); if (AllowInternal || !Result->hasInternalLinkage()) return Result; @@ -309,9 +312,9 @@ GlobalVariable *Module::getNamedGlobal(const std::string &Name) const { // table is not modified. // bool Module::addTypeName(const std::string &Name, const Type *Ty) { - SymbolTable &ST = getSymbolTable(); + TypeSymbolTable &ST = getTypeSymbolTable(); - if (ST.lookupType(Name)) return true; // Already in symtab... + if (ST.lookup(Name)) return true; // Already in symtab... // Not in symbol table? Set the name with the Symtab as an argument so the // type knows what to update... @@ -323,18 +326,18 @@ bool Module::addTypeName(const std::string &Name, const Type *Ty) { /// getTypeByName - Return the type with the specified name in this module, or /// null if there is none by that name. const Type *Module::getTypeByName(const std::string &Name) const { - const SymbolTable &ST = getSymbolTable(); - return cast_or_null<Type>(ST.lookupType(Name)); + const TypeSymbolTable &ST = getTypeSymbolTable(); + return cast_or_null<Type>(ST.lookup(Name)); } // getTypeName - If there is at least one entry in the symbol table for the // specified type, return it. // std::string Module::getTypeName(const Type *Ty) const { - const SymbolTable &ST = getSymbolTable(); + const TypeSymbolTable &ST = getTypeSymbolTable(); - SymbolTable::type_const_iterator TI = ST.type_begin(); - SymbolTable::type_const_iterator TE = ST.type_end(); + TypeSymbolTable::const_iterator TI = ST.begin(); + TypeSymbolTable::const_iterator TE = ST.end(); if ( TI == TE ) return ""; // No names for types while (TI != TE && TI->second != Ty) diff --git a/lib/VMCore/SymbolTable.cpp b/lib/VMCore/SymbolTable.cpp index 7ea3377ab9..c20366cf35 100644 --- a/lib/VMCore/SymbolTable.cpp +++ b/lib/VMCore/SymbolTable.cpp @@ -24,12 +24,6 @@ using namespace llvm; #define DEBUG_ABSTYPE 0 SymbolTable::~SymbolTable() { - // Drop all abstract type references in the type plane... - for (type_iterator TI = tmap.begin(), TE = tmap.end(); TI != TE; ++TI) { - if (TI->second->isAbstract()) // If abstract, drop the reference... - cast<DerivedType>(TI->second)->removeAbstractTypeUser(this); - } - // TODO: FIXME: BIG ONE: This doesn't unreference abstract types for the // planes that could still have entries! @@ -82,14 +76,6 @@ Value *SymbolTable::lookup(const Type *Ty, const std::string &Name) const { } -// lookup a type by name - returns null on failure -Type* SymbolTable::lookupType(const std::string& Name) const { - type_const_iterator TI = tmap.find(Name); - if (TI != tmap.end()) - return const_cast<Type*>(TI->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 @@ -158,32 +144,6 @@ void SymbolTable::remove(Value *N) { } } -// remove - Remove a type from the symbol table... -Type* SymbolTable::remove(type_iterator Entry) { - assert(Entry != tmap.end() && "Invalid entry to remove!"); - - const Type* Result = Entry->second; - -#if DEBUG_SYMBOL_TABLE - dump(); - DOUT << " Removing type: " << Entry->first << "\n"; -#endif - - tmap.erase(Entry); - - // If we are removing an abstract type, remove the symbol table from it's use - // list... - if (Result->isAbstract()) { -#if DEBUG_ABSTYPE - DOUT << "Removing abstract type from symtab" - << Result->getDescription() << "\n"; -#endif - cast<DerivedType>(Result)->removeAbstractTypeUser(this); - } - - return const_cast<Type*>(Result); -} - // insertEntry - Insert a value into the symbol table with the specified name. void SymbolTable::insertEntry(const std::string &Name, const Type *VTy, @@ -230,34 +190,6 @@ void SymbolTable::insertEntry(const std::string &Name, const Type *VTy, } -// insertEntry - Insert a type into the symbol table with the specified -// name... -// -void SymbolTable::insert(const std::string& Name, const Type* T) { - assert(T && "Can't insert null type into symbol table!"); - - // Check to see if there is a naming conflict. If so, rename this type! - std::string UniqueName = Name; - if (lookupType(Name)) - UniqueName = getUniqueName(T, Name); - -#if DEBUG_SYMBOL_TABLE - dump(); - DOUT << " Inserting type: " << UniqueName << ": " - << T->getDescription() << "\n"; -#endif - - // Insert the tmap entry - tmap.insert(make_pair(UniqueName, T)); - - // If we are adding an abstract type, add the symbol table to it's use list. - if (T->isAbstract()) { - cast<DerivedType>(T)->addAbstractTypeUser(this); -#if DEBUG_ABSTYPE - DOUT << "Added abstract type to ST: " << T->getDescription() << "\n"; -#endif - } -} // Strip the symbol table of its names. bool SymbolTable::strip() { @@ -278,11 +210,6 @@ bool SymbolTable::strip() { } } - for (type_iterator TI = tmap.begin(); TI != tmap.end(); ) { - remove(TI++); - RemovedSymbol = true; - } - return RemovedSymbol; } @@ -375,28 +302,6 @@ void SymbolTable::refineAbstractType(const DerivedType *OldType, // Remove the plane that is no longer used pmap.erase(PI); } - - // Loop over all of the types in the symbol table, replacing any references - // to OldType with references to NewType. Note that there may be multiple - // occurrences, and although we only need to remove one at a time, it's - // faster to remove them all in one pass. - // - for (type_iterator I = type_begin(), E = type_end(); I != E; ++I) { - if (I->second == (Type*)OldType) { // FIXME when Types aren't const. -#if DEBUG_ABSTYPE - DOUT << "Removing type " << OldType->getDescription() << "\n"; -#endif - OldType->removeAbstractTypeUser(this); - - I->second = (Type*)NewType; // TODO FIXME when types aren't const - if (NewType->isAbstract()) { -#if DEBUG_ABSTYPE - DOUT << "Added type " << NewType->getDescription() << "\n"; -#endif - cast<DerivedType>(NewType)->addAbstractTypeUser(this); - } - } - } } @@ -408,13 +313,6 @@ void SymbolTable::typeBecameConcrete(const DerivedType *AbsTy) { // plane is a use of the abstract type which must be dropped. if (PI != pmap.end()) AbsTy->removeAbstractTypeUser(this); - - // Loop over all of the types in the symbol table, dropping any abstract - // type user entries for AbsTy which occur because there are names for the - // type. - for (type_iterator TI = type_begin(), TE = type_end(); TI != TE; ++TI) - if (TI->second == (Type*)AbsTy) // FIXME when Types aren't const. - AbsTy->removeAbstractTypeUser(this); } static void DumpVal(const std::pair<const std::string, Value *> &V) { @@ -430,17 +328,9 @@ static void DumpPlane(const std::pair<const Type *, for_each(P.second.begin(), P.second.end(), DumpVal); } -static void DumpTypes(const std::pair<const std::string, const Type*>& T ) { - DOUT << " '" << T.first << "' = "; - T.second->dump(); - DOUT << "\n"; -} - void SymbolTable::dump() const { DOUT << "Symbol table dump:\n Plane:"; for_each(pmap.begin(), pmap.end(), DumpPlane); - DOUT << " Types: "; - for_each(tmap.begin(), tmap.end(), DumpTypes); } // vim: sw=2 ai diff --git a/lib/VMCore/SymbolTableListTraitsImpl.h b/lib/VMCore/SymbolTableListTraitsImpl.h index 6d70401c89..81849dd031 100644 --- a/lib/VMCore/SymbolTableListTraitsImpl.h +++ b/lib/VMCore/SymbolTableListTraitsImpl.h @@ -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->getSymbolTable(); + SymbolTable &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->getSymbolTable(); + SymbolTable &SymTab = SymTabObject->getValueSymbolTable(); for (typename iplist<ValueSubClass>::iterator I = List.begin(); I != List.end(); ++I) if (I->hasName()) SymTab.insert(I); @@ -53,7 +53,7 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> assert(V->getParent() == 0 && "Value already in a container!!"); V->setParent(ItemParent); if (V->hasName() && SymTabObject) - SymTabObject->getSymbolTable().insert(V); + SymTabObject->getValueSymbolTable().insert(V); } template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, @@ -62,7 +62,7 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> ::removeNodeFromList(ValueSubClass *V) { V->setParent(0); if (V->hasName() && SymTabObject) - SymTabObject->getSymbolTable().remove(V); + SymTabObject->getValueSymbolTable().remove(V); } template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, @@ -83,10 +83,10 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> ValueSubClass &V = *first; bool HasName = V.hasName(); if (OldSTO && HasName) - OldSTO->getSymbolTable().remove(&V); + OldSTO->getValueSymbolTable().remove(&V); V.setParent(NewIP); if (NewSTO && HasName) - NewSTO->getSymbolTable().insert(&V); + NewSTO->getValueSymbolTable().insert(&V); } } else { // Just transferring between blocks in the same function, simply update the diff --git a/lib/VMCore/TypeSymbolTable.cpp b/lib/VMCore/TypeSymbolTable.cpp index cfd8cbf935..ac89bb6645 100644 --- a/lib/VMCore/TypeSymbolTable.cpp +++ b/lib/VMCore/TypeSymbolTable.cpp @@ -48,10 +48,10 @@ Type* TypeSymbolTable::lookup(const std::string& Name) const { } // Erase a specific type from the symbol table -bool TypeSymbolTable::erase(Type *N) { +bool TypeSymbolTable::remove(Type *N) { for (iterator TI = tmap.begin(), TE = tmap.end(); TI != TE; ++TI) { if (TI->second == N) { - this->erase(TI); + this->remove(TI); return true; } } @@ -59,7 +59,7 @@ bool TypeSymbolTable::erase(Type *N) { } // remove - Remove a type from the symbol table... -Type* TypeSymbolTable::erase(iterator Entry) { +Type* TypeSymbolTable::remove(iterator Entry) { assert(Entry != tmap.end() && "Invalid entry to remove!"); const Type* Result = Entry->second; @@ -115,7 +115,7 @@ void TypeSymbolTable::insert(const std::string& Name, const Type* T) { bool TypeSymbolTable::strip() { bool RemovedSymbol = false; for (iterator TI = tmap.begin(); TI != tmap.end(); ) { - erase(TI++); + remove(TI++); RemovedSymbol = true; } diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index 0d9dc07fa0..94c03b834a 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -101,13 +101,13 @@ void Value::setName(const std::string &name) { if (Instruction *I = dyn_cast<Instruction>(this)) { if (BasicBlock *P = I->getParent()) if (Function *PP = P->getParent()) - ST = &PP->getSymbolTable(); + ST = &PP->getValueSymbolTable(); } else if (BasicBlock *BB = dyn_cast<BasicBlock>(this)) { - if (Function *P = BB->getParent()) ST = &P->getSymbolTable(); + if (Function *P = BB->getParent()) ST = &P->getValueSymbolTable(); } else if (GlobalValue *GV = dyn_cast<GlobalValue>(this)) { - if (Module *P = GV->getParent()) ST = &P->getSymbolTable(); + if (Module *P = GV->getParent()) ST = &P->getValueSymbolTable(); } else if (Argument *A = dyn_cast<Argument>(this)) { - if (Function *P = A->getParent()) ST = &P->getSymbolTable(); + if (Function *P = A->getParent()) ST = &P->getValueSymbolTable(); } else { assert(isa<Constant>(this) && "Unknown value type!"); return; // no name is setable for this. diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 719c6f2f5f..e03bb6d1d9 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -99,7 +99,8 @@ namespace { // Anonymous namespace for class bool doInitialization(Module &M) { Mod = &M; - verifySymbolTable(M.getSymbolTable()); + verifyTypeSymbolTable(M.getTypeSymbolTable()); + verifyValueSymbolTable(M.getValueSymbolTable()); // If this is a real pass, in a pass manager, we must abort before // returning back to the pass manager, or else the pass manager may try to @@ -173,7 +174,8 @@ namespace { // Anonymous namespace for class // Verification methods... - void verifySymbolTable(SymbolTable &ST); + void verifyTypeSymbolTable(TypeSymbolTable &ST); + void verifyValueSymbolTable(SymbolTable &ST); void visitGlobalValue(GlobalValue &GV); void visitGlobalVariable(GlobalVariable &GV); void visitFunction(Function &F); @@ -301,10 +303,12 @@ void Verifier::visitGlobalVariable(GlobalVariable &GV) { visitGlobalValue(GV); } +void Verifier::verifyTypeSymbolTable(TypeSymbolTable &ST) { +} // verifySymbolTable - Verify that a function or module symbol table is ok // -void Verifier::verifySymbolTable(SymbolTable &ST) { +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(), @@ -372,7 +376,7 @@ void Verifier::visitFunction(Function &F) { Assert1(F.getName().substr(0, 5) != "llvm.", "llvm intrinsics cannot be defined!", &F); - verifySymbolTable(F.getSymbolTable()); + verifyValueSymbolTable(F.getValueSymbolTable()); // Check the entry node BasicBlock *Entry = &F.getEntryBlock(); |