diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-02-05 20:47:22 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-02-05 20:47:22 +0000 |
commit | ef9b9a793949469cdaa4ab6d0173136229dcab7b (patch) | |
tree | 137b30d24ba219e5e745a11abb3807a9c4964aaa /lib/VMCore/Module.cpp | |
parent | 15468bfc22302b4f79300252425d74cd6865f8b1 (diff) |
For PR411:
This patch replaces the SymbolTable class with ValueSymbolTable which does
not support types planes. This means that all symbol names in LLVM must now
be unique. The patch addresses the necessary changes to deal with this and
removes code no longer needed as a result. This completes the bulk of the
changes for this PR. Some cleanup patches will follow.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33918 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Module.cpp')
-rw-r--r-- | lib/VMCore/Module.cpp | 112 |
1 files changed, 18 insertions, 94 deletions
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index efa6e6c7c0..163d8d2ac1 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -69,7 +69,7 @@ Module::Module(const std::string &MID) FunctionList.setParent(this); GlobalList.setItemParent(this); GlobalList.setParent(this); - ValSymTab = new SymbolTable(); + ValSymTab = new ValueSymbolTable(); TypeSymTab = new TypeSymbolTable(); } @@ -132,15 +132,19 @@ Module::PointerSize Module::getPointerSize() const { // Methods for easy access to the functions in the module. // +// 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 +// the symbol table directly for this common task. +// Constant *Module::getOrInsertFunction(const std::string &Name, const FunctionType *Ty) { - SymbolTable &SymTab = getValueSymbolTable(); + ValueSymbolTable &SymTab = getValueSymbolTable(); - // See if we have a definitions for the specified function already. - Function *F = - dyn_cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name)); + // See if we have a definition for the specified function already. + Function *F = dyn_cast_or_null<Function>(SymTab.lookup(Name)); if (F == 0) { - // Nope, add it. + // Nope, add it Function *New = new Function(Ty, GlobalVariable::ExternalLinkage, Name); FunctionList.push_back(New); return New; // Return the new prototype. @@ -149,7 +153,7 @@ Constant *Module::getOrInsertFunction(const std::string &Name, // Okay, the function exists. Does it have externally visible linkage? if (F->hasInternalLinkage()) { // Rename the function. - F->setName(SymTab.getUniqueName(F->getType(), F->getName())); + F->setName(SymTab.getUniqueName(F->getName())); // Retry, now there won't be a conflict. return getOrInsertFunction(Name, Ty); } @@ -188,73 +192,9 @@ Constant *Module::getOrInsertFunction(const std::string &Name, // getFunction - Look up the specified function in the module symbol table. // If it does not exist, return null. // -Function *Module::getFunction(const std::string &Name, const FunctionType *Ty) { - SymbolTable &SymTab = getValueSymbolTable(); - return cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name)); -} - - -/// getMainFunction - This function looks up main efficiently. This is such a -/// common case, that it is a method in Module. If main cannot be found, a -/// null pointer is returned. -/// -Function *Module::getMainFunction() { - std::vector<const Type*> Params; - - // int main(void)... - if (Function *F = getFunction("main", FunctionType::get(Type::Int32Ty, - Params, false))) - return F; - - // void main(void)... - if (Function *F = getFunction("main", FunctionType::get(Type::VoidTy, - Params, false))) - return F; - - Params.push_back(Type::Int32Ty); - - // int main(int argc)... - if (Function *F = getFunction("main", FunctionType::get(Type::Int32Ty, - Params, false))) - return F; - - // void main(int argc)... - if (Function *F = getFunction("main", FunctionType::get(Type::VoidTy, - Params, false))) - return F; - - for (unsigned i = 0; i != 2; ++i) { // Check argv and envp - Params.push_back(PointerType::get(PointerType::get(Type::Int8Ty))); - - // int main(int argc, char **argv)... - if (Function *F = getFunction("main", FunctionType::get(Type::Int32Ty, - Params, false))) - return F; - - // void main(int argc, char **argv)... - if (Function *F = getFunction("main", FunctionType::get(Type::VoidTy, - Params, false))) - return F; - } - - // Ok, try to find main the hard way... - return getNamedFunction("main"); -} - -/// getNamedFunction - Return the first function in the module with the -/// specified name, of arbitrary type. This method returns null if a function -/// with the specified name is not found. -/// -Function *Module::getNamedFunction(const std::string &Name) const { - // Loop over all of the functions, looking for the function desired - const Function *Found = 0; - for (const_iterator I = begin(), E = end(); I != E; ++I) - if (I->getName() == Name) - if (I->isDeclaration()) - Found = I; - else - return const_cast<Function*>(&(*I)); - return const_cast<Function*>(Found); // Non-external function not found... +Function *Module::getFunction(const std::string &Name) const { + const ValueSymbolTable &SymTab = getValueSymbolTable(); + return dyn_cast_or_null<Function>(SymTab.lookup(Name)); } //===----------------------------------------------------------------------===// @@ -269,31 +209,15 @@ Function *Module::getNamedFunction(const std::string &Name) const { /// have InternalLinkage. By default, these types are not returned. /// GlobalVariable *Module::getGlobalVariable(const std::string &Name, - const Type *Ty, bool AllowInternal) { - if (Value *V = getValueSymbolTable().lookup(PointerType::get(Ty), Name)) { - GlobalVariable *Result = cast<GlobalVariable>(V); - if (AllowInternal || !Result->hasInternalLinkage()) + bool AllowInternal) const { + if (Value *V = ValSymTab->lookup(Name)) { + GlobalVariable *Result = dyn_cast<GlobalVariable>(V); + if (Result && (AllowInternal || !Result->hasInternalLinkage())) return Result; } return 0; } -/// getNamedGlobal - Return the first global variable in the module with the -/// specified name, of arbitrary type. This method returns null if a global -/// with the specified name is not found. -/// -GlobalVariable *Module::getNamedGlobal(const std::string &Name) const { - // FIXME: This would be much faster with a symbol table that doesn't - // discriminate based on type! - for (const_global_iterator I = global_begin(), E = global_end(); - I != E; ++I) - if (I->getName() == Name) - return const_cast<GlobalVariable*>(&(*I)); - return 0; -} - - - //===----------------------------------------------------------------------===// // Methods for easy access to the types in the module. // |