[llvm] r185502 - Added support in FunctionAttrs for adding relevant function/argument attributes for the posix call gettimeofday.

Michael Gottesman mgottesman at apple.com
Tue Jul 2 21:00:55 PDT 2013


Author: mgottesman
Date: Tue Jul  2 23:00:54 2013
New Revision: 185502

URL: http://llvm.org/viewvc/llvm-project?rev=185502&view=rev
Log:
Added support in FunctionAttrs for adding relevant function/argument attributes for the posix call gettimeofday.

This implies annotating it as nounwind and its arguments as nocapture. To be
conservative, we do not annotate the arguments with noalias since some platforms
do not have restrict on the declaration for gettimeofday.

Modified:
    llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
    llvm/trunk/test/Transforms/FunctionAttrs/annotate-1.ll

Modified: llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp?rev=185502&r1=185501&r2=185502&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp Tue Jul  2 23:00:54 2013
@@ -1310,6 +1310,16 @@ bool FunctionAttrs::inferPrototypeAttrib
     // May throw; "open" is a valid pthread cancellation point.
     setDoesNotCapture(F, 1);
     break;
+  case LibFunc::gettimeofday:
+    if (FTy->getNumParams() != 2 || !FTy->getParamType(0)->isPointerTy() ||
+        !FTy->getParamType(1)->isPointerTy())
+      return false;
+    // Currently some platforms have the restrict keyword on the arguments to
+    // gettimeofday. To be conservative, do not add noalias to gettimeofday's
+    // arguments.
+    setDoesNotThrow(F);
+    setDoesNotCapture(F, 1);
+    setDoesNotCapture(F, 2);
   default:
     // Didn't mark any attributes.
     return false;

Modified: llvm/trunk/test/Transforms/FunctionAttrs/annotate-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/annotate-1.ll?rev=185502&r1=185501&r2=185502&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/annotate-1.ll (original)
+++ llvm/trunk/test/Transforms/FunctionAttrs/annotate-1.ll Tue Jul  2 23:00:54 2013
@@ -14,5 +14,8 @@ declare i32* @realloc(i32*, i32)
 declare i32 @strcpy(...)
 ; CHECK: declare i32 @strcpy(...)
 
+declare i32 @gettimeofday(i8*, i8*)
+; CHECK: declare i32 @gettimeofday(i8* nocapture, i8* nocapture) [[G0]]
+
 ; CHECK: attributes [[G0]] = { nounwind }
 ; CHECK: attributes [[G1]] = { nounwind readonly }





More information about the llvm-commits mailing list