#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"
/// 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
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);
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
}
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
}
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)