Add a mechanism to specify attributes in getOrInsertFunction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61645 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky
2009-01-04 22:54:40 +00:00
parent ad7d1e2085
commit 1186bf1350
2 changed files with 38 additions and 4 deletions

View File

@ -194,6 +194,9 @@ public:
/// the existing function. /// the existing function.
/// 4. Finally, the function exists but has the wrong prototype: return the /// 4. Finally, the function exists but has the wrong prototype: return the
/// function with a constantexpr cast to the right prototype. /// function with a constantexpr cast to the right prototype.
Constant *getOrInsertFunction(const std::string &Name, const FunctionType *T,
AttrListPtr AttributeList);
Constant *getOrInsertFunction(const std::string &Name, const FunctionType *T); Constant *getOrInsertFunction(const std::string &Name, const FunctionType *T);
/// getOrInsertFunction - Look up the specified function in the module symbol /// getOrInsertFunction - Look up the specified function in the module symbol
@ -203,7 +206,11 @@ public:
/// named function has a different type. This version of the method takes a /// named function has a different type. This version of the method takes a
/// null terminated list of function arguments, which makes it easier for /// null terminated list of function arguments, which makes it easier for
/// clients to use. /// clients to use.
Constant *getOrInsertFunction(const std::string &Name, const Type *RetTy,...) Constant *getOrInsertFunction(const std::string &Name,
AttrListPtr AttributeList,
const Type *RetTy, ...) END_WITH_NULL;
Constant *getOrInsertFunction(const std::string &Name, const Type *RetTy, ...)
END_WITH_NULL; END_WITH_NULL;
/// getFunction - Look up the specified function in the module symbol table. /// getFunction - Look up the specified function in the module symbol table.

View File

@ -137,7 +137,8 @@ Module::PointerSize Module::getPointerSize() const {
// the symbol table directly for this common task. // the symbol table directly for this common task.
// //
Constant *Module::getOrInsertFunction(const std::string &Name, Constant *Module::getOrInsertFunction(const std::string &Name,
const FunctionType *Ty) { const FunctionType *Ty,
AttrListPtr AttributeList) {
ValueSymbolTable &SymTab = getValueSymbolTable(); 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.
@ -145,6 +146,8 @@ Constant *Module::getOrInsertFunction(const std::string &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);
if (!New->isIntrinsic()) // Intrinsics get attrs set on construction
New->setAttributes(AttributeList);
FunctionList.push_back(New); FunctionList.push_back(New);
return New; // Return the new prototype. return New; // Return the new prototype.
} }
@ -168,11 +171,35 @@ Constant *Module::getOrInsertFunction(const std::string &Name,
return F; return F;
} }
Constant *Module::getOrInsertFunction(const std::string &Name,
const FunctionType *Ty) {
AttrListPtr AttributeList = AttrListPtr::get((AttributeWithIndex *)0, 0);
return getOrInsertFunction(Name, Ty, AttributeList);
}
// getOrInsertFunction - Look up the specified function in the module symbol // 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. // table. If it does not exist, add a prototype for the function and return it.
// This version of the method takes a null terminated list of function // This version of the method takes a null terminated list of function
// arguments, which makes it easier for clients to use. // arguments, which makes it easier for clients to use.
// //
Constant *Module::getOrInsertFunction(const std::string &Name,
AttrListPtr AttributeList,
const Type *RetTy, ...) {
va_list Args;
va_start(Args, RetTy);
// Build the list of argument types...
std::vector<const Type*> ArgTys;
while (const Type *ArgTy = va_arg(Args, const Type*))
ArgTys.push_back(ArgTy);
va_end(Args);
// Build the function type and chain to the other getOrInsertFunction...
return getOrInsertFunction(Name, FunctionType::get(RetTy, ArgTys, false),
AttributeList);
}
Constant *Module::getOrInsertFunction(const std::string &Name, Constant *Module::getOrInsertFunction(const std::string &Name,
const Type *RetTy, ...) { const Type *RetTy, ...) {
va_list Args; va_list Args;
@ -186,10 +213,10 @@ Constant *Module::getOrInsertFunction(const std::string &Name,
va_end(Args); va_end(Args);
// Build the function type and chain to the other getOrInsertFunction... // Build the function type and chain to the other getOrInsertFunction...
return getOrInsertFunction(Name, FunctionType::get(RetTy, ArgTys, false)); return getOrInsertFunction(Name, FunctionType::get(RetTy, ArgTys, false),
AttrListPtr::get((AttributeWithIndex *)0, 0));
} }
// getFunction - Look up the specified function in the module symbol table. // getFunction - Look up the specified function in the module symbol table.
// If it does not exist, return null. // If it does not exist, return null.
// //