Introduce a symbolic constant for ~0u for use with AliasAnalysis.
authorDan Gohman <gohman@apple.com>
Tue, 3 Aug 2010 01:03:11 +0000 (01:03 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 3 Aug 2010 01:03:11 +0000 (01:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110091 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/AliasAnalysis.h
lib/Analysis/BasicAliasAnalysis.cpp
lib/Analysis/ScalarEvolutionAliasAnalysis.cpp

index e0068dc7b20537e9e21603df21afc8042fe74aac..ef3a38a69e360a6edf916da344735d9161c2e4a0 100644 (file)
@@ -64,6 +64,11 @@ public:
   AliasAnalysis() : TD(0), AA(0) {}
   virtual ~AliasAnalysis();  // We want to be subclassed
 
+  /// UnknownSize - This is a special value which can be used with the
+  /// size arguments in alias queries to indicate that the caller does not
+  /// know the sizes of the potential memory references.
+  static unsigned const UnknownSize = ~0u;
+
   /// getTargetData - Return a pointer to the current TargetData object, or
   /// null if no TargetData object is available.
   ///
@@ -96,7 +101,7 @@ public:
 
   /// alias - A convenience wrapper for the case where the sizes are unknown.
   AliasResult alias(const Value *V1, const Value *V2) {
-    return alias(V1, ~0u, V2, ~0u);
+    return alias(V1, UnknownSize, V2, UnknownSize);
   }
 
   /// isNoAlias - A trivial helper function to check to see if the specified
index b025ec623c3d5b93c80dbda29e5416d4cd55b215..229e9e509bc1570dad1ebd2a3c4a59d5265b0f34 100644 (file)
@@ -334,7 +334,7 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
       // is impossible to alias the pointer we're checking.  If not, we have to
       // assume that the call could touch the pointer, even though it doesn't
       // escape.
-      if (!isNoAlias(cast<Value>(CI), ~0U, P, ~0U)) {
+      if (!isNoAlias(cast<Value>(CI), UnknownSize, P, UnknownSize)) {
         PassedAsArg = true;
         break;
       }
@@ -353,7 +353,7 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
   default: break;
   case Intrinsic::memcpy:
   case Intrinsic::memmove: {
-    unsigned Len = ~0U;
+    unsigned Len = UnknownSize;
     if (ConstantInt *LenCI = dyn_cast<ConstantInt>(II->getArgOperand(2)))
       Len = LenCI->getZExtValue();
     Value *Dest = II->getArgOperand(0);
@@ -490,7 +490,8 @@ BasicAliasAnalysis::aliasGEP(const GEPOperator *GEP1, unsigned V1Size,
   // out if the indexes to the GEP tell us anything about the derived pointer.
   if (const GEPOperator *GEP2 = dyn_cast<GEPOperator>(V2)) {
     // Do the base pointers alias?
-    AliasResult BaseAlias = aliasCheck(UnderlyingV1, ~0U, UnderlyingV2, ~0U);
+    AliasResult BaseAlias = aliasCheck(UnderlyingV1, UnknownSize,
+                                       UnderlyingV2, UnknownSize);
     
     // If we get a No or May, then return it immediately, no amount of analysis
     // will improve this situation.
@@ -527,10 +528,10 @@ BasicAliasAnalysis::aliasGEP(const GEPOperator *GEP1, unsigned V1Size,
     // pointer, we know they cannot alias.
 
     // If both accesses are unknown size, we can't do anything useful here.
-    if (V1Size == ~0U && V2Size == ~0U)
+    if (V1Size == UnknownSize && V2Size == UnknownSize)
       return MayAlias;
 
-    AliasResult R = aliasCheck(UnderlyingV1, ~0U, V2, V2Size);
+    AliasResult R = aliasCheck(UnderlyingV1, UnknownSize, V2, V2Size);
     if (R != MustAlias)
       // If V2 may alias GEP base pointer, conservatively returns MayAlias.
       // If V2 is known not to alias GEP base pointer, then the two values
@@ -778,8 +779,8 @@ BasicAliasAnalysis::aliasCheck(const Value *V1, unsigned V1Size,
   // If the size of one access is larger than the entire object on the other
   // side, then we know such behavior is undefined and can assume no alias.
   if (TD)
-    if ((V1Size != ~0U && isObjectSmallerThan(O2, V1Size, *TD)) ||
-        (V2Size != ~0U && isObjectSmallerThan(O1, V2Size, *TD)))
+    if ((V1Size != UnknownSize && isObjectSmallerThan(O2, V1Size, *TD)) ||
+        (V2Size != UnknownSize && isObjectSmallerThan(O1, V2Size, *TD)))
       return NoAlias;
   
   // FIXME: This isn't aggressively handling alias(GEP, PHI) for example: if the
index b3d90cb5c12b0c17921a8ee4fa3f2d97a0b6eed1..91ae98919d40acdaa0b04a3bdd33a3c9d5333d9d 100644 (file)
@@ -155,8 +155,8 @@ ScalarEvolutionAliasAnalysis::alias(const Value *A, unsigned ASize,
   Value *AO = GetBaseValue(AS);
   Value *BO = GetBaseValue(BS);
   if ((AO && AO != A) || (BO && BO != B))
-    if (alias(AO ? AO : A, AO ? ~0u : ASize,
-              BO ? BO : B, BO ? ~0u : BSize) == NoAlias)
+    if (alias(AO ? AO : A, AO ? UnknownSize : ASize,
+              BO ? BO : B, BO ? UnknownSize : BSize) == NoAlias)
       return NoAlias;
 
   // Forward the query to the next analysis.