[llvm-commits] [llvm] r61645 - in /llvm/trunk: include/llvm/Module.h lib/VMCore/Module.cpp

Nick Lewycky nicholas at mxc.ca
Sun Jan 4 14:54:40 PST 2009


Author: nicholas
Date: Sun Jan  4 16:54:40 2009
New Revision: 61645

URL: http://llvm.org/viewvc/llvm-project?rev=61645&view=rev
Log:
Add a mechanism to specify attributes in getOrInsertFunction.

Modified:
    llvm/trunk/include/llvm/Module.h
    llvm/trunk/lib/VMCore/Module.cpp

Modified: llvm/trunk/include/llvm/Module.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Module.h?rev=61645&r1=61644&r2=61645&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Module.h (original)
+++ llvm/trunk/include/llvm/Module.h Sun Jan  4 16:54:40 2009
@@ -194,6 +194,9 @@
   ///      the existing function.
   ///   4. Finally, the function exists but has the wrong prototype: return the
   ///      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);
 
   /// getOrInsertFunction - Look up the specified function in the module symbol
@@ -203,7 +206,11 @@
   /// named function has a different type.  This version of the method takes a
   /// null terminated list of function arguments, which makes it easier for
   /// 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;
 
   /// getFunction - Look up the specified function in the module symbol table.

Modified: llvm/trunk/lib/VMCore/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Module.cpp?rev=61645&r1=61644&r2=61645&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Module.cpp (original)
+++ llvm/trunk/lib/VMCore/Module.cpp Sun Jan  4 16:54:40 2009
@@ -137,7 +137,8 @@
 // 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 @@
   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 @@
   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 @@
   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.





More information about the llvm-commits mailing list