-//===-- SymbolTable.cpp - Implement the SymbolTable class -------------------=//
+//===-- SymbolTable.cpp - Implement the SymbolTable class -----------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and 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/Module.h"
#include "Support/StringExtras.h"
#include <algorithm>
+using namespace llvm;
#define DEBUG_SYMBOL_TABLE 0
#define DEBUG_ABSTYPE 0
if (I == end()) return BaseName;
std::string TryName = BaseName;
- unsigned Counter = 0;
type_iterator End = I->second.end();
- while (I->second.find(TryName) != End) // Loop until we find unoccupied
- TryName = BaseName + utostr(++Counter); // Name in the symbol table
+ while (I->second.find(TryName) != End) // Loop until we find a free
+ TryName = BaseName + utostr(++LastUnique); // name in the symbol table
return TryName;
}
// lookup - Returns null on failure...
-Value *SymbolTable::lookup(const Type *Ty, const std::string &Name) {
- iterator I = find(Ty);
+Value *SymbolTable::lookup(const Type *Ty, const std::string &Name) const {
+ const_iterator I = find(Ty);
if (I != end()) { // We have symbols in that plane...
- type_iterator J = I->second.find(Name);
+ type_const_iterator J = I->second.find(Name);
if (J != I->second.end()) // and the name is in our hash table...
return J->second;
}
// Search to see if we have any values of the type oldtype. If so, we need to
// move them into the newtype plane...
iterator TPI = find(OldType);
- if (OldType != NewType && TPI != end()) {
+ if (TPI != end()) {
// Get a handle to the new type plane...
iterator NewTypeIt = find(NewType);
if (NewTypeIt == super::end()) { // If no plane exists, add one
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 plane that is no longer used
erase(TPI);
- } else if (TPI != end()) {
- assert(OldType == NewType);
-#if DEBUG_ABSTYPE
- std::cerr << "Removing SELF type " << OldType->getDescription() << "\n";
-#endif
- OldType->removeAbstractTypeUser(this);
}
TPI = find(Type::TypeTy);
if (TPI != end()) {
// 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
- // occurances, and although we only need to remove one at a time, it's
+ // occurrences, and although we only need to remove one at a time, it's
// faster to remove them all in one pass.
//
VarMap &TyPlane = TPI->second;
}
}
+void SymbolTable::typeBecameConcrete(const DerivedType *AbsTy) {
+ iterator TPI = find(AbsTy);
+
+ // If there are any values in the symbol table of this type, then the type
+ // plan is a use of the abstract type which must be dropped.
+ if (TPI != end())
+ AbsTy->removeAbstractTypeUser(this);
+
+ TPI = find(Type::TypeTy);
+ if (TPI != end()) {
+ // 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.
+ //
+ VarMap &TyPlane = TPI->second;
+ for (VarMap::iterator I = TyPlane.begin(), E = TyPlane.end(); I != E; ++I)
+ if (I->second == (Value*)AbsTy) // FIXME when Types aren't const.
+ AbsTy->removeAbstractTypeUser(this);
+ }
+}
+
static void DumpVal(const std::pair<const std::string, Value *> &V) {
std::cout << " '" << V.first << "' = ";
V.second->dump();