diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2009-01-04 22:54:40 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2009-01-04 22:54:40 +0000 |
commit | 1186bf1350145474bb7f0ab4d38ec33dae5c79d2 (patch) | |
tree | ea2b8faf1b143ea71bc2de6eb1a0e40cde250355 /lib/VMCore/Module.cpp | |
parent | ad7d1e2085a489dbedc65b99bab811771ead1aab (diff) |
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
Diffstat (limited to 'lib/VMCore/Module.cpp')
-rw-r--r-- | lib/VMCore/Module.cpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index b7bb49184b..d5b48c0a73 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -137,7 +137,8 @@ Module::PointerSize Module::getPointerSize() const { // the symbol table directly for this common task. // Constant *Module::getOrInsertFunction(const std::string &Name, - const FunctionType *Ty) { + const FunctionType *Ty, + AttrListPtr AttributeList) { ValueSymbolTable &SymTab = getValueSymbolTable(); // 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) { // Nope, add it Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name); + if (!New->isIntrinsic()) // Intrinsics get attrs set on construction + New->setAttributes(AttributeList); FunctionList.push_back(New); return New; // Return the new prototype. } @@ -168,12 +171,19 @@ Constant *Module::getOrInsertFunction(const std::string &Name, 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 // 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 // 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); @@ -186,9 +196,26 @@ Constant *Module::getOrInsertFunction(const std::string &Name, va_end(Args); // 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), + AttributeList); } +Constant *Module::getOrInsertFunction(const std::string &Name, + 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), + AttrListPtr::get((AttributeWithIndex *)0, 0)); +} // getFunction - Look up the specified function in the module symbol table. // If it does not exist, return null. |