diff options
author | Chris Lattner <sabre@nondot.org> | 2002-11-20 18:36:02 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-11-20 18:36:02 +0000 |
commit | 6e6026b46569b01f8f6d4dcdb6c899c3a9c76b3e (patch) | |
tree | 57322a305c9e9d3273ae9d3d09728ec2662e97d8 /lib/VMCore/Module.cpp | |
parent | c09aab0a4de7e3f65dd830803faadb7abae28872 (diff) |
- Eliminated the deferred symbol table stuff in Module & Function, it really
wasn't an optimization and it was causing lots of bugs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4779 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Module.cpp')
-rw-r--r-- | lib/VMCore/Module.cpp | 47 |
1 files changed, 12 insertions, 35 deletions
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index c12b32d7c1..f54a6f390b 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -57,7 +57,7 @@ Module::Module() { GlobalList.setItemParent(this); GlobalList.setParent(this); GVRefMap = 0; - SymTab = 0; + SymTab = new SymbolTable(); } Module::~Module() { @@ -74,26 +74,6 @@ void Module::dump() const { print(std::cerr); } -SymbolTable *Module::getSymbolTableSure() { - if (!SymTab) SymTab = new SymbolTable(); - return SymTab; -} - -// hasSymbolTable() - Returns true if there is a symbol table allocated to -// this object AND if there is at least one name in it! -// -bool Module::hasSymbolTable() const { - if (!SymTab) return false; - - for (SymbolTable::const_iterator I = SymTab->begin(), E = SymTab->end(); - I != E; ++I) - if (I->second.begin() != I->second.end()) - return true; // Found nonempty type plane! - - return false; -} - - // 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 @@ -101,10 +81,10 @@ bool Module::hasSymbolTable() const { // Function *Module::getOrInsertFunction(const std::string &Name, const FunctionType *Ty) { - SymbolTable *SymTab = getSymbolTableSure(); + SymbolTable &SymTab = getSymbolTable(); // See if we have a definitions for the specified function already... - if (Value *V = SymTab->lookup(PointerType::get(Ty), Name)) { + if (Value *V = SymTab.lookup(PointerType::get(Ty), Name)) { return cast<Function>(V); // Yup, got it } else { // Nope, add one Function *New = new Function(Ty, false, Name); @@ -117,10 +97,8 @@ 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(); - if (SymTab == 0) return 0; // No symtab, no symbols... - - return cast_or_null<Function>(SymTab->lookup(PointerType::get(Ty), Name)); + SymbolTable &SymTab = getSymbolTable(); + return cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name)); } // addTypeName - Insert an entry in the symbol table mapping Str to Type. If @@ -128,13 +106,13 @@ Function *Module::getFunction(const std::string &Name, const FunctionType *Ty) { // table is not modified. // bool Module::addTypeName(const std::string &Name, const Type *Ty) { - SymbolTable *ST = getSymbolTableSure(); + SymbolTable &ST = getSymbolTable(); - if (ST->lookup(Type::TypeTy, Name)) return true; // Already in symtab... + if (ST.lookup(Type::TypeTy, 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... - ((Value*)Ty)->setName(Name, ST); + ((Value*)Ty)->setName(Name, &ST); return false; } @@ -204,13 +182,12 @@ Function *Module::getNamedFunction(const std::string &Name) { // specified type, return it. // std::string Module::getTypeName(const Type *Ty) { - const SymbolTable *ST = getSymbolTable(); - if (ST == 0) return ""; // No symbol table, must not have an entry... - if (ST->find(Type::TypeTy) == ST->end()) + const SymbolTable &ST = getSymbolTable(); + if (ST.find(Type::TypeTy) == ST.end()) return ""; // No names for types... - SymbolTable::type_const_iterator TI = ST->type_begin(Type::TypeTy); - SymbolTable::type_const_iterator TE = ST->type_end(Type::TypeTy); + SymbolTable::type_const_iterator TI = ST.type_begin(Type::TypeTy); + SymbolTable::type_const_iterator TE = ST.type_end(Type::TypeTy); while (TI != TE && TI->second != (const Value*)Ty) ++TI; |