X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FModule.cpp;h=a598005e2a8946336fcd13efb190a10231d67dd8;hb=baeb911d60401818dc9fe0db6182cd048e4fdd03;hp=896245d69e6754cb2b21cb9304f7b164fcc00c05;hpb=d24479730a8790d82c4859dc477bc2416d7a6bda;p=oota-llvm.git diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 896245d69e6..a598005e2a8 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -29,14 +29,6 @@ using namespace llvm; // Methods to implement the globals and functions lists. // -Function *ilist_traits::createSentinel() { - FunctionType *FTy = - FunctionType::get(Type::VoidTy, std::vector(), false); - Function *Ret = Function::Create(FTy, GlobalValue::ExternalLinkage); - // This should not be garbage monitored. - LeakDetector::removeGarbageObject(Ret); - return Ret; -} GlobalVariable *ilist_traits::createSentinel() { GlobalVariable *Ret = new GlobalVariable(Type::Int32Ty, false, GlobalValue::ExternalLinkage); @@ -52,16 +44,6 @@ GlobalAlias *ilist_traits::createSentinel() { return Ret; } -iplist &ilist_traits::getList(Module *M) { - return M->getFunctionList(); -} -iplist &ilist_traits::getList(Module *M) { - return M->getGlobalList(); -} -iplist &ilist_traits::getList(Module *M) { - return M->getAliasList(); -} - // Explicit instantiations of SymbolTableListTraits since some of the methods // are not in the public header file. template class SymbolTableListTraits; @@ -127,6 +109,18 @@ Module::PointerSize Module::getPointerSize() const { return ret; } +/// getNamedValue - Return the first global value in the module with +/// the specified name, of arbitrary type. This method returns null +/// if a global with the specified name is not found. +GlobalValue *Module::getNamedValue(const std::string &Name) const { + return cast_or_null(getValueSymbolTable().lookup(Name)); +} + +GlobalValue *Module::getNamedValue(const char *Name) const { + llvm::Value *V = getValueSymbolTable().lookup(Name, Name+strlen(Name)); + return cast_or_null(V); +} + //===----------------------------------------------------------------------===// // Methods for easy access to the functions in the module. // @@ -139,10 +133,8 @@ Module::PointerSize Module::getPointerSize() const { Constant *Module::getOrInsertFunction(const std::string &Name, const FunctionType *Ty, AttrListPtr AttributeList) { - ValueSymbolTable &SymTab = getValueSymbolTable(); - // See if we have a definition for the specified function already. - GlobalValue *F = dyn_cast_or_null(SymTab.lookup(Name)); + GlobalValue *F = getNamedValue(Name); if (F == 0) { // Nope, add it Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name); @@ -174,10 +166,8 @@ Constant *Module::getOrInsertFunction(const std::string &Name, Constant *Module::getOrInsertTargetIntrinsic(const std::string &Name, const FunctionType *Ty, AttrListPtr AttributeList) { - ValueSymbolTable &SymTab = getValueSymbolTable(); - // See if we have a definition for the specified function already. - GlobalValue *F = dyn_cast_or_null(SymTab.lookup(Name)); + GlobalValue *F = getNamedValue(Name); if (F == 0) { // Nope, add it Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name); @@ -240,13 +230,11 @@ Constant *Module::getOrInsertFunction(const std::string &Name, // If it does not exist, return null. // Function *Module::getFunction(const std::string &Name) const { - const ValueSymbolTable &SymTab = getValueSymbolTable(); - return dyn_cast_or_null(SymTab.lookup(Name)); + return dyn_cast_or_null(getNamedValue(Name)); } Function *Module::getFunction(const char *Name) const { - const ValueSymbolTable &SymTab = getValueSymbolTable(); - return dyn_cast_or_null(SymTab.lookup(Name, Name+strlen(Name))); + return dyn_cast_or_null(getNamedValue(Name)); } //===----------------------------------------------------------------------===// @@ -262,11 +250,10 @@ Function *Module::getFunction(const char *Name) const { /// GlobalVariable *Module::getGlobalVariable(const std::string &Name, bool AllowLocal) const { - if (Value *V = ValSymTab->lookup(Name)) { - GlobalVariable *Result = dyn_cast(V); - if (Result && (AllowLocal || !Result->hasLocalLinkage())) + if (GlobalVariable *Result = + dyn_cast_or_null(getNamedValue(Name))) + if (AllowLocal || !Result->hasLocalLinkage()) return Result; - } return 0; } @@ -277,10 +264,8 @@ GlobalVariable *Module::getGlobalVariable(const std::string &Name, /// 3. Finally, if the existing global is the correct delclaration, return the /// existing global. Constant *Module::getOrInsertGlobal(const std::string &Name, const Type *Ty) { - ValueSymbolTable &SymTab = getValueSymbolTable(); - // See if we have a definition for the specified global already. - GlobalVariable *GV = dyn_cast_or_null(SymTab.lookup(Name)); + GlobalVariable *GV = dyn_cast_or_null(getNamedValue(Name)); if (GV == 0) { // Nope, add it GlobalVariable *New = @@ -306,8 +291,7 @@ Constant *Module::getOrInsertGlobal(const std::string &Name, const Type *Ty) { // If it does not exist, return null. // GlobalAlias *Module::getNamedAlias(const std::string &Name) const { - const ValueSymbolTable &SymTab = getValueSymbolTable(); - return dyn_cast_or_null(SymTab.lookup(Name)); + return dyn_cast_or_null(getNamedValue(Name)); } //===----------------------------------------------------------------------===//