Make AliasAnalysis and related classes use

getAnalysisIfAvailable<TargetData>().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77028 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2009-07-25 00:48:42 +00:00
parent d5b385c09f
commit fc2a3ed0c9
8 changed files with 54 additions and 47 deletions

View File

@@ -56,8 +56,7 @@ protected:
void InitializeAliasAnalysis(Pass *P);
/// getAnalysisUsage - All alias analysis implementations should invoke this
/// directly (using AliasAnalysis::getAnalysisUsage(AU)) to make sure that
/// TargetData is required by the pass.
/// directly (using AliasAnalysis::getAnalysisUsage(AU)).
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
public:
@@ -65,11 +64,15 @@ public:
AliasAnalysis() : TD(0), AA(0) {}
virtual ~AliasAnalysis(); // We want to be subclassed
/// getTargetData - Every alias analysis implementation depends on the size of
/// data items in the current Target. This provides a uniform way to handle
/// it.
/// getTargetData - Return a pointer to the current TargetData object, or
/// null if no TargetData object is available.
///
const TargetData &getTargetData() const { return *TD; }
const TargetData *getTargetData() const { return TD; }
/// getTypeStoreSize - Return the TargetData store size for the given type,
/// if known, or a conservative value otherwise.
///
unsigned getTypeStoreSize(const Type *Ty);
//===--------------------------------------------------------------------===//
/// Alias Queries...

View File

@@ -88,7 +88,7 @@ AliasAnalysis::getModRefInfo(CallSite CS1, CallSite CS2) {
AliasAnalysis::ModRefResult
AliasAnalysis::getModRefInfo(LoadInst *L, Value *P, unsigned Size) {
return alias(L->getOperand(0), TD->getTypeStoreSize(L->getType()),
return alias(L->getOperand(0), getTypeStoreSize(L->getType()),
P, Size) ? Ref : NoModRef;
}
@@ -97,7 +97,7 @@ AliasAnalysis::getModRefInfo(StoreInst *S, Value *P, unsigned Size) {
// If the stored address cannot alias the pointer in question, then the
// pointer cannot be modified by the store.
if (!alias(S->getOperand(1),
TD->getTypeStoreSize(S->getOperand(0)->getType()), P, Size))
getTypeStoreSize(S->getOperand(0)->getType()), P, Size))
return NoModRef;
// If the pointer is a pointer to constant memory, then it could not have been
@@ -177,18 +177,23 @@ AliasAnalysis::~AliasAnalysis() {}
/// AliasAnalysis interface before any other methods are called.
///
void AliasAnalysis::InitializeAliasAnalysis(Pass *P) {
TD = &P->getAnalysis<TargetData>();
TD = P->getAnalysisIfAvailable<TargetData>();
AA = &P->getAnalysis<AliasAnalysis>();
}
// getAnalysisUsage - All alias analysis implementations should invoke this
// directly (using AliasAnalysis::getAnalysisUsage(AU)) to make sure that
// TargetData is required by the pass.
// directly (using AliasAnalysis::getAnalysisUsage(AU)).
void AliasAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<TargetData>(); // All AA's need TargetData.
AU.addRequired<AliasAnalysis>(); // All AA's chain
}
/// getTypeStoreSize - Return the TargetData store size for the given type,
/// if known, or a conservative value otherwise.
///
unsigned AliasAnalysis::getTypeStoreSize(const Type *Ty) {
return TD ? TD->getTypeStoreSize(Ty) : ~0u;
}
/// canBasicBlockModify - Return true if it is possible for execution of the
/// specified basic block to modify the value pointed to by Ptr.
///

View File

@@ -109,8 +109,6 @@ PrintModRefResults(const char *Msg, bool P, Instruction *I, Value *Ptr,
bool AAEval::runOnFunction(Function &F) {
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
const TargetData &TD = AA.getTargetData();
std::set<Value *> Pointers;
std::set<CallSite> CallSites;
@@ -142,14 +140,14 @@ bool AAEval::runOnFunction(Function &F) {
// iterate over the worklist, and run the full (n^2)/2 disambiguations
for (std::set<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end();
I1 != E; ++I1) {
unsigned I1Size = 0;
unsigned I1Size = ~0u;
const Type *I1ElTy = cast<PointerType>((*I1)->getType())->getElementType();
if (I1ElTy->isSized()) I1Size = TD.getTypeStoreSize(I1ElTy);
if (I1ElTy->isSized()) I1Size = AA.getTypeStoreSize(I1ElTy);
for (std::set<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2) {
unsigned I2Size = 0;
unsigned I2Size = ~0u;
const Type *I2ElTy =cast<PointerType>((*I2)->getType())->getElementType();
if (I2ElTy->isSized()) I2Size = TD.getTypeStoreSize(I2ElTy);
if (I2ElTy->isSized()) I2Size = AA.getTypeStoreSize(I2ElTy);
switch (AA.alias(*I1, I1Size, *I2, I2Size)) {
case AliasAnalysis::NoAlias:
@@ -174,9 +172,9 @@ bool AAEval::runOnFunction(Function &F) {
for (std::set<Value *>::iterator V = Pointers.begin(), Ve = Pointers.end();
V != Ve; ++V) {
unsigned Size = 0;
unsigned Size = ~0u;
const Type *ElTy = cast<PointerType>((*V)->getType())->getElementType();
if (ElTy->isSized()) Size = TD.getTypeStoreSize(ElTy);
if (ElTy->isSized()) Size = AA.getTypeStoreSize(ElTy);
switch (AA.getModRefInfo(*C, *V, Size)) {
case AliasAnalysis::NoModRef:

View File

@@ -280,7 +280,7 @@ bool AliasSetTracker::add(Value *Ptr, unsigned Size) {
bool AliasSetTracker::add(LoadInst *LI) {
bool NewPtr;
AliasSet &AS = addPointer(LI->getOperand(0),
AA.getTargetData().getTypeStoreSize(LI->getType()),
AA.getTypeStoreSize(LI->getType()),
AliasSet::Refs, NewPtr);
if (LI->isVolatile()) AS.setVolatile();
return NewPtr;
@@ -290,7 +290,7 @@ bool AliasSetTracker::add(StoreInst *SI) {
bool NewPtr;
Value *Val = SI->getOperand(0);
AliasSet &AS = addPointer(SI->getOperand(1),
AA.getTargetData().getTypeStoreSize(Val->getType()),
AA.getTypeStoreSize(Val->getType()),
AliasSet::Mods, NewPtr);
if (SI->isVolatile()) AS.setVolatile();
return NewPtr;
@@ -412,7 +412,7 @@ bool AliasSetTracker::remove(Value *Ptr, unsigned Size) {
}
bool AliasSetTracker::remove(LoadInst *LI) {
unsigned Size = AA.getTargetData().getTypeStoreSize(LI->getType());
unsigned Size = AA.getTypeStoreSize(LI->getType());
AliasSet *AS = findAliasSetForPointer(LI->getOperand(0), Size);
if (!AS) return false;
remove(*AS);
@@ -420,8 +420,7 @@ bool AliasSetTracker::remove(LoadInst *LI) {
}
bool AliasSetTracker::remove(StoreInst *SI) {
unsigned Size =
AA.getTargetData().getTypeStoreSize(SI->getOperand(0)->getType());
unsigned Size = AA.getTypeStoreSize(SI->getOperand(0)->getType());
AliasSet *AS = findAliasSetForPointer(SI->getOperand(1), Size);
if (!AS) return false;
remove(*AS);

View File

@@ -141,11 +141,10 @@ namespace {
explicit NoAA(void *PID) : ImmutablePass(PID) { }
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<TargetData>();
}
virtual void initializePass() {
TD = &getAnalysis<TargetData>();
TD = getAnalysisIfAvailable<TargetData>();
}
virtual AliasResult alias(const Value *V1, unsigned V1Size,
@@ -354,10 +353,10 @@ BasicAliasAnalysis::alias(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.
const TargetData &TD = getTargetData();
if ((V1Size != ~0U && isObjectSmallerThan(O2, V1Size, TD)) ||
(V2Size != ~0U && isObjectSmallerThan(O1, V2Size, TD)))
return NoAlias;
if (TD)
if ((V1Size != ~0U && isObjectSmallerThan(O2, V1Size, *TD)) ||
(V2Size != ~0U && isObjectSmallerThan(O1, V2Size, *TD)))
return NoAlias;
// If one pointer is the result of a call/invoke and the other is a
// non-escaping local object, then we know the object couldn't escape to a
@@ -476,16 +475,16 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
// the size of the argument... build an index vector that is equal to
// the arguments provided, except substitute 0's for any variable
// indexes we find...
if (cast<PointerType>(
if (TD && cast<PointerType>(
BasePtr->getType())->getElementType()->isSized()) {
for (unsigned i = 0; i != GEPOperands.size(); ++i)
if (!isa<ConstantInt>(GEPOperands[i]))
GEPOperands[i] =
Context.getNullValue(GEPOperands[i]->getType());
int64_t Offset =
getTargetData().getIndexedOffset(BasePtr->getType(),
&GEPOperands[0],
GEPOperands.size());
TD->getIndexedOffset(BasePtr->getType(),
&GEPOperands[0],
GEPOperands.size());
if (Offset >= (int64_t)V2Size || Offset <= -(int64_t)V1Size)
return NoAlias;
@@ -677,6 +676,10 @@ BasicAliasAnalysis::CheckGEPInstructions(
// However, one GEP may have more operands than the other. If this is the
// case, there may still be hope. Check this now.
if (FirstConstantOper == MinOperands) {
// Without TargetData, we won't know what the offsets are.
if (!TD)
return MayAlias;
// Make GEP1Ops be the longer one if there is a longer one.
if (NumGEP1Ops < NumGEP2Ops) {
std::swap(GEP1Ops, GEP2Ops);
@@ -696,13 +699,12 @@ BasicAliasAnalysis::CheckGEPInstructions(
GEP1Ops[i] = Context.getNullValue(GEP1Ops[i]->getType());
// Okay, now get the offset. This is the relative offset for the full
// instruction.
const TargetData &TD = getTargetData();
int64_t Offset1 = TD.getIndexedOffset(GEPPointerTy, GEP1Ops,
NumGEP1Ops);
int64_t Offset1 = TD->getIndexedOffset(GEPPointerTy, GEP1Ops,
NumGEP1Ops);
// Now check without any constants at the end.
int64_t Offset2 = TD.getIndexedOffset(GEPPointerTy, GEP1Ops,
MinOperands);
int64_t Offset2 = TD->getIndexedOffset(GEPPointerTy, GEP1Ops,
MinOperands);
// Make sure we compare the absolute difference.
if (Offset1 > Offset2)
@@ -818,11 +820,11 @@ BasicAliasAnalysis::CheckGEPInstructions(
}
}
if (GEPPointerTy->getElementType()->isSized()) {
if (TD && GEPPointerTy->getElementType()->isSized()) {
int64_t Offset1 =
getTargetData().getIndexedOffset(GEPPointerTy, GEP1Ops, NumGEP1Ops);
TD->getIndexedOffset(GEPPointerTy, GEP1Ops, NumGEP1Ops);
int64_t Offset2 =
getTargetData().getIndexedOffset(GEPPointerTy, GEP2Ops, NumGEP2Ops);
TD->getIndexedOffset(GEPPointerTy, GEP2Ops, NumGEP2Ops);
assert(Offset1 != Offset2 &&
"There is at least one different constant here!");

View File

@@ -119,8 +119,8 @@ void LoopDependenceAnalysis::analysePair(DependencePair *P) const {
const Value *aobj = aptr->getUnderlyingObject();
const Value *bobj = bptr->getUnderlyingObject();
AliasAnalysis::AliasResult alias = AA->alias(
aobj, AA->getTargetData().getTypeStoreSize(aobj->getType()),
bobj, AA->getTargetData().getTypeStoreSize(bobj->getType()));
aobj, AA->getTypeStoreSize(aobj->getType()),
bobj, AA->getTypeStoreSize(bobj->getType()));
// We can not analyse objects if we do not know about their aliasing.
if (alias == AliasAnalysis::MayAlias) {

View File

@@ -390,7 +390,7 @@ bool LICM::canSinkOrHoistInst(Instruction &I) {
// Don't hoist loads which have may-aliased stores in loop.
unsigned Size = 0;
if (LI->getType()->isSized())
Size = AA->getTargetData().getTypeStoreSize(LI->getType());
Size = AA->getTypeStoreSize(LI->getType());
return !pointerInvalidatedByLoop(LI->getOperand(0), Size);
} else if (CallInst *CI = dyn_cast<CallInst>(&I)) {
// Handle obvious cases efficiently.

View File

@@ -540,7 +540,7 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB,
unsigned AccessSize = 0;
if (AA) {
const Type *AccessTy = cast<PointerType>(Ptr->getType())->getElementType();
AccessSize = AA->getTargetData().getTypeStoreSize(AccessTy);
AccessSize = AA->getTypeStoreSize(AccessTy);
}
while (ScanFrom != ScanBB->begin()) {