forked from OSchip/llvm-project
Add Module::getNamedValue; use to normalize access to Module symbol
table. - No functionality change. llvm-svn: 66289
This commit is contained in:
parent
6e447e08ee
commit
dcf8d3c9eb
|
@ -182,6 +182,16 @@ public:
|
||||||
GlobalScopeAsm += '\n';
|
GlobalScopeAsm += '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @}
|
||||||
|
/// @name Generic Value Accessors
|
||||||
|
/// @{
|
||||||
|
|
||||||
|
/// 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 *getNamedValue(const std::string &Name) const;
|
||||||
|
GlobalValue *getNamedValue(const char *Name) const;
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Function Accessors
|
/// @name Function Accessors
|
||||||
/// @{
|
/// @{
|
||||||
|
|
|
@ -127,6 +127,18 @@ Module::PointerSize Module::getPointerSize() const {
|
||||||
return ret;
|
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<GlobalValue>(getValueSymbolTable().lookup(Name));
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalValue *Module::getNamedValue(const char *Name) const {
|
||||||
|
llvm::Value *V = getValueSymbolTable().lookup(Name, Name+strlen(Name));
|
||||||
|
return cast_or_null<GlobalValue>(V);
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Methods for easy access to the functions in the module.
|
// Methods for easy access to the functions in the module.
|
||||||
//
|
//
|
||||||
|
@ -139,10 +151,8 @@ Module::PointerSize Module::getPointerSize() const {
|
||||||
Constant *Module::getOrInsertFunction(const std::string &Name,
|
Constant *Module::getOrInsertFunction(const std::string &Name,
|
||||||
const FunctionType *Ty,
|
const FunctionType *Ty,
|
||||||
AttrListPtr AttributeList) {
|
AttrListPtr AttributeList) {
|
||||||
ValueSymbolTable &SymTab = getValueSymbolTable();
|
|
||||||
|
|
||||||
// See if we have a definition for the specified function already.
|
// See if we have a definition for the specified function already.
|
||||||
GlobalValue *F = dyn_cast_or_null<GlobalValue>(SymTab.lookup(Name));
|
GlobalValue *F = getNamedValue(Name);
|
||||||
if (F == 0) {
|
if (F == 0) {
|
||||||
// Nope, add it
|
// Nope, add it
|
||||||
Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
|
Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
|
||||||
|
@ -174,10 +184,8 @@ Constant *Module::getOrInsertFunction(const std::string &Name,
|
||||||
Constant *Module::getOrInsertTargetIntrinsic(const std::string &Name,
|
Constant *Module::getOrInsertTargetIntrinsic(const std::string &Name,
|
||||||
const FunctionType *Ty,
|
const FunctionType *Ty,
|
||||||
AttrListPtr AttributeList) {
|
AttrListPtr AttributeList) {
|
||||||
ValueSymbolTable &SymTab = getValueSymbolTable();
|
|
||||||
|
|
||||||
// See if we have a definition for the specified function already.
|
// See if we have a definition for the specified function already.
|
||||||
GlobalValue *F = dyn_cast_or_null<GlobalValue>(SymTab.lookup(Name));
|
GlobalValue *F = getNamedValue(Name);
|
||||||
if (F == 0) {
|
if (F == 0) {
|
||||||
// Nope, add it
|
// Nope, add it
|
||||||
Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
|
Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
|
||||||
|
@ -240,13 +248,11 @@ Constant *Module::getOrInsertFunction(const std::string &Name,
|
||||||
// If it does not exist, return null.
|
// If it does not exist, return null.
|
||||||
//
|
//
|
||||||
Function *Module::getFunction(const std::string &Name) const {
|
Function *Module::getFunction(const std::string &Name) const {
|
||||||
const ValueSymbolTable &SymTab = getValueSymbolTable();
|
return dyn_cast_or_null<Function>(getNamedValue(Name));
|
||||||
return dyn_cast_or_null<Function>(SymTab.lookup(Name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Function *Module::getFunction(const char *Name) const {
|
Function *Module::getFunction(const char *Name) const {
|
||||||
const ValueSymbolTable &SymTab = getValueSymbolTable();
|
return dyn_cast_or_null<Function>(getNamedValue(Name));
|
||||||
return dyn_cast_or_null<Function>(SymTab.lookup(Name, Name+strlen(Name)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -262,11 +268,10 @@ Function *Module::getFunction(const char *Name) const {
|
||||||
///
|
///
|
||||||
GlobalVariable *Module::getGlobalVariable(const std::string &Name,
|
GlobalVariable *Module::getGlobalVariable(const std::string &Name,
|
||||||
bool AllowLocal) const {
|
bool AllowLocal) const {
|
||||||
if (Value *V = ValSymTab->lookup(Name)) {
|
if (GlobalVariable *Result =
|
||||||
GlobalVariable *Result = dyn_cast<GlobalVariable>(V);
|
dyn_cast_or_null<GlobalVariable>(getNamedValue(Name)))
|
||||||
if (Result && (AllowLocal || !Result->hasLocalLinkage()))
|
if (AllowLocal || !Result->hasLocalLinkage())
|
||||||
return Result;
|
return Result;
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,10 +282,8 @@ GlobalVariable *Module::getGlobalVariable(const std::string &Name,
|
||||||
/// 3. Finally, if the existing global is the correct delclaration, return the
|
/// 3. Finally, if the existing global is the correct delclaration, return the
|
||||||
/// existing global.
|
/// existing global.
|
||||||
Constant *Module::getOrInsertGlobal(const std::string &Name, const Type *Ty) {
|
Constant *Module::getOrInsertGlobal(const std::string &Name, const Type *Ty) {
|
||||||
ValueSymbolTable &SymTab = getValueSymbolTable();
|
|
||||||
|
|
||||||
// See if we have a definition for the specified global already.
|
// See if we have a definition for the specified global already.
|
||||||
GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(SymTab.lookup(Name));
|
GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(getNamedValue(Name));
|
||||||
if (GV == 0) {
|
if (GV == 0) {
|
||||||
// Nope, add it
|
// Nope, add it
|
||||||
GlobalVariable *New =
|
GlobalVariable *New =
|
||||||
|
@ -306,8 +309,7 @@ Constant *Module::getOrInsertGlobal(const std::string &Name, const Type *Ty) {
|
||||||
// If it does not exist, return null.
|
// If it does not exist, return null.
|
||||||
//
|
//
|
||||||
GlobalAlias *Module::getNamedAlias(const std::string &Name) const {
|
GlobalAlias *Module::getNamedAlias(const std::string &Name) const {
|
||||||
const ValueSymbolTable &SymTab = getValueSymbolTable();
|
return dyn_cast_or_null<GlobalAlias>(getNamedValue(Name));
|
||||||
return dyn_cast_or_null<GlobalAlias>(SymTab.lookup(Name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
Loading…
Reference in New Issue