Teach FunctionAttrs about AccessesArgumentsReadonly.
authorDan Gohman <gohman@apple.com>
Tue, 9 Nov 2010 19:56:27 +0000 (19:56 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 9 Nov 2010 19:56:27 +0000 (19:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118617 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/FunctionAttrs.cpp

index a2173933efb81c814c321bc7bbebc02d711b85bd..71671d6fe9a5a0d68709aeb208571df430703a09 100644 (file)
@@ -152,6 +152,25 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
           }
           // Only reads and writes local memory.
           continue;
+        case AliasAnalysis::AccessesArgumentsReadonly:
+          // Check whether all pointer arguments point to local memory, and
+          // ignore calls that only access local memory.
+          for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
+               CI != CE; ++CI) {
+            Value *Arg = *CI;
+            if (Arg->getType()->isPointerTy()) {
+              AliasAnalysis::Location Loc(Arg,
+                                          AliasAnalysis::UnknownSize,
+                                          I->getMetadata(LLVMContext::MD_tbaa));
+              if (!AA->pointsToConstantMemory(Loc, /*OrLocal=*/true)) {
+                // Reads non-local memory.
+                ReadsMemory = true;
+                break;
+              }
+            }
+          }
+          // Only reads memory.
+          continue;
         default:
           // Otherwise, be conservative.
           break;