36 #define DEBUG_TYPE "memdep"
38 STATISTIC(NumCacheNonLocal,
"Number of fully cached non-local responses");
39 STATISTIC(NumCacheDirtyNonLocal,
"Number of dirty cached non-local responses");
40 STATISTIC(NumUncacheNonLocal,
"Number of uncached non-local responses");
43 "Number of fully cached non-local ptr responses");
45 "Number of cached, but dirty, non-local ptr responses");
47 "Number of uncached non-local ptr responses");
49 "Number of block queries that were completely cached");
61 "Memory Dependence Analysis",
false,
true)
67 MemoryDependenceAnalysis::MemoryDependenceAnalysis()
78 NonLocalPointerDeps.
clear();
79 ReverseLocalDeps.
clear();
80 ReverseNonLocalDeps.
clear();
81 ReverseNonLocalPtrDeps.
clear();
94 AA = &getAnalysis<AliasAnalysis>();
95 AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
97 getAnalysisIfAvailable<DominatorTreeWrapperPass>();
104 template <
typename KeyTy>
109 InstIt = ReverseMap.
find(Inst);
110 assert(InstIt != ReverseMap.
end() &&
"Reverse map out of sync?");
112 assert(Found &&
"Invalid reverse map!"); (void)Found;
113 if (InstIt->second.
empty())
114 ReverseMap.erase(InstIt);
123 if (
const LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
124 if (LI->isUnordered()) {
136 if (
const StoreInst *
SI = dyn_cast<StoreInst>(Inst)) {
137 if (
SI->isUnordered()) {
149 if (
const VAArgInst *V = dyn_cast<VAArgInst>(Inst)) {
160 if (
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
163 switch (II->getIntrinsicID()) {
164 case Intrinsic::lifetime_start:
165 case Intrinsic::lifetime_end:
166 case Intrinsic::invariant_start:
167 II->getAAMetadata(AAInfo);
169 II->getArgOperand(1),
170 cast<ConstantInt>(II->getArgOperand(0))->getZExtValue(), AAInfo);
174 case Intrinsic::invariant_end:
175 II->getAAMetadata(AAInfo);
177 II->getArgOperand(2),
178 cast<ConstantInt>(II->getArgOperand(1))->getZExtValue(), AAInfo);
198 getCallSiteDependencyFrom(
CallSite CS,
bool isReadOnlyCall,
203 while (ScanIt != BB->
begin()) {
224 if (isa<DbgInfoIntrinsic>(Inst))
continue;
261 const Value *&MemLocBase,
271 MemLocBase, MemLocOffs, MemLoc.
Size, LI);
283 const Value *MemLocBase, int64_t MemLocOffs,
unsigned MemLocSize,
297 const Value *LIBase =
302 if (LIBase != MemLocBase)
return 0;
311 if (MemLocOffs < LIOffs)
return 0;
320 int64_t MemLocEnd = MemLocOffs+MemLocSize;
323 if (LIOffs+LoadAlign < MemLocEnd)
return 0;
333 if (NewLoadByteSize > LoadAlign ||
337 if (LIOffs + NewLoadByteSize > MemLocEnd &&
346 if (LIOffs+NewLoadByteSize >= MemLocEnd)
347 return NewLoadByteSize;
349 NewLoadByteSize <<= 1;
354 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst))
355 return LI->isVolatile();
356 else if (
StoreInst *
SI = dyn_cast<StoreInst>(Inst))
357 return SI->isVolatile();
359 return AI->isVolatile();
374 const Value *MemLocBase =
nullptr;
375 int64_t MemLocOffset = 0;
377 bool isInvariantLoad =
false;
411 if (isLoad && QueryInst) {
414 isInvariantLoad =
true;
420 while (ScanIt != BB->
begin()) {
425 if (isa<DbgInfoIntrinsic>(II))
continue;
436 if (II->getIntrinsicID() == Intrinsic::lifetime_start) {
452 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
457 if (LI->isVolatile()) {
470 if (LI->isAtomic() && LI->getOrdering() >
Unordered) {
475 if (
auto *QueryLI = dyn_cast<LoadInst>(QueryInst)) {
476 if (!QueryLI->isSimple())
478 }
else if (
auto *QuerySI = dyn_cast<StoreInst>(QueryInst)) {
479 if (!QuerySI->isSimple())
499 if (
IntegerType *ITy = dyn_cast<IntegerType>(LI->getType())) {
500 if (LI->getAlignment() * 8 > ITy->getPrimitiveSizeInBits() &&
512 #if 0 // FIXME: Temporarily disabled. GVN is cleverly rewriting loads
544 if (!
SI->isUnordered()) {
549 if (
auto *QueryLI = dyn_cast<LoadInst>(QueryInst)) {
550 if (!QueryLI->isSimple())
552 }
else if (
auto *QuerySI = dyn_cast<StoreInst>(QueryInst)) {
553 if (!QuerySI->isSimple())
564 if (
SI->isVolatile())
598 if (isa<AllocaInst>(Inst) ||
isNoAliasFn(Inst, TLI)) {
601 if (AccessPtr == Inst || AA->
isMustAlias(Inst, AccessPtr))
610 if (isa<AllocaInst>(Inst) ||
627 case AliasAnalysis::Mod:
657 if (!LocalCache.isDirty())
685 isLoad |= II->getIntrinsicID() == Intrinsic::lifetime_start;
688 QueryParent, QueryInst);
689 }
else if (isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)) {
692 LocalCache = getCallSiteDependencyFrom(QueryCS, isReadOnly, ScanPos,
701 ReverseLocalDeps[
I].insert(QueryInst);
711 if (Count == -1) Count = Cache.size();
712 if (Count == 0)
return;
714 for (
unsigned i = 1; i !=
unsigned(Count); ++i)
715 assert(!(Cache[i] < Cache[i-1]) &&
"Cache isn't sorted!");
734 "getNonLocalCallDependency should only be used on calls with non-local deps!");
744 if (!Cache.empty()) {
747 if (!CacheP.second) {
754 for (NonLocalDepInfo::iterator
I = Cache.begin(), E = Cache.end();
756 if (
I->getResult().isDirty())
760 std::sort(Cache.begin(), Cache.end());
762 ++NumCacheDirtyNonLocal;
770 ++NumUncacheNonLocal;
778 unsigned NumSortedEntries = Cache.
size();
782 while (!DirtyBlocks.
empty()) {
787 if (!Visited.
insert(DirtyBB).second)
793 NonLocalDepInfo::iterator Entry =
794 std::upper_bound(Cache.begin(), Cache.begin()+NumSortedEntries,
796 if (Entry != Cache.begin() && std::prev(Entry)->getBB() == DirtyBB)
800 if (Entry != Cache.begin()+NumSortedEntries &&
801 Entry->getBB() == DirtyBB) {
804 if (!Entry->getResult().isDirty())
808 ExistingResult = &*Entry;
814 if (ExistingResult) {
826 if (ScanPos != DirtyBB->
begin()) {
827 Dep = getCallSiteDependencyFrom(QueryCS, isReadonlyCall,ScanPos, DirtyBB);
873 bool isLoad = isa<LoadInst>(QueryInst);
878 "Can't get pointer deps of a non-pointer!");
890 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
891 return !LI->isUnordered();
892 }
else if (
StoreInst *
SI = dyn_cast<StoreInst>(Inst)) {
893 return !
SI->isUnordered();
897 if (
isVolatile(QueryInst) || isOrdered(QueryInst)) {
900 const_cast<Value *>(Loc.
Ptr)));
903 const DataLayout &
DL = FromBB->getModule()->getDataLayout();
911 if (!getNonLocalPointerDepFromBB(QueryInst, Address, Loc, isLoad, FromBB,
912 Result, Visited,
true))
917 const_cast<Value *>(Loc.
Ptr)));
924 MemDepResult MemoryDependenceAnalysis::GetNonLocalInfoForBlock(
926 BasicBlock *BB, NonLocalDepInfo *Cache,
unsigned NumSortedEntries) {
930 NonLocalDepInfo::iterator Entry =
931 std::upper_bound(Cache->begin(), Cache->begin()+NumSortedEntries,
933 if (Entry != Cache->begin() && (Entry-1)->getBB() == BB)
937 if (Entry != Cache->begin()+NumSortedEntries && Entry->getBB() == BB)
938 ExistingResult = &*Entry;
942 if (ExistingResult && !ExistingResult->
getResult().isDirty()) {
943 ++NumCacheNonLocalPtr;
953 "Instruction invalidated?");
954 ++NumCacheDirtyNonLocalPtr;
958 ValueIsLoadPair CacheKey(Loc.
Ptr, isLoad);
961 ++NumUncacheNonLocalPtr;
984 assert(Inst &&
"Didn't depend on anything?");
985 ValueIsLoadPair CacheKey(Loc.
Ptr, isLoad);
986 ReverseNonLocalPtrDeps[Inst].
insert(CacheKey);
995 unsigned NumSortedEntries) {
996 switch (Cache.size() - NumSortedEntries) {
1004 MemoryDependenceAnalysis::NonLocalDepInfo::iterator Entry =
1005 std::upper_bound(Cache.begin(), Cache.end()-1, Val);
1006 Cache.insert(Entry, Val);
1011 if (Cache.size() != 1) {
1014 MemoryDependenceAnalysis::NonLocalDepInfo::iterator Entry =
1015 std::upper_bound(Cache.begin(), Cache.end(), Val);
1016 Cache.insert(Entry, Val);
1021 std::sort(Cache.begin(), Cache.end());
1038 bool MemoryDependenceAnalysis::getNonLocalPointerDepFromBB(
1044 ValueIsLoadPair CacheKey(Pointer.
getAddr(), isLoad);
1050 NonLocalPointerInfo InitialNLPI;
1051 InitialNLPI.Size = Loc.
Size;
1052 InitialNLPI.AATags = Loc.
AATags;
1056 std::pair<CachedNonLocalPointerInfo::iterator, bool> Pair =
1057 NonLocalPointerDeps.
insert(std::make_pair(CacheKey, InitialNLPI));
1058 NonLocalPointerInfo *CacheInfo = &Pair.first->second;
1063 if (CacheInfo->Size < Loc.
Size) {
1066 CacheInfo->Pair = BBSkipFirstBlockPair();
1067 CacheInfo->Size = Loc.
Size;
1068 for (NonLocalDepInfo::iterator
DI = CacheInfo->NonLocalDeps.begin(),
1069 DE = CacheInfo->NonLocalDeps.end();
DI != DE; ++
DI)
1072 CacheInfo->NonLocalDeps.clear();
1073 }
else if (CacheInfo->Size > Loc.
Size) {
1076 return getNonLocalPointerDepFromBB(QueryInst, Pointer,
1078 isLoad, StartBB, Result, Visited,
1085 if (CacheInfo->AATags != Loc.
AATags) {
1086 if (CacheInfo->AATags) {
1087 CacheInfo->Pair = BBSkipFirstBlockPair();
1089 for (NonLocalDepInfo::iterator
DI = CacheInfo->NonLocalDeps.begin(),
1090 DE = CacheInfo->NonLocalDeps.end();
DI != DE; ++
DI)
1093 CacheInfo->NonLocalDeps.clear();
1096 return getNonLocalPointerDepFromBB(QueryInst,
1098 isLoad, StartBB, Result, Visited,
1107 if (CacheInfo->Pair == BBSkipFirstBlockPair(StartBB, SkipFirstBlock)) {
1113 if (!Visited.
empty()) {
1114 for (NonLocalDepInfo::iterator
I = Cache->begin(), E = Cache->end();
1117 if (VI == Visited.
end() || VI->second == Pointer.
getAddr())
1128 for (NonLocalDepInfo::iterator
I = Cache->begin(), E = Cache->end();
1130 Visited.
insert(std::make_pair(
I->getBB(), Addr));
1131 if (
I->getResult().isNonLocal()) {
1143 ++NumCacheCompleteNonLocalPtr;
1152 CacheInfo->Pair = BBSkipFirstBlockPair(StartBB, SkipFirstBlock);
1154 CacheInfo->Pair = BBSkipFirstBlockPair();
1167 unsigned NumSortedEntries = Cache->size();
1170 while (!Worklist.
empty()) {
1180 if (Cache && NumSortedEntries != Cache->size()) {
1187 CacheInfo->Pair = BBSkipFirstBlockPair();
1192 if (!SkipFirstBlock) {
1195 assert(Visited.
count(BB) &&
"Should check 'visited' before adding to WL");
1201 Loc, isLoad, BB, Cache,
1223 SkipFirstBlock =
false;
1227 std::pair<DenseMap<BasicBlock*,Value*>::iterator,
bool>
1228 InsertRes = Visited.
insert(std::make_pair(Pred, Pointer.
getAddr()));
1229 if (InsertRes.second) {
1238 if (InsertRes.first->second != Pointer.
getAddr()) {
1241 for (
unsigned i = 0; i < NewBlocks.
size(); i++)
1242 Visited.
erase(NewBlocks[i]);
1243 goto PredTranslationFailure;
1253 goto PredTranslationFailure;
1260 if (Cache && NumSortedEntries != Cache->size()) {
1262 NumSortedEntries = Cache->size();
1268 PredList.
push_back(std::make_pair(Pred, Pointer));
1281 std::pair<DenseMap<BasicBlock*,Value*>::iterator,
bool>
1282 InsertRes = Visited.
insert(std::make_pair(Pred, PredPtrVal));
1284 if (!InsertRes.second) {
1290 if (InsertRes.first->second == PredPtrVal)
1299 for (
unsigned i = 0, n = PredList.
size(); i < n; ++i)
1300 Visited.
erase(PredList[i].first);
1302 goto PredTranslationFailure;
1311 for (
unsigned i = 0, n = PredList.
size(); i < n; ++i) {
1316 bool CanTranslate =
true;
1322 CanTranslate =
false;
1332 if (!CanTranslate ||
1333 getNonLocalPointerDepFromBB(QueryInst, PredPointer,
1339 Result.push_back(Entry);
1346 NonLocalPointerInfo &NLPI = NonLocalPointerDeps[CacheKey];
1347 NLPI.Pair = BBSkipFirstBlockPair();
1353 CacheInfo = &NonLocalPointerDeps[CacheKey];
1354 Cache = &CacheInfo->NonLocalDeps;
1355 NumSortedEntries = Cache->size();
1361 CacheInfo->Pair = BBSkipFirstBlockPair();
1362 SkipFirstBlock =
false;
1365 PredTranslationFailure:
1372 CacheInfo = &NonLocalPointerDeps[CacheKey];
1373 Cache = &CacheInfo->NonLocalDeps;
1374 NumSortedEntries = Cache->size();
1381 CacheInfo->Pair = BBSkipFirstBlockPair();
1391 for (NonLocalDepInfo::reverse_iterator
I = Cache->rbegin(); ; ++
I) {
1392 assert(
I != Cache->rend() &&
"Didn't find current block??");
1393 if (
I->getBB() != BB)
1397 "Should only be here with transparent block");
1413 void MemoryDependenceAnalysis::
1414 RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair
P) {
1416 NonLocalPointerDeps.
find(P);
1417 if (It == NonLocalPointerDeps.
end())
return;
1423 for (
unsigned i = 0, e = PInfo.size(); i != e; ++i) {
1425 if (!Target)
continue;
1426 assert(Target->
getParent() == PInfo[i].getBB());
1433 NonLocalPointerDeps.
erase(It);
1466 if (NLDI != NonLocalDeps.
end()) {
1468 for (NonLocalDepInfo::iterator
DI = BlockMap.begin(), DE = BlockMap.end();
1472 NonLocalDeps.
erase(NLDI);
1478 if (LocalDepEntry != LocalDeps.
end()) {
1480 if (
Instruction *Inst = LocalDepEntry->second.getInst())
1484 LocalDeps.
erase(LocalDepEntry);
1494 RemoveCachedNonLocalPointerDependencies(
ValueIsLoadPair(RemInst,
false));
1495 RemoveCachedNonLocalPointerDependencies(
ValueIsLoadPair(RemInst,
true));
1513 if (ReverseDepIt != ReverseLocalDeps.
end()) {
1515 assert(!ReverseDepIt->second.empty() && !isa<TerminatorInst>(RemInst) &&
1516 "Nothing can locally depend on a terminator");
1518 for (
Instruction *InstDependingOnRemInst : ReverseDepIt->second) {
1519 assert(InstDependingOnRemInst != RemInst &&
1520 "Already removed our local dep info");
1522 LocalDeps[InstDependingOnRemInst] = NewDirtyVal;
1525 assert(NewDirtyVal.
getInst() &&
"There is no way something else can have "
1526 "a local dep on this if it is a terminator!");
1528 InstDependingOnRemInst));
1531 ReverseLocalDeps.
erase(ReverseDepIt);
1535 while (!ReverseDepsToAdd.
empty()) {
1536 ReverseLocalDeps[ReverseDepsToAdd.
back().first]
1542 ReverseDepIt = ReverseNonLocalDeps.
find(RemInst);
1543 if (ReverseDepIt != ReverseNonLocalDeps.
end()) {
1545 assert(I != RemInst &&
"Already removed NonLocalDep info for RemInst");
1547 PerInstNLInfo &INLD = NonLocalDeps[
I];
1551 for (NonLocalDepInfo::iterator
DI = INLD.first.begin(),
1552 DE = INLD.first.end();
DI != DE; ++
DI) {
1553 if (
DI->getResult().getInst() != RemInst)
continue;
1556 DI->setResult(NewDirtyVal);
1559 ReverseDepsToAdd.
push_back(std::make_pair(NextI, I));
1563 ReverseNonLocalDeps.
erase(ReverseDepIt);
1566 while (!ReverseDepsToAdd.
empty()) {
1567 ReverseNonLocalDeps[ReverseDepsToAdd.
back().first]
1576 ReverseNonLocalPtrDeps.
find(RemInst);
1577 if (ReversePtrDepIt != ReverseNonLocalPtrDeps.
end()) {
1582 "Already removed NonLocalPointerDeps info for RemInst");
1590 for (NonLocalDepInfo::iterator
DI = NLPDI.begin(), DE = NLPDI.end();
1592 if (
DI->getResult().getInst() != RemInst)
continue;
1595 DI->setResult(NewDirtyVal);
1598 ReversePtrDepsToAdd.
push_back(std::make_pair(NewDirtyInst, P));
1603 std::sort(NLPDI.begin(), NLPDI.end());
1606 ReverseNonLocalPtrDeps.
erase(ReversePtrDepIt);
1608 while (!ReversePtrDepsToAdd.
empty()) {
1609 ReverseNonLocalPtrDeps[ReversePtrDepsToAdd.
back().first]
1616 assert(!NonLocalDeps.
count(RemInst) &&
"RemInst got reinserted?");
1618 DEBUG(verifyRemoved(RemInst));
1623 void MemoryDependenceAnalysis::verifyRemoved(
Instruction *D)
const {
1626 E = LocalDeps.
end();
I != E; ++
I) {
1627 assert(
I->first != D &&
"Inst occurs in data structures");
1628 assert(
I->second.getInst() != D &&
1629 "Inst occurs in data structures");
1633 E = NonLocalPointerDeps.
end();
I != E; ++
I) {
1634 assert(
I->first.getPointer() != D &&
"Inst occurs in NLPD map key");
1636 for (NonLocalDepInfo::const_iterator II = Val.begin(), E = Val.end();
1638 assert(II->getResult().getInst() != D &&
"Inst occurs as NLPD value");
1642 E = NonLocalDeps.
end();
I != E; ++
I) {
1643 assert(
I->first != D &&
"Inst occurs in data structures");
1644 const PerInstNLInfo &INLD =
I->second;
1645 for (NonLocalDepInfo::const_iterator II = INLD.first.begin(),
1646 EE = INLD.first.end(); II != EE; ++II)
1647 assert(II->getResult().getInst() != D &&
"Inst occurs in data structures");
1651 E = ReverseLocalDeps.
end();
I != E; ++
I) {
1652 assert(
I->first != D &&
"Inst occurs in data structures");
1654 assert(Inst != D &&
"Inst occurs in data structures");
1658 E = ReverseNonLocalDeps.
end();
1660 assert(
I->first != D &&
"Inst occurs in data structures");
1662 assert(Inst != D &&
"Inst occurs in data structures");
1666 I = ReverseNonLocalPtrDeps.
begin(),
1667 E = ReverseNonLocalPtrDeps.
end();
I != E; ++
I) {
1668 assert(
I->first != D &&
"Inst occurs in rev NLPD map");
1670 for (ValueIsLoadPair P :
I->second)
1671 assert(P != ValueIsLoadPair(D,
false) &&
1672 P != ValueIsLoadPair(D,
true) &&
1673 "Inst occurs in ReverseNonLocalPtrDeps map");
The two locations precisely alias each other.
void push_back(const T &Elt)
static AliasAnalysis::ModRefResult GetLocation(const Instruction *Inst, MemoryLocation &Loc, AliasAnalysis *AA)
GetLocation - If the given instruction references a specific memory location, fill in Loc with the de...
A parsed version of the target data layout string in and methods for querying it. ...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void invalidateCachedPointerInfo(Value *Ptr)
invalidateCachedPointerInfo - This method is used to invalidate cached information about the specifie...
bool isDef() const
isDef - Return true if this MemDepResult represents a query that is an instruction definition depende...
STATISTIC(NumFunctions,"Total number of functions")
ModRefResult callCapturesBefore(const Instruction *I, const MemoryLocation &MemLoc, DominatorTree *DT)
callCapturesBefore - Return information about whether a particular call site modifies or reads the sp...
InstrTy * getInstruction() const
AtomicCmpXchgInst - an instruction that atomically checks whether a specified value is in a memory lo...
static void RemoveFromReverseMap(DenseMap< Instruction *, SmallPtrSet< KeyTy, 4 > > &ReverseMap, Instruction *Inst, KeyTy Val)
RemoveFromReverseMap - This is a helper function that removes Val from 'Inst's set in ReverseMap...
This class provides various memory handling functions that manipulate MemoryBlock instances...
The two locations alias, but only due to a partial overlap.
CallInst - This class represents a function call, abstracting a target machine's calling convention...
static void AssertSorted(MemoryDependenceAnalysis::NonLocalDepInfo &Cache, int Count=-1)
AssertSorted - This method is used when -debug is specified to verify that cache arrays are properly ...
An immutable pass that tracks lazily created AssumptionCache objects.
const Function * getParent() const
Return the enclosing method, or null if none.
The two locations do not alias at all.
LoadInst - an instruction for reading from memory.
bool isClobber() const
isClobber - Return true if this MemDepResult represents a query that is an instruction clobber depend...
MemoryLocation getWithNewSize(uint64_t NewSize) const
virtual bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal=false)
pointsToConstantMemory - If the specified memory location is known to be constant, return true.
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
isMustAlias - A convenience wrapper.
iterator begin()
Instruction iterator methods.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
AnalysisUsage & addRequired()
ArrayRef< BasicBlock * > get(BasicBlock *BB)
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool NeedsPHITranslationFromBlock(BasicBlock *BB) const
NeedsPHITranslationFromBlock - Return true if moving from the specified BasicBlock to its predecessor...
MemoryLocation getWithoutAATags() const
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
bool runOnFunction(Function &) override
Pass Implementation stuff. This doesn't do any analysis eagerly.
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
static MemDepResult getDef(Instruction *Inst)
get methods: These are static ctor methods for creating various MemDepResult kinds.
MemoryLocation getWithNewPtr(const Value *NewPtr) const
MemoryDependenceAnalysis - This is an analysis that determines, for a given memory operation...
DominatorTree & getDomTree()
bool isNoAliasFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a function that returns a NoAlias pointer (including malloc/c...
bool mayReadFromMemory() const
mayReadFromMemory - Return true if this instruction may read memory.
void releaseMemory() override
Clean up memory in between runs.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL)
GetPointerBaseWithConstantOffset - Analyze the specified pointer to see if it can be expressed as a b...
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
StoreInst - an instruction for storing to memory.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Does not modify anything.
bool onlyReadsMemory(ImmutableCallSite CS)
onlyReadsMemory - If the specified call is known to only read from non-volatile memory (or not access...
bool mayReadOrWriteMemory() const
mayReadOrWriteMemory - Return true if this instruction may read or write memory.
static MemDepResult getUnknown()
MemDepResult getPointerDependencyFrom(const MemoryLocation &Loc, bool isLoad, BasicBlock::iterator ScanIt, BasicBlock *BB, Instruction *QueryInst=nullptr)
getPointerDependencyFrom - Return the instruction on which a memory location depends.
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
bool erase(const KeyT &Val)
bool isIdenticalToWhenDefined(const Instruction *I) const
isIdenticalToWhenDefined - This is like isIdenticalTo, except that it ignores the SubclassOptionalDat...
LLVM Basic Block Representation.
PointerIntPair - This class implements a pair of a pointer and small integer.
PHITransAddr - An address value which tracks and handles phi translation.
NonLocalDepResult - This is a result from a NonLocal dependence query.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
AliasResult
The possible results of an alias query.
Represent the analysis usage information of a pass.
static MemDepResult getNonFuncLocal()
FunctionPass class - This class is used to implement most global optimizations.
Value * getPointerOperand()
const MemDepResult & getResult() const
Class to represent integer types.
void setResult(const MemDepResult &R)
#define INITIALIZE_AG_DEPENDENCY(depName)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
uint64_t NextPowerOf2(uint64_t A)
NextPowerOf2 - Returns the next power of two (in 64-bits) that is strictly greater than A...
VAArgInst - This class represents the va_arg llvm instruction, which returns an argument of the speci...
virtual void deleteValue(Value *V)
Methods that clients should call when they transform the program to allow alias analyses to update th...
DenseMapIterator< Instruction *, MemDepResult, DenseMapInfo< Instruction * >, detail::DenseMapPair< Instruction *, MemDepResult >, true > const_iterator
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
GetUnderlyingObject - This method strips off any GEP address adjustments and pointer casts from the s...
bool IsPotentiallyPHITranslatable() const
IsPotentiallyPHITranslatable - If this needs PHI translation, return true if we have some hope of doi...
bool mayWriteToMemory() const
mayWriteToMemory - Return true if this instruction may modify memory.
MemDepResult - A memory dependence query can return one of three different answers, described below.
void clear()
clear - Remove all information.
bool isTerminator() const
const Value * Ptr
The address of the start of the location.
Representation for a specific memory location.
PointerTy getPointer() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
bool fitsInLegalInteger(unsigned Width) const
Returns true if the specified type fits in a native integer type supported by the CPU...
bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree *DT, bool MustDominate)
PHITranslateValue - PHI translate the current address up the CFG from CurBB to Pred, updating our state to reflect any needed changes.
virtual AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
Alias Queries...
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
static const unsigned int BlockScanLimit
Provides information about what library functions are available for the current target.
static MemDepResult getClobber(Instruction *Inst)
MDNode * getMetadata(unsigned KindID) const
getMetadata - Get the metadata of given kind attached to this Instruction.
ModRefResult getModRefInfo(const Instruction *I)
getModRefInfo - Return information about whether or not an instruction may read or write memory (with...
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
bool isNonLocal() const
isNonLocal - Return true if this MemDepResult represents a query that is transparent to the start of ...
std::vector< NonLocalDepEntry > NonLocalDepInfo
DenseMapIterator< ValueIsLoadPair, NonLocalPointerInfo, DenseMapInfo< ValueIsLoadPair >, detail::DenseMapPair< ValueIsLoadPair, NonLocalPointerInfo > > iterator
const BasicBlock & getEntryBlock() const
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Target - Wrapper for Target specific information.
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isMallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates uninitialized memory (such ...
INITIALIZE_PASS_BEGIN(MemoryDependenceAnalysis,"memdep","Memory Dependence Analysis", false, true) INITIALIZE_PASS_END(MemoryDependenceAnalysis
void initializeMemoryDependenceAnalysisPass(PassRegistry &)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Instruction * getInst() const
getInst() - If this is a normal dependency, return the instruction that is depended on...
AAMDNodes AATags
The metadata nodes which describes the aliasing of the location (each member is null if that kind of ...
static void SortNonLocalDepInfoCache(MemoryDependenceAnalysis::NonLocalDepInfo &Cache, unsigned NumSortedEntries)
SortNonLocalDepInfoCache - Sort the NonLocalDepInfo cache, given a certain number of elements in the ...
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
MemDepResult getDependency(Instruction *QueryInst)
getDependency - Return the instruction on which a memory operation depends.
void invalidateCachedPredecessors()
invalidateCachedPredecessors - Clear the PredIteratorCache info.
unsigned getAlignment() const
getAlignment - Return the alignment of the access that is being performed
bool isCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates zero-filled memory (such as...
iterator find(const KeyT &Val)
~MemoryDependenceAnalysis() override
const NonLocalDepInfo & getNonLocalCallDependency(CallSite QueryCS)
getNonLocalCallDependency - Perform a full dependency query for the specified call, returning the set of blocks that the value is potentially live across.
AnalysisUsage & addRequiredTransitive()
Memory Dependence Analysis
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
ModRefResult
Simple mod/ref information...
const TargetLibraryInfo * getTargetLibraryInfo() const
getTargetLibraryInfo - Return a pointer to the current TargetLibraryInfo object, or null if no Target...
NonLocalDepEntry - This is an entry in the NonLocalDepInfo cache.
static bool isLoadLoadClobberIfExtendedToFullWidth(const MemoryLocation &MemLoc, const Value *&MemLocBase, int64_t &MemLocOffs, const LoadInst *LI)
isLoadLoadClobberIfExtendedToFullWidth - Return true if LI is a load that would fully overlap MemLoc ...
Legacy analysis pass which computes a DominatorTree.
static bool isVolatile(Instruction *Inst)
Dependence - This class represents a dependence between two memory memory references in a function...
static MemDepResult getNonLocal()
static unsigned getLoadLoadClobberFullWidthSize(const Value *MemLocBase, int64_t MemLocOffs, unsigned MemLocSize, const LoadInst *LI)
getLoadLoadClobberFullWidthSize - This is a little bit of analysis that looks at a memory location fo...
static const unsigned int NumResultsLimit
const BasicBlock * getParent() const
void removeInstruction(Instruction *InstToRemove)
removeInstruction - Remove an instruction from the dependence analysis, updating the dependence of in...
void getNonLocalPointerDependency(Instruction *QueryInst, SmallVectorImpl< NonLocalDepResult > &Result)
getNonLocalPointerDependency - Perform a full dependency query for an access to the QueryInst's speci...
IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic functions.
uint64_t Size
The maximum size of the location, in address-units, or UnknownSize if the size is not known...