2002-08-22 18:25:32 +00:00
|
|
|
//===- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation -==//
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-08-22 18:25:32 +00:00
|
|
|
//
|
|
|
|
// This file implements the generic AliasAnalysis interface which is used as the
|
|
|
|
// common interface used by all clients and implementations of alias analysis.
|
|
|
|
//
|
|
|
|
// This file also implements the default version of the AliasAnalysis interface
|
|
|
|
// that is to be used when no other implementation is specified. This does some
|
|
|
|
// simple tests that detect obvious cases: two different global pointers cannot
|
|
|
|
// alias, a global cannot alias a malloc, two different mallocs cannot alias,
|
|
|
|
// etc.
|
|
|
|
//
|
|
|
|
// This alias analysis implementation really isn't very good for anything, but
|
|
|
|
// it is very fast, and makes a nice clean default implementation. Because it
|
|
|
|
// handles lots of little corner cases, other, more complex, alias analysis
|
|
|
|
// implementations may choose to rely on this pass to resolve these simple and
|
|
|
|
// easy cases.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-02-26 19:41:54 +00:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2006-06-07 20:00:19 +00:00
|
|
|
#include "llvm/Pass.h"
|
2002-08-22 18:25:32 +00:00
|
|
|
#include "llvm/BasicBlock.h"
|
2007-12-01 07:51:45 +00:00
|
|
|
#include "llvm/Function.h"
|
2009-02-03 06:27:22 +00:00
|
|
|
#include "llvm/IntrinsicInst.h"
|
2004-07-29 17:30:56 +00:00
|
|
|
#include "llvm/Instructions.h"
|
2010-09-14 21:25:10 +00:00
|
|
|
#include "llvm/LLVMContext.h"
|
2005-03-17 15:38:16 +00:00
|
|
|
#include "llvm/Type.h"
|
2003-02-26 19:26:51 +00:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2004-03-15 04:07:29 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2002-08-22 18:25:32 +00:00
|
|
|
// Register the AliasAnalysis interface, providing a nice name to refer to.
|
2010-10-19 17:21:58 +00:00
|
|
|
INITIALIZE_ANALYSIS_GROUP(AliasAnalysis, "Alias Analysis", NoAA)
|
2007-05-03 01:11:54 +00:00
|
|
|
char AliasAnalysis::ID = 0;
|
2002-08-22 18:25:32 +00:00
|
|
|
|
2004-05-23 21:15:48 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Default chaining methods
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
AliasAnalysis::AliasResult
|
2010-09-14 21:25:10 +00:00
|
|
|
AliasAnalysis::alias(const Location &LocA, const Location &LocB) {
|
2004-05-23 21:15:48 +00:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-09-14 21:25:10 +00:00
|
|
|
return AA->alias(LocA, LocB);
|
2004-05-23 21:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-08 16:45:26 +00:00
|
|
|
bool AliasAnalysis::pointsToConstantMemory(const Location &Loc,
|
|
|
|
bool OrLocal) {
|
2004-05-23 21:15:48 +00:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-11-08 16:45:26 +00:00
|
|
|
return AA->pointsToConstantMemory(Loc, OrLocal);
|
2004-05-23 21:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AliasAnalysis::deleteValue(Value *V) {
|
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
|
|
|
AA->deleteValue(V);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AliasAnalysis::copyValue(Value *From, Value *To) {
|
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
|
|
|
AA->copyValue(From, To);
|
|
|
|
}
|
|
|
|
|
2011-01-03 21:38:41 +00:00
|
|
|
void AliasAnalysis::addEscapingUse(Use &U) {
|
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
|
|
|
AA->addEscapingUse(U);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-06 01:25:49 +00:00
|
|
|
AliasAnalysis::ModRefResult
|
|
|
|
AliasAnalysis::getModRefInfo(ImmutableCallSite CS,
|
2010-09-14 21:25:10 +00:00
|
|
|
const Location &Loc) {
|
2010-10-25 16:28:57 +00:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-08-06 01:25:49 +00:00
|
|
|
|
|
|
|
ModRefBehavior MRB = getModRefBehavior(CS);
|
|
|
|
if (MRB == DoesNotAccessMemory)
|
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
ModRefResult Mask = ModRef;
|
2010-11-09 20:06:55 +00:00
|
|
|
if (onlyReadsMemory(MRB))
|
2010-08-06 01:25:49 +00:00
|
|
|
Mask = Ref;
|
2010-11-09 20:06:55 +00:00
|
|
|
|
2010-11-10 18:17:28 +00:00
|
|
|
if (onlyAccessesArgPointees(MRB)) {
|
2010-08-06 01:25:49 +00:00
|
|
|
bool doesAlias = false;
|
2011-04-27 18:39:03 +00:00
|
|
|
if (doesAccessArgPointees(MRB)) {
|
|
|
|
MDNode *CSTag = CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa);
|
2010-11-10 18:17:28 +00:00
|
|
|
for (ImmutableCallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end();
|
2011-04-27 18:39:03 +00:00
|
|
|
AI != AE; ++AI) {
|
|
|
|
const Value *Arg = *AI;
|
|
|
|
if (!Arg->getType()->isPointerTy())
|
|
|
|
continue;
|
|
|
|
Location CSLoc(Arg, UnknownSize, CSTag);
|
|
|
|
if (!isNoAlias(CSLoc, Loc)) {
|
2010-11-10 18:17:28 +00:00
|
|
|
doesAlias = true;
|
|
|
|
break;
|
|
|
|
}
|
2011-04-27 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-06 01:25:49 +00:00
|
|
|
if (!doesAlias)
|
|
|
|
return NoModRef;
|
|
|
|
}
|
|
|
|
|
2010-09-14 21:25:10 +00:00
|
|
|
// If Loc is a constant memory location, the call definitely could not
|
2010-08-06 01:25:49 +00:00
|
|
|
// modify the memory location.
|
2010-09-14 21:25:10 +00:00
|
|
|
if ((Mask & Mod) && pointsToConstantMemory(Loc))
|
2010-08-06 01:25:49 +00:00
|
|
|
Mask = ModRefResult(Mask & ~Mod);
|
|
|
|
|
2010-10-25 16:29:52 +00:00
|
|
|
// If this is the end of the chain, don't forward.
|
2010-08-06 01:25:49 +00:00
|
|
|
if (!AA) return Mask;
|
|
|
|
|
|
|
|
// Otherwise, fall back to the next AA in the chain. But we can merge
|
|
|
|
// in any mask we've managed to compute.
|
2010-09-14 21:25:10 +00:00
|
|
|
return ModRefResult(AA->getModRefInfo(CS, Loc) & Mask);
|
2010-08-06 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-23 21:15:48 +00:00
|
|
|
AliasAnalysis::ModRefResult
|
2010-08-03 21:48:53 +00:00
|
|
|
AliasAnalysis::getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2) {
|
2010-10-25 16:28:57 +00:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-08-06 01:25:49 +00:00
|
|
|
|
|
|
|
// If CS1 or CS2 are readnone, they don't interact.
|
|
|
|
ModRefBehavior CS1B = getModRefBehavior(CS1);
|
|
|
|
if (CS1B == DoesNotAccessMemory) return NoModRef;
|
|
|
|
|
|
|
|
ModRefBehavior CS2B = getModRefBehavior(CS2);
|
|
|
|
if (CS2B == DoesNotAccessMemory) return NoModRef;
|
|
|
|
|
|
|
|
// If they both only read from memory, there is no dependence.
|
2010-11-09 20:06:55 +00:00
|
|
|
if (onlyReadsMemory(CS1B) && onlyReadsMemory(CS2B))
|
2010-08-06 01:25:49 +00:00
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
AliasAnalysis::ModRefResult Mask = ModRef;
|
|
|
|
|
|
|
|
// If CS1 only reads memory, the only dependence on CS2 can be
|
|
|
|
// from CS1 reading memory written by CS2.
|
2010-11-09 20:06:55 +00:00
|
|
|
if (onlyReadsMemory(CS1B))
|
2010-08-06 01:25:49 +00:00
|
|
|
Mask = ModRefResult(Mask & Ref);
|
|
|
|
|
|
|
|
// If CS2 only access memory through arguments, accumulate the mod/ref
|
|
|
|
// information from CS1's references to the memory referenced by
|
|
|
|
// CS2's arguments.
|
2010-11-10 18:17:28 +00:00
|
|
|
if (onlyAccessesArgPointees(CS2B)) {
|
2010-08-06 01:25:49 +00:00
|
|
|
AliasAnalysis::ModRefResult R = NoModRef;
|
2011-04-27 18:39:03 +00:00
|
|
|
if (doesAccessArgPointees(CS2B)) {
|
|
|
|
MDNode *CS2Tag = CS2.getInstruction()->getMetadata(LLVMContext::MD_tbaa);
|
2010-11-10 18:17:28 +00:00
|
|
|
for (ImmutableCallSite::arg_iterator
|
|
|
|
I = CS2.arg_begin(), E = CS2.arg_end(); I != E; ++I) {
|
2011-04-27 18:39:03 +00:00
|
|
|
const Value *Arg = *I;
|
|
|
|
if (!Arg->getType()->isPointerTy())
|
|
|
|
continue;
|
|
|
|
Location CS2Loc(Arg, UnknownSize, CS2Tag);
|
|
|
|
R = ModRefResult((R | getModRefInfo(CS1, CS2Loc)) & Mask);
|
2010-11-10 18:17:28 +00:00
|
|
|
if (R == Mask)
|
|
|
|
break;
|
|
|
|
}
|
2011-04-27 18:39:03 +00:00
|
|
|
}
|
2010-08-06 01:25:49 +00:00
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If CS1 only accesses memory through arguments, check if CS2 references
|
|
|
|
// any of the memory referenced by CS1's arguments. If not, return NoModRef.
|
2010-11-10 18:17:28 +00:00
|
|
|
if (onlyAccessesArgPointees(CS1B)) {
|
2010-08-06 01:25:49 +00:00
|
|
|
AliasAnalysis::ModRefResult R = NoModRef;
|
2011-04-27 18:39:03 +00:00
|
|
|
if (doesAccessArgPointees(CS1B)) {
|
|
|
|
MDNode *CS1Tag = CS1.getInstruction()->getMetadata(LLVMContext::MD_tbaa);
|
2010-11-10 18:17:28 +00:00
|
|
|
for (ImmutableCallSite::arg_iterator
|
2011-04-27 18:39:03 +00:00
|
|
|
I = CS1.arg_begin(), E = CS1.arg_end(); I != E; ++I) {
|
|
|
|
const Value *Arg = *I;
|
|
|
|
if (!Arg->getType()->isPointerTy())
|
|
|
|
continue;
|
|
|
|
Location CS1Loc(Arg, UnknownSize, CS1Tag);
|
|
|
|
if (getModRefInfo(CS2, CS1Loc) != NoModRef) {
|
2010-11-10 18:17:28 +00:00
|
|
|
R = Mask;
|
|
|
|
break;
|
|
|
|
}
|
2011-04-27 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-06 01:25:49 +00:00
|
|
|
if (R == NoModRef)
|
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
2010-10-25 16:29:52 +00:00
|
|
|
// If this is the end of the chain, don't forward.
|
2010-08-06 01:25:49 +00:00
|
|
|
if (!AA) return Mask;
|
|
|
|
|
|
|
|
// Otherwise, fall back to the next AA in the chain. But we can merge
|
|
|
|
// in any mask we've managed to compute.
|
|
|
|
return ModRefResult(AA->getModRefInfo(CS1, CS2) & Mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::ModRefBehavior
|
|
|
|
AliasAnalysis::getModRefBehavior(ImmutableCallSite CS) {
|
2010-10-25 16:28:57 +00:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-08-06 01:25:49 +00:00
|
|
|
|
|
|
|
ModRefBehavior Min = UnknownModRefBehavior;
|
|
|
|
|
|
|
|
// Call back into the alias analysis with the other form of getModRefBehavior
|
|
|
|
// to see if it can give a better response.
|
|
|
|
if (const Function *F = CS.getCalledFunction())
|
|
|
|
Min = getModRefBehavior(F);
|
|
|
|
|
2010-10-25 16:29:52 +00:00
|
|
|
// If this is the end of the chain, don't forward.
|
2010-08-06 01:25:49 +00:00
|
|
|
if (!AA) return Min;
|
|
|
|
|
|
|
|
// Otherwise, fall back to the next AA in the chain. But we can merge
|
|
|
|
// in any result we've managed to compute.
|
2010-11-10 01:02:18 +00:00
|
|
|
return ModRefBehavior(AA->getModRefBehavior(CS) & Min);
|
2010-08-06 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::ModRefBehavior
|
|
|
|
AliasAnalysis::getModRefBehavior(const Function *F) {
|
2004-05-23 21:15:48 +00:00
|
|
|
assert(AA && "AA didn't call InitializeAliasAnalysis in its run method!");
|
2010-08-06 01:25:49 +00:00
|
|
|
return AA->getModRefBehavior(F);
|
2004-05-23 21:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AliasAnalysis non-virtual helper method implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-11-11 21:50:19 +00:00
|
|
|
AliasAnalysis::Location AliasAnalysis::getLocation(const LoadInst *LI) {
|
|
|
|
return Location(LI->getPointerOperand(),
|
|
|
|
getTypeStoreSize(LI->getType()),
|
|
|
|
LI->getMetadata(LLVMContext::MD_tbaa));
|
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::Location AliasAnalysis::getLocation(const StoreInst *SI) {
|
|
|
|
return Location(SI->getPointerOperand(),
|
|
|
|
getTypeStoreSize(SI->getValueOperand()->getType()),
|
|
|
|
SI->getMetadata(LLVMContext::MD_tbaa));
|
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::Location AliasAnalysis::getLocation(const VAArgInst *VI) {
|
|
|
|
return Location(VI->getPointerOperand(),
|
|
|
|
UnknownSize,
|
|
|
|
VI->getMetadata(LLVMContext::MD_tbaa));
|
|
|
|
}
|
|
|
|
|
2011-09-26 20:15:28 +00:00
|
|
|
AliasAnalysis::Location
|
|
|
|
AliasAnalysis::getLocation(const AtomicCmpXchgInst *CXI) {
|
|
|
|
return Location(CXI->getPointerOperand(),
|
|
|
|
getTypeStoreSize(CXI->getCompareOperand()->getType()),
|
|
|
|
CXI->getMetadata(LLVMContext::MD_tbaa));
|
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::Location
|
|
|
|
AliasAnalysis::getLocation(const AtomicRMWInst *RMWI) {
|
|
|
|
return Location(RMWI->getPointerOperand(),
|
|
|
|
getTypeStoreSize(RMWI->getValOperand()->getType()),
|
|
|
|
RMWI->getMetadata(LLVMContext::MD_tbaa));
|
|
|
|
}
|
2010-11-21 07:51:27 +00:00
|
|
|
|
|
|
|
AliasAnalysis::Location
|
|
|
|
AliasAnalysis::getLocationForSource(const MemTransferInst *MTI) {
|
|
|
|
uint64_t Size = UnknownSize;
|
|
|
|
if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
|
|
|
|
Size = C->getValue().getZExtValue();
|
|
|
|
|
2010-12-16 02:51:19 +00:00
|
|
|
// memcpy/memmove can have TBAA tags. For memcpy, they apply
|
|
|
|
// to both the source and the destination.
|
|
|
|
MDNode *TBAATag = MTI->getMetadata(LLVMContext::MD_tbaa);
|
|
|
|
|
|
|
|
return Location(MTI->getRawSource(), Size, TBAATag);
|
2010-11-21 07:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::Location
|
2010-11-30 01:48:20 +00:00
|
|
|
AliasAnalysis::getLocationForDest(const MemIntrinsic *MTI) {
|
2010-11-21 07:51:27 +00:00
|
|
|
uint64_t Size = UnknownSize;
|
|
|
|
if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
|
|
|
|
Size = C->getValue().getZExtValue();
|
2010-12-16 02:51:19 +00:00
|
|
|
|
|
|
|
// memcpy/memmove can have TBAA tags. For memcpy, they apply
|
|
|
|
// to both the source and the destination.
|
|
|
|
MDNode *TBAATag = MTI->getMetadata(LLVMContext::MD_tbaa);
|
2010-11-21 07:51:27 +00:00
|
|
|
|
2010-12-16 02:51:19 +00:00
|
|
|
return Location(MTI->getRawDest(), Size, TBAATag);
|
2010-11-21 07:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-02-26 19:26:51 +00:00
|
|
|
AliasAnalysis::ModRefResult
|
2010-09-14 21:25:10 +00:00
|
|
|
AliasAnalysis::getModRefInfo(const LoadInst *L, const Location &Loc) {
|
2011-08-15 20:54:19 +00:00
|
|
|
// Be conservative in the face of volatile/atomic.
|
|
|
|
if (!L->isUnordered())
|
2010-08-06 18:11:28 +00:00
|
|
|
return ModRef;
|
|
|
|
|
2010-08-03 17:27:43 +00:00
|
|
|
// If the load address doesn't alias the given address, it doesn't read
|
|
|
|
// or write the specified memory.
|
2010-11-11 21:50:19 +00:00
|
|
|
if (!alias(getLocation(L), Loc))
|
2010-08-03 17:27:43 +00:00
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
// Otherwise, a load just reads.
|
|
|
|
return Ref;
|
2003-02-26 19:26:51 +00:00
|
|
|
}
|
2002-08-22 18:25:32 +00:00
|
|
|
|
2003-02-26 19:26:51 +00:00
|
|
|
AliasAnalysis::ModRefResult
|
2010-09-14 21:25:10 +00:00
|
|
|
AliasAnalysis::getModRefInfo(const StoreInst *S, const Location &Loc) {
|
2011-08-15 20:54:19 +00:00
|
|
|
// Be conservative in the face of volatile/atomic.
|
|
|
|
if (!S->isUnordered())
|
2010-08-06 18:11:28 +00:00
|
|
|
return ModRef;
|
|
|
|
|
2010-08-06 18:10:45 +00:00
|
|
|
// If the store address cannot alias the pointer in question, then the
|
|
|
|
// specified memory cannot be modified by the store.
|
2010-11-11 21:50:19 +00:00
|
|
|
if (!alias(getLocation(S), Loc))
|
2004-01-30 22:16:42 +00:00
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
// If the pointer is a pointer to constant memory, then it could not have been
|
|
|
|
// modified by this store.
|
2010-09-14 21:25:10 +00:00
|
|
|
if (pointsToConstantMemory(Loc))
|
2010-08-03 17:27:43 +00:00
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
// Otherwise, a store just writes.
|
|
|
|
return Mod;
|
2002-08-22 18:25:32 +00:00
|
|
|
}
|
|
|
|
|
2010-08-06 18:24:38 +00:00
|
|
|
AliasAnalysis::ModRefResult
|
2010-09-14 21:25:10 +00:00
|
|
|
AliasAnalysis::getModRefInfo(const VAArgInst *V, const Location &Loc) {
|
2010-08-06 18:24:38 +00:00
|
|
|
// If the va_arg address cannot alias the pointer in question, then the
|
|
|
|
// specified memory cannot be accessed by the va_arg.
|
2010-11-11 21:50:19 +00:00
|
|
|
if (!alias(getLocation(V), Loc))
|
2010-08-06 18:24:38 +00:00
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
// If the pointer is a pointer to constant memory, then it could not have been
|
|
|
|
// modified by this va_arg.
|
2010-09-14 21:25:10 +00:00
|
|
|
if (pointsToConstantMemory(Loc))
|
2010-08-06 18:24:38 +00:00
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
// Otherwise, a va_arg reads and writes.
|
|
|
|
return ModRef;
|
|
|
|
}
|
|
|
|
|
2011-09-26 20:15:28 +00:00
|
|
|
AliasAnalysis::ModRefResult
|
|
|
|
AliasAnalysis::getModRefInfo(const AtomicCmpXchgInst *CX, const Location &Loc) {
|
|
|
|
// Acquire/Release cmpxchg has properties that matter for arbitrary addresses.
|
|
|
|
if (CX->getOrdering() > Monotonic)
|
|
|
|
return ModRef;
|
|
|
|
|
|
|
|
// If the cmpxchg address does not alias the location, it does not access it.
|
|
|
|
if (!alias(getLocation(CX), Loc))
|
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
return ModRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
AliasAnalysis::ModRefResult
|
|
|
|
AliasAnalysis::getModRefInfo(const AtomicRMWInst *RMW, const Location &Loc) {
|
|
|
|
// Acquire/Release atomicrmw has properties that matter for arbitrary addresses.
|
|
|
|
if (RMW->getOrdering() > Monotonic)
|
|
|
|
return ModRef;
|
|
|
|
|
|
|
|
// If the atomicrmw address does not alias the location, it does not access it.
|
|
|
|
if (!alias(getLocation(RMW), Loc))
|
|
|
|
return NoModRef;
|
|
|
|
|
|
|
|
return ModRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-22 18:25:32 +00:00
|
|
|
// AliasAnalysis destructor: DO NOT move this to the header file for
|
|
|
|
// AliasAnalysis or else clients of the AliasAnalysis class may not depend on
|
|
|
|
// the AliasAnalysis.o file in the current .a file, causing alias analysis
|
|
|
|
// support to not be included in the tool correctly!
|
|
|
|
//
|
|
|
|
AliasAnalysis::~AliasAnalysis() {}
|
|
|
|
|
2008-05-30 00:02:02 +00:00
|
|
|
/// InitializeAliasAnalysis - Subclasses must call this method to initialize the
|
2003-02-26 19:26:51 +00:00
|
|
|
/// AliasAnalysis interface before any other methods are called.
|
2002-08-22 22:46:39 +00:00
|
|
|
///
|
2003-02-26 19:26:51 +00:00
|
|
|
void AliasAnalysis::InitializeAliasAnalysis(Pass *P) {
|
2009-07-25 00:48:42 +00:00
|
|
|
TD = P->getAnalysisIfAvailable<TargetData>();
|
2004-05-23 21:15:48 +00:00
|
|
|
AA = &P->getAnalysis<AliasAnalysis>();
|
2003-02-26 19:26:51 +00:00
|
|
|
}
|
2002-08-22 18:25:32 +00:00
|
|
|
|
2003-02-26 19:26:51 +00:00
|
|
|
// getAnalysisUsage - All alias analysis implementations should invoke this
|
2009-07-25 00:48:42 +00:00
|
|
|
// directly (using AliasAnalysis::getAnalysisUsage(AU)).
|
2003-02-26 19:26:51 +00:00
|
|
|
void AliasAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
|
2004-05-23 21:15:48 +00:00
|
|
|
AU.addRequired<AliasAnalysis>(); // All AA's chain
|
2003-02-26 19:26:51 +00:00
|
|
|
}
|
2002-08-22 18:25:32 +00:00
|
|
|
|
2009-07-25 00:48:42 +00:00
|
|
|
/// getTypeStoreSize - Return the TargetData store size for the given type,
|
|
|
|
/// if known, or a conservative value otherwise.
|
|
|
|
///
|
2011-07-18 04:54:35 +00:00
|
|
|
uint64_t AliasAnalysis::getTypeStoreSize(Type *Ty) {
|
2010-10-19 17:06:23 +00:00
|
|
|
return TD ? TD->getTypeStoreSize(Ty) : UnknownSize;
|
2009-07-25 00:48:42 +00:00
|
|
|
}
|
|
|
|
|
2003-02-26 19:26:51 +00:00
|
|
|
/// canBasicBlockModify - Return true if it is possible for execution of the
|
|
|
|
/// specified basic block to modify the value pointed to by Ptr.
|
|
|
|
///
|
|
|
|
bool AliasAnalysis::canBasicBlockModify(const BasicBlock &BB,
|
2010-09-14 21:25:10 +00:00
|
|
|
const Location &Loc) {
|
|
|
|
return canInstructionRangeModify(BB.front(), BB.back(), Loc);
|
2002-08-22 18:25:32 +00:00
|
|
|
}
|
|
|
|
|
2002-08-22 22:46:39 +00:00
|
|
|
/// canInstructionRangeModify - Return true if it is possible for the execution
|
|
|
|
/// of the specified instructions to modify the value pointed to by Ptr. The
|
|
|
|
/// instructions to consider are all of the instructions in the range of [I1,I2]
|
|
|
|
/// INCLUSIVE. I1 and I2 must be in the same basic block.
|
|
|
|
///
|
2002-08-22 18:25:32 +00:00
|
|
|
bool AliasAnalysis::canInstructionRangeModify(const Instruction &I1,
|
|
|
|
const Instruction &I2,
|
2010-09-14 21:25:10 +00:00
|
|
|
const Location &Loc) {
|
2002-08-22 18:25:32 +00:00
|
|
|
assert(I1.getParent() == I2.getParent() &&
|
|
|
|
"Instructions not in same basic block!");
|
2010-08-03 21:48:53 +00:00
|
|
|
BasicBlock::const_iterator I = &I1;
|
|
|
|
BasicBlock::const_iterator E = &I2;
|
2002-08-22 18:25:32 +00:00
|
|
|
++E; // Convert from inclusive to exclusive range.
|
|
|
|
|
2003-02-26 19:26:51 +00:00
|
|
|
for (; I != E; ++I) // Check every instruction in range
|
2010-09-14 21:25:10 +00:00
|
|
|
if (getModRefInfo(I, Loc) & Mod)
|
2002-08-22 18:25:32 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-03 01:28:32 +00:00
|
|
|
/// isNoAliasCall - Return true if this pointer is returned by a noalias
|
|
|
|
/// function.
|
|
|
|
bool llvm::isNoAliasCall(const Value *V) {
|
|
|
|
if (isa<CallInst>(V) || isa<InvokeInst>(V))
|
2010-08-03 21:48:53 +00:00
|
|
|
return ImmutableCallSite(cast<Instruction>(V))
|
2009-02-03 01:28:32 +00:00
|
|
|
.paramHasAttr(0, Attribute::NoAlias);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isIdentifiedObject - Return true if this pointer refers to a distinct and
|
|
|
|
/// identifiable object. This returns true for:
|
2009-08-27 17:52:56 +00:00
|
|
|
/// Global Variables and Functions (but not Global Aliases)
|
2009-02-03 01:28:32 +00:00
|
|
|
/// Allocas and Mallocs
|
2010-07-07 14:27:09 +00:00
|
|
|
/// ByVal and NoAlias Arguments
|
|
|
|
/// NoAlias returns
|
2009-02-03 01:28:32 +00:00
|
|
|
///
|
2010-07-07 14:27:09 +00:00
|
|
|
bool llvm::isIdentifiedObject(const Value *V) {
|
2010-06-29 00:50:39 +00:00
|
|
|
if (isa<AllocaInst>(V))
|
2009-08-27 17:52:56 +00:00
|
|
|
return true;
|
|
|
|
if (isa<GlobalValue>(V) && !isa<GlobalAlias>(V))
|
2009-02-03 01:28:32 +00:00
|
|
|
return true;
|
2010-07-07 14:27:09 +00:00
|
|
|
if (isNoAliasCall(V))
|
|
|
|
return true;
|
|
|
|
if (const Argument *A = dyn_cast<Argument>(V))
|
|
|
|
return A->hasNoAliasAttr() || A->hasByValAttr();
|
2009-02-03 01:28:32 +00:00
|
|
|
return false;
|
|
|
|
}
|