Modified Deserializer::ReadCStr to allow C-strings to be read into a
[oota-llvm.git] / lib / Analysis / BasicAliasAnalysis.cpp
index 5ec9afaec98797d47b4d09a27b2073cdb3598b9a..7ce9d1651f73c25a422f8ec31e8e7cb5792428e4 100644 (file)
@@ -25,8 +25,6 @@
 #include "llvm/Pass.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
@@ -116,9 +114,6 @@ namespace {
     /// global) or not.
     bool pointsToConstantMemory(const Value *P);
 
-    virtual ModRefBehavior getModRefBehavior(Function *F, CallSite CS,
-                                          std::vector<PointerAccessInfo> *Info);
-
   private:
     // CheckGEPInstructions - Check two GEP instructions with known
     // must-aliasing base pointers.  This checks to see if the index expressions
@@ -396,17 +391,19 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
   if (isGEP(V1) && isGEP(V2)) {
     // Drill down into the first non-gep value, to test for must-aliasing of
     // the base pointers.
-    const Value *BasePtr1 = V1, *BasePtr2 = V2;
-    do {
-      BasePtr1 = cast<User>(BasePtr1)->getOperand(0);
-    } while (isGEP(BasePtr1) &&
-             cast<User>(BasePtr1)->getOperand(1) ==
-       Constant::getNullValue(cast<User>(BasePtr1)->getOperand(1)->getType()));
-    do {
-      BasePtr2 = cast<User>(BasePtr2)->getOperand(0);
-    } while (isGEP(BasePtr2) &&
-             cast<User>(BasePtr2)->getOperand(1) ==
-       Constant::getNullValue(cast<User>(BasePtr2)->getOperand(1)->getType()));
+    const User *G = cast<User>(V1);
+    while (isGEP(G->getOperand(0)) &&
+           G->getOperand(1) ==
+           Constant::getNullValue(G->getOperand(1)->getType()))
+      G = cast<User>(G->getOperand(0));
+    const Value *BasePtr1 = G->getOperand(0);
+
+    G = cast<User>(V2);
+    while (isGEP(G->getOperand(0)) &&
+           G->getOperand(1) ==
+           Constant::getNullValue(G->getOperand(1)->getType()))
+      G = cast<User>(G->getOperand(0));
+    const Value *BasePtr2 = G->getOperand(0);
 
     // Do the base pointers alias?
     AliasResult BaseAlias = alias(BasePtr1, ~0U, BasePtr2, ~0U);
@@ -735,8 +732,8 @@ BasicAliasAnalysis::CheckGEPInstructions(
           if (const ArrayType *AT = dyn_cast<ArrayType>(BasePtr1Ty)) {
             if (Op1C->getZExtValue() >= AT->getNumElements())
               return MayAlias;  // Be conservative with out-of-range accesses
-          } else if (const VectorType *PT = dyn_cast<VectorType>(BasePtr1Ty)) {
-            if (Op1C->getZExtValue() >= PT->getNumElements())
+          } else if (const VectorType *VT = dyn_cast<VectorType>(BasePtr1Ty)) {
+            if (Op1C->getZExtValue() >= VT->getNumElements())
               return MayAlias;  // Be conservative with out-of-range accesses
           }
           
@@ -761,10 +758,10 @@ BasicAliasAnalysis::CheckGEPInstructions(
       if (Op2) {
         if (const ConstantInt *Op2C = dyn_cast<ConstantInt>(Op2)) {
           // If this is an array index, make sure the array element is in range.
-          if (const ArrayType *AT = dyn_cast<ArrayType>(BasePtr1Ty)) {
+          if (const ArrayType *AT = dyn_cast<ArrayType>(BasePtr2Ty)) {
             if (Op2C->getZExtValue() >= AT->getNumElements())
               return MayAlias;  // Be conservative with out-of-range accesses
-          } else if (const VectorType *VT = dyn_cast<VectorType>(BasePtr1Ty)) {
+          } else if (const VectorType *VT = dyn_cast<VectorType>(BasePtr2Ty)) {
             if (Op2C->getZExtValue() >= VT->getNumElements())
               return MayAlias;  // Be conservative with out-of-range accesses
           }
@@ -810,37 +807,5 @@ BasicAliasAnalysis::CheckGEPInstructions(
   return MayAlias;
 }
 
-static ManagedStatic<BitVector> NoMemoryIntrinsics;
-static ManagedStatic<BitVector> OnlyReadsMemoryIntrinsics;
-
-AliasAnalysis::ModRefBehavior
-BasicAliasAnalysis::getModRefBehavior(Function *F, CallSite CS,
-                                      std::vector<PointerAccessInfo> *Info) {
-  if (!F->isDeclaration()) return UnknownModRefBehavior;
-
-  static bool Initialized = false;
-  if (!Initialized) {
-    NoMemoryIntrinsics->resize(Intrinsic::num_intrinsics);
-    OnlyReadsMemoryIntrinsics->resize(Intrinsic::num_intrinsics);
-#define GET_MODREF_BEHAVIOR
-#include "llvm/Intrinsics.gen"
-#undef GET_MODREF_BEHAVIOR
-    
-    Initialized = true;
-  }
-
-  // If this is an intrinsic, we can use lookup tables
-  if (unsigned id = F->getIntrinsicID()) {
-    if (NoMemoryIntrinsics->test(id))
-      return DoesNotAccessMemory;
-    if (OnlyReadsMemoryIntrinsics->test(id))
-      return OnlyReadsMemory;
-
-    return UnknownModRefBehavior;
-  }
-
-  return UnknownModRefBehavior;
-}
-
 // Make sure that anything that uses AliasAnalysis pulls in this file...
 DEFINING_FILE_FOR(BasicAliasAnalysis)