X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FTypeSymbolTable.cpp;h=d68a44bd6711c88df870a95e1e5c4ed77f2a75e3;hb=1b4051095dd518175bea303ed6d7328bd6849cd4;hp=6cc1055ebce20d307d0cc9b21c485c8fcebaa253;hpb=67408dab1b50e17decf788c119ca0194fc7024a6;p=oota-llvm.git diff --git a/lib/VMCore/TypeSymbolTable.cpp b/lib/VMCore/TypeSymbolTable.cpp index 6cc1055ebce..d68a44bd671 100644 --- a/lib/VMCore/TypeSymbolTable.cpp +++ b/lib/VMCore/TypeSymbolTable.cpp @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by Reid Spencer. It is distributed under the -// University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -14,7 +14,10 @@ #include "llvm/TypeSymbolTable.h" #include "llvm/DerivedTypes.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Support/Streams.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/raw_ostream.h" #include using namespace llvm; @@ -29,53 +32,45 @@ TypeSymbolTable::~TypeSymbolTable() { } } -std::string TypeSymbolTable::getUniqueName(const std::string &BaseName) const { +std::string TypeSymbolTable::getUniqueName(StringRef BaseName) const { std::string TryName = BaseName; + const_iterator End = tmap.end(); // See if the name exists while (tmap.find(TryName) != End) // Loop until we find a free - TryName = BaseName + utostr(++LastUnique); // name in the symbol table + TryName = BaseName.str() + utostr(++LastUnique); // name in the symbol table return TryName; } // lookup a type by name - returns null on failure -Type* TypeSymbolTable::lookup(const std::string& Name) const { +Type* TypeSymbolTable::lookup(StringRef Name) const { const_iterator TI = tmap.find(Name); + Type* result = 0; if (TI != tmap.end()) - return const_cast(TI->second); - return 0; -} - -// Erase a specific type from the symbol table -bool TypeSymbolTable::remove(Type *N) { - for (iterator TI = tmap.begin(), TE = tmap.end(); TI != TE; ++TI) { - if (TI->second == N) { - this->remove(TI); - return true; - } - } - return false; + result = const_cast(TI->second); + return result; } // remove - Remove a type from the symbol table... Type* TypeSymbolTable::remove(iterator Entry) { assert(Entry != tmap.end() && "Invalid entry to remove!"); - const Type* Result = Entry->second; #if DEBUG_SYMBOL_TABLE dump(); - cerr << " Removing Value: " << Result->getName() << "\n"; + dbgs() << " Removing Value: " << Result->getDescription() << "\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 - cerr << "Removing abstract type from symtab" << Result->getDescription()<<"\n"; + dbgs() << "Removing abstract type from symtab" + << Result->getDescription() + << "\n"; #endif cast(Result)->removeAbstractTypeUser(this); } @@ -85,63 +80,64 @@ Type* TypeSymbolTable::remove(iterator Entry) { // insert - Insert a type into the symbol table with the specified name... -void TypeSymbolTable::insert(const std::string& Name, const Type* T) { +void TypeSymbolTable::insert(StringRef 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 (lookup(Name)) - UniqueName = getUniqueName(Name); - + if (tmap.insert(std::make_pair(Name, T)).second) { + // Type inserted fine with no conflict. + #if DEBUG_SYMBOL_TABLE - dump(); - cerr << " Inserting type: " << UniqueName << ": " - << T->getDescription() << "\n"; + dump(); + dbgs() << " Inserted type: " << Name << ": " << T->getDescription() << "\n"; +#endif + } else { + // If there is a name conflict... + + // Check to see if there is a naming conflict. If so, rename this type! + std::string UniqueName = Name; + if (lookup(Name)) + UniqueName = getUniqueName(Name); + +#if DEBUG_SYMBOL_TABLE + dump(); + dbgs() << " Inserting type: " << UniqueName << ": " + << T->getDescription() << "\n"; #endif - // Insert the tmap entry - tmap.insert(make_pair(UniqueName, T)); - + // 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(T)->addAbstractTypeUser(this); #if DEBUG_ABSTYPE - cerr << "Added abstract type to ST: " << T->getDescription() << "\n"; + dbgs() << "Added abstract type to ST: " << T->getDescription() << "\n"; #endif } } -// Strip the symbol table of its names. -bool TypeSymbolTable::strip() { - bool RemovedSymbol = false; - for (iterator TI = tmap.begin(); TI != tmap.end(); ) { - remove(TI++); - RemovedSymbol = true; - } - - return RemovedSymbol; -} - // This function is called when one of the types in the type plane are refined void TypeSymbolTable::refineAbstractType(const DerivedType *OldType, const Type *NewType) { - // 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 (iterator I = begin(), E = end(); I != E; ++I) { - if (I->second == (Type*)OldType) { // FIXME when Types aren't const. + // FIXME when Types aren't const. + if (I->second == const_cast(OldType)) { #if DEBUG_ABSTYPE - cerr << "Removing type " << OldType->getDescription() << "\n"; + dbgs() << "Removing type " << OldType->getDescription() << "\n"; #endif OldType->removeAbstractTypeUser(this); - I->second = (Type*)NewType; // TODO FIXME when types aren't const + // TODO FIXME when types aren't const + I->second = const_cast(NewType); if (NewType->isAbstract()) { #if DEBUG_ABSTYPE - cerr << "Added type " << NewType->getDescription() << "\n"; + dbgs() << "Added type " << NewType->getDescription() << "\n"; #endif cast(NewType)->addAbstractTypeUser(this); } @@ -161,14 +157,13 @@ void TypeSymbolTable::typeBecameConcrete(const DerivedType *AbsTy) { } static void DumpTypes(const std::pair& T ) { - cerr << " '" << T.first << "' = "; + dbgs() << " '" << T.first << "' = "; T.second->dump(); - cerr << "\n"; + dbgs() << "\n"; } void TypeSymbolTable::dump() const { - cerr << "TypeSymbolPlane: "; + dbgs() << "TypeSymbolPlane: "; for_each(tmap.begin(), tmap.end(), DumpTypes); } -// vim: sw=2 ai