Factor out the code for testing whether a function accesses
authorDan Gohman <gohman@apple.com>
Wed, 10 Nov 2010 17:34:04 +0000 (17:34 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 10 Nov 2010 17:34:04 +0000 (17:34 +0000)
arbitrary memory into a helper function, and adjust some comments.

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

include/llvm/Analysis/AliasAnalysis.h
lib/Transforms/IPO/FunctionAttrs.cpp

index 6b716ddee9478dde6b64166eaf1511e657a9cb2e..12b2090b174914d4bc8e95e9a1683335eeaf22c4 100644 (file)
@@ -268,14 +268,21 @@ public:
     return onlyReadsMemory(getModRefBehavior(F));
   }
 
-  /// onlyReadsMemory - If the functions with the specified behavior are known
-  /// to only read from non-volatile memory (or not access memory at all), return
-  /// true.  For use when the call site is not known.
+  /// onlyReadsMemory - Return true if functions with the specified behavior are
+  /// known to only read from non-volatile memory (or not access memory at all).
   ///
   static bool onlyReadsMemory(ModRefBehavior MRB) {
     return !(MRB & Mod);
   }
 
+  /// onlyAccessesArgPointees - Return true if functions with the specified
+  /// behavior are known to read at most from objects pointed to by their
+  /// pointer-typed arguments (with arbitrary offsets).
+  ///
+  static bool onlyAccessesArgPointees(ModRefBehavior MRB) {
+    return !(MRB & Anywhere & ~ArgumentPointees);
+  }
+
   /// getModRefInfo - Return information about whether or not an instruction may
   /// read or write the specified memory location.  An instruction
   /// that doesn't read or write memory may be trivially LICM'd for example.
index 3b1b13d378fcd8c000c1119f081492787ec849ec..2e3440066e6c5f680e4663702e7cbeed9a4761eb 100644 (file)
@@ -131,9 +131,8 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
         AliasAnalysis::ModRefBehavior MRB = AA->getModRefBehavior(CS);
         // If the call doesn't access arbitrary memory, we may be able to
         // figure out something.
-        if (!(MRB & AliasAnalysis::Anywhere &
-              ~AliasAnalysis::ArgumentPointees)) {
-          // If the call accesses argument pointees, check each argument.
+        if (AliasAnalysis::onlyAccessesArgPointees(MRB)) {
+          // If the call does access argument pointees, check each argument.
           if (MRB & AliasAnalysis::AccessesArguments)
             // Check whether all pointer arguments point to local memory, and
             // ignore calls that only access local memory.