Integrate the readonly/readnone logic more deeply
into alias analysis.  This meant updating the API
which now has versions of the getModRefBehavior,
doesNotAccessMemory and onlyReadsMemory methods
which take a callsite parameter.  These should be
used unless the callsite is not known, since in
general they can do a better job than the versions
that take a function.  Also, users should no longer
call the version of getModRefBehavior that takes
both a function and a callsite.  To reduce the
chance of misuse it is now protected.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44487 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/AliasAnalysis.cpp b/lib/Analysis/AliasAnalysis.cpp
index 2a3ac5a..9e1ae2a 100644
--- a/lib/Analysis/AliasAnalysis.cpp
+++ b/lib/Analysis/AliasAnalysis.cpp
@@ -27,6 +27,7 @@
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Pass.h"
 #include "llvm/BasicBlock.h"
+#include "llvm/Function.h"
 #include "llvm/Instructions.h"
 #include "llvm/Type.h"
 #include "llvm/Target/TargetData.h"
@@ -112,16 +113,40 @@
   return pointsToConstantMemory(P) ? NoModRef : Mod;
 }
 
+AliasAnalysis::ModRefBehavior
+AliasAnalysis::getModRefBehavior(CallSite CS,
+                                 std::vector<PointerAccessInfo> *Info) {
+  if (CS.paramHasAttr(0, ParamAttr::ReadNone))
+    // Can't do better than this.
+    return DoesNotAccessMemory;
+  ModRefBehavior MRB = UnknownModRefBehavior;
+  if (Function *F = CS.getCalledFunction())
+    MRB = getModRefBehavior(F, CS, Info);
+  if (MRB != DoesNotAccessMemory && CS.paramHasAttr(0, ParamAttr::ReadOnly))
+    return OnlyReadsMemory;
+  return MRB;
+}
+
+AliasAnalysis::ModRefBehavior
+AliasAnalysis::getModRefBehavior(Function *F,
+                                 std::vector<PointerAccessInfo> *Info) {
+  if (F->paramHasAttr(0, ParamAttr::ReadNone))
+    // Can't do better than this.
+    return DoesNotAccessMemory;
+  ModRefBehavior MRB = getModRefBehavior(F, CallSite(), Info);
+  if (MRB != DoesNotAccessMemory && F->paramHasAttr(0, ParamAttr::ReadOnly))
+    return OnlyReadsMemory;
+  return MRB;
+}
+
 AliasAnalysis::ModRefResult
 AliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
   ModRefResult Mask = ModRef;
-  if (Function *F = CS.getCalledFunction()) {
-    ModRefBehavior MRB = getModRefBehavior(F, CallSite());
-    if (MRB == OnlyReadsMemory)
-      Mask = Ref;
-    else if (MRB == DoesNotAccessMemory)
-      return NoModRef;
-  }
+  ModRefBehavior MRB = getModRefBehavior(CS);
+  if (MRB == OnlyReadsMemory)
+    Mask = Ref;
+  else if (MRB == DoesNotAccessMemory)
+    return NoModRef;
 
   if (!AA) return Mask;