Give RWMutex the SmartRWMutex treatment too.
[oota-llvm.git] / lib / Analysis / BasicAliasAnalysis.cpp
index 1b26dc421ce3786e6deada1ac47ef49525b8bb75..d0620456399b3a4159f83346b4f3d42f8c98461b 100644 (file)
@@ -123,7 +123,7 @@ static bool isObjectSmallerThan(const Value *V, unsigned Size,
   }
   
   if (AccessTy->isSized())
-    return TD.getTypePaddedSize(AccessTy) < Size;
+    return TD.getTypeAllocSize(AccessTy) < Size;
   return false;
 }
 
@@ -201,13 +201,7 @@ namespace {
 
     ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size);
     ModRefResult getModRefInfo(CallSite CS1, CallSite CS2);
-    
-    virtual ModRefBehavior getModRefBehavior(CallSite CS,
-                                     std::vector<PointerAccessInfo> *Info = 0);
 
-    virtual ModRefBehavior getModRefBehavior(Function *F,
-                                     std::vector<PointerAccessInfo> *Info = 0);
-    
     /// hasNoModRefInfoForCalls - We can provide mod/ref information against
     /// non-escaping allocations.
     virtual bool hasNoModRefInfoForCalls() const { return false; }
@@ -251,51 +245,6 @@ bool BasicAliasAnalysis::pointsToConstantMemory(const Value *P) {
 }
 
 
-static bool isAtomicRMW(Function* F) {
-  if (!F) return false;
-  if (F->isIntrinsic()) {
-    switch (F->getIntrinsicID()) {
-      case Intrinsic::atomic_cmp_swap:
-      case Intrinsic::atomic_load_add:
-      case Intrinsic::atomic_load_and:
-      case Intrinsic::atomic_load_max:
-      case Intrinsic::atomic_load_min:
-      case Intrinsic::atomic_load_nand:
-      case Intrinsic::atomic_load_or:
-      case Intrinsic::atomic_load_sub:
-      case Intrinsic::atomic_load_umax:
-      case Intrinsic::atomic_load_umin:
-      case Intrinsic::atomic_load_xor:
-      case Intrinsic::atomic_swap:
-        return true;
-      default:
-        return false;
-    }
-  }
-  
-  return false;
-}
-
-AliasAnalysis::ModRefBehavior
-BasicAliasAnalysis::getModRefBehavior(CallSite CS,
-                                 std::vector<PointerAccessInfo> *Info) {
-  if (isAtomicRMW(CS.getCalledFunction()))
-    // CAS and related intrinsics only access their arguments.
-    return AliasAnalysis::AccessesArguments;
-  
-  return AliasAnalysis::getModRefBehavior(CS, Info);
-}
-
-AliasAnalysis::ModRefBehavior
-BasicAliasAnalysis::getModRefBehavior(Function *F,
-                                 std::vector<PointerAccessInfo> *Info) {
-  if (isAtomicRMW(F))
-    // CAS and related intrinsics only access their arguments.
-    return AliasAnalysis::AccessesArguments;
-
-  return AliasAnalysis::getModRefBehavior(F, Info);
-}
-
 // getModRefInfo - Check to see if the specified callsite can clobber the
 // specified memory object.  Since we only look at local properties of this
 // function, we really can't say much about this query.  We do, however, use
@@ -319,7 +268,7 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
     // If the pointer is to a locally allocated object that does not escape,
     // then the call can not mod/ref the pointer unless the call takes the
     // argument without capturing it.
-    if (isNonEscapingLocalObject(Object)) {
+    if (isNonEscapingLocalObject(Object) && CS.getInstruction() != Object) {
       bool passedAsArg = false;
       // TODO: Eventually only check 'nocapture' arguments.
       for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
@@ -414,10 +363,10 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
   // non-escaping local object, then we know the object couldn't escape to a
   // point where the call could return it.
   if ((isa<CallInst>(O1) || isa<InvokeInst>(O1)) &&
-      isNonEscapingLocalObject(O2))
+      isNonEscapingLocalObject(O2) && O1 != O2)
     return NoAlias;
   if ((isa<CallInst>(O2) || isa<InvokeInst>(O2)) &&
-      isNonEscapingLocalObject(O1))
+      isNonEscapingLocalObject(O1) && O1 != O2)
     return NoAlias;
   
   // If we have two gep instructions with must-alias'ing base pointers, figure
@@ -662,18 +611,39 @@ BasicAliasAnalysis::CheckGEPInstructions(
           if (G1OC != G2OC) {
             // Handle the "be careful" case above: if this is an array/vector
             // subscript, scan for a subsequent variable array index.
-            if (isa<SequentialType>(BasePtr1Ty))  {
-              const Type *NextTy =
-                cast<SequentialType>(BasePtr1Ty)->getElementType();
+            if (const SequentialType *STy =
+                  dyn_cast<SequentialType>(BasePtr1Ty)) {
+              const Type *NextTy = STy;
               bool isBadCase = false;
               
-              for (unsigned Idx = FirstConstantOper+1;
+              for (unsigned Idx = FirstConstantOper;
                    Idx != MinOperands && isa<SequentialType>(NextTy); ++Idx) {
                 const Value *V1 = GEP1Ops[Idx], *V2 = GEP2Ops[Idx];
                 if (!isa<Constant>(V1) || !isa<Constant>(V2)) {
                   isBadCase = true;
                   break;
                 }
+                // If the array is indexed beyond the bounds of the static type
+                // at this level, it will also fall into the "be careful" case.
+                // It would theoretically be possible to analyze these cases,
+                // but for now just be conservatively correct.
+                if (const ArrayType *ATy = dyn_cast<ArrayType>(STy))
+                  if (cast<ConstantInt>(G1OC)->getZExtValue() >=
+                        ATy->getNumElements() ||
+                      cast<ConstantInt>(G2OC)->getZExtValue() >=
+                        ATy->getNumElements()) {
+                    isBadCase = true;
+                    break;
+                  }
+                if (const VectorType *VTy = dyn_cast<VectorType>(STy))
+                  if (cast<ConstantInt>(G1OC)->getZExtValue() >=
+                        VTy->getNumElements() ||
+                      cast<ConstantInt>(G2OC)->getZExtValue() >=
+                        VTy->getNumElements()) {
+                    isBadCase = true;
+                    break;
+                  }
+                STy = cast<SequentialType>(NextTy);
                 NextTy = cast<SequentialType>(NextTy)->getElementType();
               }