diff options
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 34 | ||||
-rw-r--r-- | lib/VMCore/BasicBlock.cpp | 6 | ||||
-rw-r--r-- | lib/VMCore/Function.cpp | 18 | ||||
-rw-r--r-- | lib/VMCore/Instruction.cpp | 6 | ||||
-rw-r--r-- | lib/VMCore/Linker.cpp | 11 | ||||
-rw-r--r-- | lib/VMCore/Module.cpp | 47 | ||||
-rw-r--r-- | lib/VMCore/SlotCalculator.cpp | 11 | ||||
-rw-r--r-- | lib/VMCore/SymbolTableListTraitsImpl.h | 16 | ||||
-rw-r--r-- | lib/VMCore/Verifier.cpp | 8 |
9 files changed, 63 insertions, 94 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index e27bd26ba2..2c9a77c834 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -74,20 +74,19 @@ static SlotCalculator *createSlotCalculator(const Value *V) { // static void fillTypeNameTable(const Module *M, map<const Type *, string> &TypeNames) { - if (M && M->hasSymbolTable()) { - const SymbolTable *ST = M->getSymbolTable(); - SymbolTable::const_iterator PI = ST->find(Type::TypeTy); - if (PI != ST->end()) { - SymbolTable::type_const_iterator I = PI->second.begin(); - for (; I != PI->second.end(); ++I) { - // As a heuristic, don't insert pointer to primitive types, because - // they are used too often to have a single useful name. - // - const Type *Ty = cast<const Type>(I->second); - if (!isa<PointerType>(Ty) || - !cast<PointerType>(Ty)->getElementType()->isPrimitiveType()) - TypeNames.insert(std::make_pair(Ty, "%"+I->first)); - } + if (!M) return; + const SymbolTable &ST = M->getSymbolTable(); + SymbolTable::const_iterator PI = ST.find(Type::TypeTy); + if (PI != ST.end()) { + SymbolTable::type_const_iterator I = PI->second.begin(); + for (; I != PI->second.end(); ++I) { + // As a heuristic, don't insert pointer to primitive types, because + // they are used too often to have a single useful name. + // + const Type *Ty = cast<const Type>(I->second); + if (!isa<PointerType>(Ty) || + !cast<PointerType>(Ty)->getElementType()->isPrimitiveType()) + TypeNames.insert(std::make_pair(Ty, "%"+I->first)); } } } @@ -200,7 +199,7 @@ ostream &WriteTypeSymbolic(ostream &Out, const Type *Ty, const Module *M) { // If they want us to print out a type, attempt to make it symbolic if there // is a symbol table in the module... - if (M && M->hasSymbolTable()) { + if (M) { map<const Type *, string> TypeNames; fillTypeNameTable(M, TypeNames); @@ -406,7 +405,7 @@ ostream &WriteAsOperand(ostream &Out, const Value *V, bool PrintType, map<const Type *, string> TypeNames; if (Context == 0) Context = getModuleFromVal(V); - if (Context && Context->hasSymbolTable()) + if (Context) fillTypeNameTable(Context, TypeNames); if (PrintType) @@ -524,8 +523,7 @@ void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType, void AssemblyWriter::printModule(const Module *M) { // Loop over the symbol table, emitting all named constants... - if (M->hasSymbolTable()) - printSymbolTable(*M->getSymbolTable()); + printSymbolTable(M->getSymbolTable()); for (Module::const_giterator I = M->gbegin(), E = M->gend(); I != E; ++I) printGlobal(I); diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index 6ddcc08c82..89f9a27f8d 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -105,11 +105,11 @@ void BasicBlock::setParent(Function *parent) { // Specialize setName to take care of symbol table majik void BasicBlock::setName(const std::string &name, SymbolTable *ST) { Function *P; - assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) && + assert((ST == 0 || (!getParent() || ST == &getParent()->getSymbolTable())) && "Invalid symtab argument!"); - if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this); + if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this); Value::setName(name); - if (P && hasName()) P->getSymbolTable()->insert(this); + if (P && hasName()) P->getSymbolTable().insert(this); } TerminatorInst *BasicBlock::getTerminator() { diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index 9b837dcaa1..70569c0f67 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -57,11 +57,11 @@ Argument::Argument(const Type *Ty, const std::string &Name, Function *Par) // Specialize setName to take care of symbol table majik void Argument::setName(const std::string &name, SymbolTable *ST) { Function *P; - assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) && + assert((ST == 0 || (!getParent() || ST == &getParent()->getSymbolTable())) && "Invalid symtab argument!"); - if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this); + if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this); Value::setName(name); - if (P && hasName()) P->getSymbolTableSure()->insert(this); + if (P && hasName()) P->getSymbolTable().insert(this); } void Argument::setParent(Function *parent) { @@ -114,11 +114,11 @@ Function::~Function() { // Specialize setName to take care of symbol table majik void Function::setName(const std::string &name, SymbolTable *ST) { Module *P; - assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) && + assert((ST == 0 || (!getParent() || ST == &getParent()->getSymbolTable())) && "Invalid symtab argument!"); - if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this); + if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this); Value::setName(name); - if (P && getName() != "") P->getSymbolTableSure()->insert(this); + if (P && getName() != "") P->getSymbolTable().insert(this); } void Function::setParent(Module *parent) { @@ -178,9 +178,9 @@ void GlobalVariable::setParent(Module *parent) { // Specialize setName to take care of symbol table majik void GlobalVariable::setName(const std::string &name, SymbolTable *ST) { Module *P; - assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) && + assert((ST == 0 || (!getParent() || ST == &getParent()->getSymbolTable())) && "Invalid symtab argument!"); - if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this); + if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this); Value::setName(name); - if (P && getName() != "") P->getSymbolTableSure()->insert(this); + if (P && getName() != "") P->getSymbolTable().insert(this); } diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index 95267aacd0..01381faed6 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -40,12 +40,12 @@ void Instruction::setParent(BasicBlock *P) { void Instruction::setName(const std::string &name, SymbolTable *ST) { BasicBlock *P = 0; Function *PP = 0; assert((ST == 0 || !getParent() || !getParent()->getParent() || - ST == getParent()->getParent()->getSymbolTable()) && + ST == &getParent()->getParent()->getSymbolTable()) && "Invalid symtab argument!"); if ((P = getParent()) && (PP = P->getParent()) && hasName()) - PP->getSymbolTable()->remove(this); + PP->getSymbolTable().remove(this); Value::setName(name); - if (PP && hasName()) PP->getSymbolTableSure()->insert(this); + if (PP && hasName()) PP->getSymbolTable().insert(this); } diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp index 8fe9113d82..0d3cc9bfa9 100644 --- a/lib/VMCore/Linker.cpp +++ b/lib/VMCore/Linker.cpp @@ -32,11 +32,8 @@ static inline bool Error(string *E, string Message) { // Make sure there are no type name conflicts. // static bool LinkTypes(Module *Dest, const Module *Src, string *Err = 0) { - // No symbol table? Can't have named types. - if (!Src->hasSymbolTable()) return false; - - SymbolTable *DestST = Dest->getSymbolTableSure(); - const SymbolTable *SrcST = Src->getSymbolTable(); + SymbolTable *DestST = &Dest->getSymbolTable(); + const SymbolTable *SrcST = &Src->getSymbolTable(); // Look for a type plane for Type's... SymbolTable::const_iterator PI = SrcST->find(Type::TypeTy); @@ -176,7 +173,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src, map<const Value*, Value*> &ValueMap, string *Err = 0) { // We will need a module level symbol table if the src module has a module // level symbol table... - SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0; + SymbolTable *ST = (SymbolTable*)&Src->getSymbolTable(); // Loop over all of the globals in the src module, mapping them over as we go // @@ -266,7 +263,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src, string *Err = 0) { // We will need a module level symbol table if the src module has a module // level symbol table... - SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0; + SymbolTable *ST = (SymbolTable*)&Src->getSymbolTable(); // Loop over all of the functions in the src module, mapping them over as we // go 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; diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp index ca74711b48..5f6f2e7835 100644 --- a/lib/VMCore/SlotCalculator.cpp +++ b/lib/VMCore/SlotCalculator.cpp @@ -90,9 +90,9 @@ void SlotCalculator::processModule() { // Insert constants that are named at module level into the slot pool so that // the module symbol table can refer to them... // - if (TheModule->hasSymbolTable() && !IgnoreNamedNodes) { + if (!IgnoreNamedNodes) { SC_DEBUG("Inserting SymbolTable values:\n"); - processSymbolTable(TheModule->getSymbolTable()); + processSymbolTable(&TheModule->getSymbolTable()); } SC_DEBUG("end processModule!\n"); @@ -156,8 +156,7 @@ void SlotCalculator::incorporateFunction(const Function *M) { // symboltable references to constants not in the output. Scan for these // constants now. // - if (M->hasSymbolTable()) - processSymbolTableConstants(M->getSymbolTable()); + processSymbolTableConstants(&M->getSymbolTable()); } SC_DEBUG("Inserting Labels:\n"); @@ -174,9 +173,9 @@ void SlotCalculator::incorporateFunction(const Function *M) { for_each(inst_begin(M), inst_end(M), bind_obj(this, &SlotCalculator::insertValue)); - if (M->hasSymbolTable() && !IgnoreNamedNodes) { + if (!IgnoreNamedNodes) { SC_DEBUG("Inserting SymbolTable values:\n"); - processSymbolTable(M->getSymbolTable()); + processSymbolTable(&M->getSymbolTable()); } SC_DEBUG("end processFunction!\n"); diff --git a/lib/VMCore/SymbolTableListTraitsImpl.h b/lib/VMCore/SymbolTableListTraitsImpl.h index 36b08ab9f6..682ea23d16 100644 --- a/lib/VMCore/SymbolTableListTraitsImpl.h +++ b/lib/VMCore/SymbolTableListTraitsImpl.h @@ -20,20 +20,20 @@ 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->getSymbolTable(); for (typename iplist<ValueSubClass>::iterator I = List.begin(); I != List.end(); ++I) - if (I->hasName()) SymTab->remove(I); + if (I->hasName()) SymTab.remove(I); } SymTabObject = STO; // Add all of the items to the new symtab... if (SymTabObject && !List.empty()) { - SymbolTable *SymTab = SymTabObject->getSymbolTableSure(); + SymbolTable &SymTab = SymTabObject->getSymbolTable(); for (typename iplist<ValueSubClass>::iterator I = List.begin(); I != List.end(); ++I) - if (I->hasName()) SymTab->insert(I); + if (I->hasName()) SymTab.insert(I); } } @@ -44,7 +44,7 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> assert(V->getParent() == 0 && "Value already in a container!!"); V->setParent(ItemParent); if (V->hasName() && SymTabObject) - SymTabObject->getSymbolTableSure()->insert(V); + SymTabObject->getSymbolTable().insert(V); } template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, @@ -53,7 +53,7 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> ::removeNodeFromList(ValueSubClass *V) { V->setParent(0); if (V->hasName() && SymTabObject) - SymTabObject->getSymbolTable()->remove(V); + SymTabObject->getSymbolTable().remove(V); } template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass, @@ -74,10 +74,10 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass> ValueSubClass &V = *first; bool HasName = V.hasName(); if (OldSTO && HasName) - OldSTO->getSymbolTable()->remove(&V); + OldSTO->getSymbolTable().remove(&V); V.setParent(NewIP); if (NewSTO && HasName) - NewSTO->getSymbolTableSure()->insert(&V); + NewSTO->getSymbolTable().insert(&V); } } else { // Just transfering between blocks in the same function, simply update the diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index da3449b95c..812ca4a868 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -124,7 +124,7 @@ namespace { // Anonymous namespace for class } // Verification methods... - void verifySymbolTable(SymbolTable *ST); + void verifySymbolTable(SymbolTable &ST); void visitFunction(Function &F); void visitBasicBlock(BasicBlock &BB); void visitPHINode(PHINode &PN); @@ -172,11 +172,9 @@ namespace { // Anonymous namespace for class // verifySymbolTable - Verify that a function or module symbol table is ok // -void Verifier::verifySymbolTable(SymbolTable *ST) { - if (ST == 0) return; // No symbol table to process - +void Verifier::verifySymbolTable(SymbolTable &ST) { // Loop over all of the types in the symbol table... - for (SymbolTable::iterator TI = ST->begin(), TE = ST->end(); TI != TE; ++TI) + for (SymbolTable::iterator TI = ST.begin(), TE = ST.end(); TI != TE; ++TI) for (SymbolTable::type_iterator I = TI->second.begin(), E = TI->second.end(); I != E; ++I) { Value *V = I->second; |