Added support in FunctionAttrs for adding relevant function/argument attributes for...
authorMichael Gottesman <mgottesman@apple.com>
Wed, 3 Jul 2013 04:00:54 +0000 (04:00 +0000)
committerMichael Gottesman <mgottesman@apple.com>
Wed, 3 Jul 2013 04:00:54 +0000 (04:00 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185502 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/FunctionAttrs.cpp
test/Transforms/FunctionAttrs/annotate-1.ll

index 79ce3c330572c542c0d4a9f15e0bbb9d8f5e4396..7df556ebffae7019aefb7722b01db61d4e8f14d6 100644 (file)
@@ -1310,6 +1310,16 @@ bool FunctionAttrs::inferPrototypeAttributes(Function &F) {
     // 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;
index ae77380acc4a1e1f85a9b0a8ba7952abc63b833a..d8e90cf1c38158d767637a65cb6ad7315c15f2a0 100644 (file)
@@ -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 }