52 #define DEBUG_TYPE "memdep"
54 STATISTIC(NumCacheNonLocal,
"Number of fully cached non-local responses");
55 STATISTIC(NumCacheDirtyNonLocal,
"Number of dirty cached non-local responses");
56 STATISTIC(NumUncacheNonLocal,
"Number of uncached non-local responses");
59 "Number of fully cached non-local ptr responses");
61 "Number of cached, but dirty, non-local ptr responses");
62 STATISTIC(NumUncacheNonLocalPtr,
"Number of uncached non-local ptr responses");
64 "Number of block queries that were completely cached");
70 cl::desc(
"The number of instructions to scan in a block in memory "
71 "dependency analysis (default = 100)"));
75 cl::desc(
"The number of blocks to scan during memory "
76 "dependency analysis (default = 1000)"));
84 template <
typename KeyTy>
89 ReverseMap.
find(Inst);
90 assert(InstIt != ReverseMap.
end() &&
"Reverse map out of sync?");
91 bool Found = InstIt->second.
erase(Val);
92 assert(Found &&
"Invalid reverse map!");
94 if (InstIt->second.
empty())
95 ReverseMap.erase(InstIt);
105 if (
const LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
106 if (LI->isUnordered()) {
118 if (
const StoreInst *
SI = dyn_cast<StoreInst>(Inst)) {
119 if (
SI->isUnordered()) {
131 if (
const VAArgInst *V = dyn_cast<VAArgInst>(Inst)) {
142 if (
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
145 switch (II->getIntrinsicID()) {
146 case Intrinsic::lifetime_start:
147 case Intrinsic::lifetime_end:
148 case Intrinsic::invariant_start:
149 II->getAAMetadata(AAInfo);
151 II->getArgOperand(1),
152 cast<ConstantInt>(II->getArgOperand(0))->getZExtValue(), AAInfo);
156 case Intrinsic::invariant_end:
157 II->getAAMetadata(AAInfo);
159 II->getArgOperand(2),
160 cast<ConstantInt>(II->getArgOperand(1))->getZExtValue(), AAInfo);
178 MemDepResult MemoryDependenceResults::getCallSiteDependencyFrom(
184 while (ScanIt != BB->
begin()) {
205 if (isa<DbgInfoIntrinsic>(Inst))
212 if (isReadOnlyCall && !(MR &
MRI_Mod) &&
238 const Value *MemLocBase, int64_t MemLocOffs,
unsigned MemLocSize,
253 const Value *LIBase =
258 if (LIBase != MemLocBase)
268 if (MemLocOffs < LIOffs)
278 int64_t MemLocEnd = MemLocOffs + MemLocSize;
281 if (LIOffs + LoadAlign < MemLocEnd)
292 if (NewLoadByteSize > LoadAlign ||
296 if (LIOffs + NewLoadByteSize > MemLocEnd &&
298 Attribute::SanitizeAddress))
305 if (LIOffs + NewLoadByteSize >= MemLocEnd)
306 return NewLoadByteSize;
308 NewLoadByteSize <<= 1;
313 if (
auto *LI = dyn_cast<LoadInst>(Inst))
314 return LI->isVolatile();
315 if (
auto *
SI = dyn_cast<StoreInst>(Inst))
316 return SI->isVolatile();
317 if (
auto *AI = dyn_cast<AtomicCmpXchgInst>(Inst))
318 return AI->isVolatile();
327 if (QueryInst !=
nullptr) {
328 if (
auto *LI = dyn_cast<LoadInst>(QueryInst)) {
331 if (InvariantGroupDependency.
isDef())
332 return InvariantGroupDependency;
336 MemLoc, isLoad, ScanIt, BB, QueryInst, Limit);
337 if (SimpleDep.
isDef())
343 return InvariantGroupDependency;
346 "InvariantGroupDependency should be only unknown at this point");
355 if (!InvariantGroupMD)
366 if (isa<GlobalValue>(LoadOperand))
371 LoadOperandsQueue.
push_back(LoadOperand);
377 assert(
Other &&
"Must call it with not null instruction");
386 while (!LoadOperandsQueue.
empty()) {
388 assert(Ptr && !isa<GlobalValue>(Ptr) &&
389 "Null or GlobalValue should not be inserted");
391 for (
const Use &Us : Ptr->
uses()) {
393 if (!U || U == LI || !DT.
dominates(U, LI))
398 if (isa<BitCastInst>(U)) {
407 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(U))
408 if (
GEP->hasAllZeroIndices()) {
416 if ((isa<LoadInst>(U) || isa<StoreInst>(U)) &&
418 ClosestDependency = GetClosestDependency(ClosestDependency, U);
422 if (!ClosestDependency)
424 if (ClosestDependency->
getParent() == BB)
430 NonLocalDefsCache.try_emplace(
439 bool isInvariantLoad =
false;
479 if (isLoad && QueryInst) {
482 isInvariantLoad =
true;
495 auto isNonSimpleLoadOrStore = [](
Instruction *
I) ->
bool {
496 if (
auto *LI = dyn_cast<LoadInst>(
I))
497 return !LI->isSimple();
498 if (
auto *
SI = dyn_cast<StoreInst>(
I))
499 return !
SI->isSimple();
506 return !isa<LoadInst>(
I) && !isa<StoreInst>(
I) &&
I->mayReadOrWriteMemory();
510 while (ScanIt != BB->
begin()) {
515 if (isa<DbgInfoIntrinsic>(II))
527 if (II->getIntrinsicID() == Intrinsic::lifetime_start) {
543 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
548 if (LI->isVolatile()) {
563 if (!QueryInst || isNonSimpleLoadOrStore(QueryInst) ||
564 isOtherMemAccess(QueryInst))
583 #if 0 // FIXME: Temporarily disabled. GVN is cleverly rewriting loads
615 if (!
SI->isUnordered() &&
SI->isAtomic()) {
616 if (!QueryInst || isNonSimpleLoadOrStore(QueryInst) ||
617 isOtherMemAccess(QueryInst))
627 if (
SI->isVolatile())
628 if (!QueryInst || isNonSimpleLoadOrStore(QueryInst) ||
629 isOtherMemAccess(QueryInst))
660 if (isa<AllocaInst>(Inst) ||
isNoAliasFn(Inst, &TLI)) {
662 if (AccessPtr == Inst || AA.
isMustAlias(Inst, AccessPtr))
674 if (
FenceInst *FI = dyn_cast<FenceInst>(Inst))
716 if (!LocalCache.isDirty())
743 if (
auto *II = dyn_cast<IntrinsicInst>(QueryInst))
744 isLoad |= II->getIntrinsicID() == Intrinsic::lifetime_start;
747 MemLoc, isLoad, ScanPos->
getIterator(), QueryParent, QueryInst);
748 }
else if (isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)) {
751 LocalCache = getCallSiteDependencyFrom(
752 QueryCS, isReadOnly, ScanPos->
getIterator(), QueryParent);
760 ReverseLocalDeps[
I].insert(QueryInst);
771 Count = Cache.size();
772 assert(std::is_sorted(Cache.begin(), Cache.begin() + Count) &&
773 "Cache isn't sorted!");
780 "getNonLocalCallDependency should only be used on calls with "
790 if (!Cache.empty()) {
793 if (!CacheP.second) {
800 for (
auto &Entry : Cache)
801 if (Entry.getResult().isDirty())
807 ++NumCacheDirtyNonLocal;
815 ++NumUncacheNonLocal;
823 unsigned NumSortedEntries = Cache.
size();
827 while (!DirtyBlocks.
empty()) {
832 if (!Visited.
insert(DirtyBB).second)
838 NonLocalDepInfo::iterator Entry =
839 std::upper_bound(Cache.begin(), Cache.begin() + NumSortedEntries,
841 if (Entry != Cache.begin() && std::prev(Entry)->getBB() == DirtyBB)
845 if (Entry != Cache.begin() + NumSortedEntries &&
846 Entry->getBB() == DirtyBB) {
849 if (!Entry->getResult().isDirty())
853 ExistingResult = &*Entry;
859 if (ExistingResult) {
871 if (ScanPos != DirtyBB->
begin()) {
873 getCallSiteDependencyFrom(QueryCS, isReadonlyCall, ScanPos, DirtyBB);
911 bool isLoad = isa<LoadInst>(QueryInst);
916 "Can't get pointer deps of a non-pointer!");
922 auto NonLocalDefIt = NonLocalDefsCache.find(QueryInst);
923 if (NonLocalDefIt != NonLocalDefsCache.end()) {
924 Result.
push_back(std::move(NonLocalDefIt->second));
925 NonLocalDefsCache.erase(NonLocalDefIt);
938 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
939 return !LI->isUnordered();
940 }
else if (
StoreInst *
SI = dyn_cast<StoreInst>(Inst)) {
941 return !
SI->isUnordered();
947 const_cast<Value *>(Loc.
Ptr)));
950 const DataLayout &
DL = FromBB->getModule()->getDataLayout();
958 if (getNonLocalPointerDepFromBB(QueryInst, Address, Loc, isLoad, FromBB,
959 Result, Visited,
true))
963 const_cast<Value *>(Loc.
Ptr)));
971 MemDepResult MemoryDependenceResults::GetNonLocalInfoForBlock(
973 BasicBlock *BB, NonLocalDepInfo *Cache,
unsigned NumSortedEntries) {
977 NonLocalDepInfo::iterator Entry = std::upper_bound(
979 if (Entry != Cache->begin() && (Entry - 1)->getBB() == BB)
983 if (Entry != Cache->begin() + NumSortedEntries && Entry->getBB() == BB)
984 ExistingResult = &*Entry;
988 if (ExistingResult && !ExistingResult->
getResult().isDirty()) {
989 ++NumCacheNonLocalPtr;
999 "Instruction invalidated?");
1000 ++NumCacheDirtyNonLocalPtr;
1004 ValueIsLoadPair CacheKey(Loc.
Ptr, isLoad);
1007 ++NumUncacheNonLocalPtr;
1030 assert(Inst &&
"Didn't depend on anything?");
1031 ValueIsLoadPair CacheKey(Loc.
Ptr, isLoad);
1032 ReverseNonLocalPtrDeps[Inst].
insert(CacheKey);
1042 unsigned NumSortedEntries) {
1043 switch (Cache.size() - NumSortedEntries) {
1051 MemoryDependenceResults::NonLocalDepInfo::iterator Entry =
1052 std::upper_bound(Cache.begin(), Cache.end() - 1, Val);
1053 Cache.insert(Entry, Val);
1058 if (Cache.size() != 1) {
1061 MemoryDependenceResults::NonLocalDepInfo::iterator Entry =
1062 std::upper_bound(Cache.begin(), Cache.end(), Val);
1063 Cache.insert(Entry, Val);
1086 bool MemoryDependenceResults::getNonLocalPointerDepFromBB(
1092 ValueIsLoadPair CacheKey(Pointer.
getAddr(), isLoad);
1098 NonLocalPointerInfo InitialNLPI;
1099 InitialNLPI.Size = Loc.
Size;
1100 InitialNLPI.AATags = Loc.
AATags;
1104 std::pair<CachedNonLocalPointerInfo::iterator, bool> Pair =
1105 NonLocalPointerDeps.
insert(std::make_pair(CacheKey, InitialNLPI));
1106 NonLocalPointerInfo *CacheInfo = &Pair.first->second;
1111 if (CacheInfo->Size < Loc.
Size) {
1114 CacheInfo->Pair = BBSkipFirstBlockPair();
1115 CacheInfo->Size = Loc.
Size;
1116 for (
auto &Entry : CacheInfo->NonLocalDeps)
1117 if (
Instruction *Inst = Entry.getResult().getInst())
1119 CacheInfo->NonLocalDeps.clear();
1120 }
else if (CacheInfo->Size > Loc.
Size) {
1123 return getNonLocalPointerDepFromBB(
1125 StartBB, Result, Visited, SkipFirstBlock);
1131 if (CacheInfo->AATags != Loc.
AATags) {
1132 if (CacheInfo->AATags) {
1133 CacheInfo->Pair = BBSkipFirstBlockPair();
1135 for (
auto &Entry : CacheInfo->NonLocalDeps)
1136 if (
Instruction *Inst = Entry.getResult().getInst())
1138 CacheInfo->NonLocalDeps.clear();
1141 return getNonLocalPointerDepFromBB(
1143 Visited, SkipFirstBlock);
1151 if (CacheInfo->Pair == BBSkipFirstBlockPair(StartBB, SkipFirstBlock)) {
1157 if (!Visited.
empty()) {
1158 for (
auto &Entry : *Cache) {
1160 Visited.
find(Entry.getBB());
1161 if (VI == Visited.
end() || VI->second == Pointer.
getAddr())
1172 for (
auto &Entry : *Cache) {
1173 Visited.
insert(std::make_pair(Entry.getBB(), Addr));
1174 if (Entry.getResult().isNonLocal()) {
1183 ++NumCacheCompleteNonLocalPtr;
1192 CacheInfo->Pair = BBSkipFirstBlockPair(StartBB, SkipFirstBlock);
1194 CacheInfo->Pair = BBSkipFirstBlockPair();
1207 unsigned NumSortedEntries = Cache->size();
1209 bool GotWorklistLimit =
false;
1212 while (!Worklist.
empty()) {
1222 if (Cache && NumSortedEntries != Cache->size()) {
1229 CacheInfo->Pair = BBSkipFirstBlockPair();
1234 if (!SkipFirstBlock) {
1237 assert(Visited.
count(BB) &&
"Should check 'visited' before adding to WL");
1242 MemDepResult Dep = GetNonLocalInfoForBlock(QueryInst, Loc, isLoad, BB,
1243 Cache, NumSortedEntries);
1259 SkipFirstBlock =
false;
1263 std::pair<DenseMap<BasicBlock *, Value *>::iterator,
bool> InsertRes =
1265 if (InsertRes.second) {
1274 if (InsertRes.first->second != Pointer.
getAddr()) {
1277 for (
unsigned i = 0; i < NewBlocks.
size(); i++)
1278 Visited.
erase(NewBlocks[i]);
1279 goto PredTranslationFailure;
1282 if (NewBlocks.
size() > WorklistEntries) {
1285 for (
unsigned i = 0; i < NewBlocks.
size(); i++)
1286 Visited.
erase(NewBlocks[i]);
1287 GotWorklistLimit =
true;
1288 goto PredTranslationFailure;
1290 WorklistEntries -= NewBlocks.
size();
1298 goto PredTranslationFailure;
1305 if (Cache && NumSortedEntries != Cache->size()) {
1307 NumSortedEntries = Cache->size();
1313 PredList.
push_back(std::make_pair(Pred, Pointer));
1326 std::pair<DenseMap<BasicBlock *, Value *>::iterator,
bool> InsertRes =
1327 Visited.
insert(std::make_pair(Pred, PredPtrVal));
1329 if (!InsertRes.second) {
1335 if (InsertRes.first->second == PredPtrVal)
1344 for (
unsigned i = 0, n = PredList.
size(); i < n; ++i)
1345 Visited.
erase(PredList[i].first);
1347 goto PredTranslationFailure;
1356 for (
unsigned i = 0, n = PredList.
size(); i < n; ++i) {
1361 bool CanTranslate =
true;
1367 CanTranslate =
false;
1377 if (!CanTranslate ||
1378 !getNonLocalPointerDepFromBB(QueryInst, PredPointer,
1380 Pred, Result, Visited)) {
1383 Result.push_back(Entry);
1390 NonLocalPointerInfo &NLPI = NonLocalPointerDeps[CacheKey];
1391 NLPI.Pair = BBSkipFirstBlockPair();
1397 CacheInfo = &NonLocalPointerDeps[CacheKey];
1398 Cache = &CacheInfo->NonLocalDeps;
1399 NumSortedEntries = Cache->size();
1405 CacheInfo->Pair = BBSkipFirstBlockPair();
1406 SkipFirstBlock =
false;
1409 PredTranslationFailure:
1416 CacheInfo = &NonLocalPointerDeps[CacheKey];
1417 Cache = &CacheInfo->NonLocalDeps;
1418 NumSortedEntries = Cache->size();
1425 CacheInfo->Pair = BBSkipFirstBlockPair();
1435 bool foundBlock =
false;
1437 if (
I.getBB() != BB)
1440 assert((GotWorklistLimit ||
I.getResult().isNonLocal() ||
1442 "Should only be here with transparent block");
1449 (void)foundBlock; (void)GotWorklistLimit;
1450 assert((foundBlock || GotWorklistLimit) &&
"Current block not in cache?");
1460 void MemoryDependenceResults::RemoveCachedNonLocalPointerDependencies(
1461 ValueIsLoadPair
P) {
1463 if (It == NonLocalPointerDeps.
end())
1470 for (
unsigned i = 0, e = PInfo.size(); i != e; ++i) {
1481 NonLocalPointerDeps.
erase(It);
1502 if (NLDI != NonLocalDeps.
end()) {
1504 for (
auto &Entry : BlockMap)
1505 if (
Instruction *Inst = Entry.getResult().getInst())
1507 NonLocalDeps.
erase(NLDI);
1513 if (LocalDepEntry != LocalDeps.
end()) {
1515 if (
Instruction *Inst = LocalDepEntry->second.getInst())
1519 LocalDeps.
erase(LocalDepEntry);
1529 RemoveCachedNonLocalPointerDependencies(
ValueIsLoadPair(RemInst,
false));
1530 RemoveCachedNonLocalPointerDependencies(
ValueIsLoadPair(RemInst,
true));
1545 NewDirtyVal = MemDepResult::getDirty(&*++RemInst->
getIterator());
1548 if (ReverseDepIt != ReverseLocalDeps.
end()) {
1550 assert(!ReverseDepIt->second.empty() && !isa<TerminatorInst>(RemInst) &&
1551 "Nothing can locally depend on a terminator");
1553 for (
Instruction *InstDependingOnRemInst : ReverseDepIt->second) {
1554 assert(InstDependingOnRemInst != RemInst &&
1555 "Already removed our local dep info");
1557 LocalDeps[InstDependingOnRemInst] = NewDirtyVal;
1561 "There is no way something else can have "
1562 "a local dep on this if it is a terminator!");
1564 std::make_pair(NewDirtyVal.
getInst(), InstDependingOnRemInst));
1567 ReverseLocalDeps.
erase(ReverseDepIt);
1571 while (!ReverseDepsToAdd.
empty()) {
1572 ReverseLocalDeps[ReverseDepsToAdd.
back().first].
insert(
1573 ReverseDepsToAdd.
back().second);
1578 ReverseDepIt = ReverseNonLocalDeps.
find(RemInst);
1579 if (ReverseDepIt != ReverseNonLocalDeps.
end()) {
1581 assert(I != RemInst &&
"Already removed NonLocalDep info for RemInst");
1583 PerInstNLInfo &INLD = NonLocalDeps[
I];
1587 for (
auto &Entry : INLD.first) {
1588 if (Entry.getResult().getInst() != RemInst)
1592 Entry.setResult(NewDirtyVal);
1595 ReverseDepsToAdd.
push_back(std::make_pair(NextI, I));
1599 ReverseNonLocalDeps.
erase(ReverseDepIt);
1602 while (!ReverseDepsToAdd.
empty()) {
1603 ReverseNonLocalDeps[ReverseDepsToAdd.
back().first].
insert(
1604 ReverseDepsToAdd.
back().second);
1612 ReverseNonLocalPtrDeps.
find(RemInst);
1613 if (ReversePtrDepIt != ReverseNonLocalPtrDeps.
end()) {
1615 ReversePtrDepsToAdd;
1619 "Already removed NonLocalPointerDeps info for RemInst");
1627 for (
auto &Entry : NLPDI) {
1628 if (Entry.getResult().getInst() != RemInst)
1632 Entry.setResult(NewDirtyVal);
1635 ReversePtrDepsToAdd.
push_back(std::make_pair(NewDirtyInst, P));
1643 ReverseNonLocalPtrDeps.
erase(ReversePtrDepIt);
1645 while (!ReversePtrDepsToAdd.
empty()) {
1646 ReverseNonLocalPtrDeps[ReversePtrDepsToAdd.
back().first].
insert(
1647 ReversePtrDepsToAdd.
back().second);
1652 assert(!NonLocalDeps.
count(RemInst) &&
"RemInst got reinserted?");
1653 DEBUG(verifyRemoved(RemInst));
1660 void MemoryDependenceResults::verifyRemoved(
Instruction *
D)
const {
1662 for (
const auto &DepKV : LocalDeps) {
1663 assert(DepKV.first != D &&
"Inst occurs in data structures");
1664 assert(DepKV.second.getInst() != D &&
"Inst occurs in data structures");
1667 for (
const auto &DepKV : NonLocalPointerDeps) {
1668 assert(DepKV.first.getPointer() != D &&
"Inst occurs in NLPD map key");
1669 for (
const auto &Entry : DepKV.second.NonLocalDeps)
1670 assert(Entry.getResult().getInst() != D &&
"Inst occurs as NLPD value");
1673 for (
const auto &DepKV : NonLocalDeps) {
1674 assert(DepKV.first != D &&
"Inst occurs in data structures");
1675 const PerInstNLInfo &INLD = DepKV.second;
1676 for (
const auto &Entry : INLD.first)
1677 assert(Entry.getResult().getInst() != D &&
1678 "Inst occurs in data structures");
1681 for (
const auto &DepKV : ReverseLocalDeps) {
1682 assert(DepKV.first != D &&
"Inst occurs in data structures");
1684 assert(Inst != D &&
"Inst occurs in data structures");
1687 for (
const auto &DepKV : ReverseNonLocalDeps) {
1688 assert(DepKV.first != D &&
"Inst occurs in data structures");
1690 assert(Inst != D &&
"Inst occurs in data structures");
1693 for (
const auto &DepKV : ReverseNonLocalPtrDeps) {
1694 assert(DepKV.first != D &&
"Inst occurs in rev NLPD map");
1696 for (ValueIsLoadPair P : DepKV.second)
1697 assert(P != ValueIsLoadPair(D,
false) && P != ValueIsLoadPair(D,
true) &&
1698 "Inst occurs in ReverseNonLocalPtrDeps map");
1717 "Memory Dependence Analysis",
false,
true)
1766 auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
1767 auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
1768 auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
1769 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
1770 MemDep.emplace(AA, AC, TLI, DT);
The two locations precisely alias each other.
void push_back(const T &Elt)
void invalidateCachedPointerInfo(Value *Ptr)
Invalidates cached information about the specified pointer, because it may be too conservative in mem...
A parsed version of the target data layout string in and methods for querying it. ...
void invalidateCachedPredecessors()
Clears the PredIteratorCache info.
iterator_range< use_iterator > uses()
Provides a lazy, caching interface for making common memory aliasing information queries, backed by LLVM's alias analysis passes.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool isDef() const
Tests if this MemDepResult represents a query that is an instruction definition dependency.
Atomic ordering constants.
STATISTIC(NumFunctions,"Total number of functions")
MemDepResult getInvariantGroupPointerDependency(LoadInst *LI, BasicBlock *BB)
This analysis looks for other loads and stores with invariant.group metadata and the same pointer ope...
An instruction for ordering other memory operations.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
This class provides various memory handling functions that manipulate MemoryBlock instances...
The two locations alias, but only due to a partial overlap.
This class represents a function call, abstracting a target machine's calling convention.
static bool isOrdered(const Instruction *I)
An immutable pass that tracks lazily created AssumptionCache objects.
bool onlyReadsMemory(ImmutableCallSite CS)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
const Function * getParent() const
Return the enclosing method, or null if none.
The two locations do not alias at all.
Analysis pass which computes a DominatorTree.
An instruction for reading from memory.
bool isUnknown() const
Tests if this MemDepResult represents a query which cannot and/or will not be computed.
The access modifies the value stored in memory.
bool isClobber() const
Tests if this MemDepResult represents a query that is an instruction clobber dependency.
MemoryLocation getWithNewSize(uint64_t NewSize) const
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
iterator begin()
Instruction iterator methods.
static cl::opt< unsigned > BlockScanLimit("memdep-block-scan-limit", cl::Hidden, cl::init(100), cl::desc("The number of instructions to scan in a block in memory ""dependency analysis (default = 100)"))
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
AnalysisUsage & addRequired()
ArrayRef< BasicBlock * > get(BasicBlock *BB)
#define INITIALIZE_PASS_DEPENDENCY(depName)
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
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...
A Use represents the edge between a Value definition and its users.
static unsigned getLoadLoadClobberFullWidthSize(const Value *MemLocBase, int64_t MemLocOffs, unsigned MemLocSize, const LoadInst *LI)
Looks at a memory location for a load (specified by MemLocBase, Offs, and Size) and compares it again...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
void getNonLocalPointerDependency(Instruction *QueryInst, SmallVectorImpl< NonLocalDepResult > &Result)
Perform a full dependency query for an access to the QueryInst's specified memory location...
static MemDepResult getDef(Instruction *Inst)
get methods: These are static ctor methods for creating various MemDepResult kinds.
MemoryLocation getWithNewPtr(const Value *NewPtr) const
An analysis that produces MemoryDependenceResults for a function.
The access references the value stored in memory.
std::vector< NonLocalDepEntry > NonLocalDepInfo
LLVM_NODISCARD bool empty() const
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
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
Return true if this instruction may read memory.
PointerTy getPointer() const
static void RemoveFromReverseMap(DenseMap< Instruction *, SmallPtrSet< KeyTy, 4 >> &ReverseMap, Instruction *Inst, KeyTy Val)
This is a helper function that removes Val from 'Inst's set in ReverseMap.
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL)
Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset...
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
An instruction for storing to memory.
~MemoryDependenceWrapperPass() override
iterator find(const_arg_type_t< KeyT > Val)
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal=false)
Checks whether the given location points to constant memory, or if OrLocal is true whether it points ...
static MemDepResult getUnknown()
The access neither references nor modifies the value stored in memory.
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
initializer< Ty > init(const Ty &Val)
bool erase(const KeyT &Val)
const NonLocalDepInfo & getNonLocalCallDependency(CallSite QueryCS)
Perform a full dependency query for the specified call, returning the set of blocks that the value is...
A set of analyses that are preserved following a run of a transformation pass.
bool isIdenticalToWhenDefined(const Instruction *I) const
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags, which may specify conditions under which the instruction's result is undefined.
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
INITIALIZE_PASS_BEGIN(MemoryDependenceWrapperPass,"memdep","Memory Dependence Analysis", false, true) INITIALIZE_PASS_END(MemoryDependenceWrapperPass
A manager for alias analyses.
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.
MemDepResult getSimplePointerDependencyFrom(const MemoryLocation &MemLoc, bool isLoad, BasicBlock::iterator ScanIt, BasicBlock *BB, Instruction *QueryInst, unsigned *Limit=nullptr)
AliasResult
The possible results of an alias query.
Represent the analysis usage information of a pass.
static MemDepResult getNonFuncLocal()
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
FunctionPass class - This class is used to implement most global optimizations.
Value * getPointerOperand()
const MemDepResult & getResult() const
self_iterator getIterator()
void setResult(const MemDepResult &R)
bool isPointerTy() const
True if this is an instance of PointerType.
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
static void SortNonLocalDepInfoCache(MemoryDependenceResults::NonLocalDepInfo &Cache, unsigned NumSortedEntries)
Sort the NonLocalDepInfo cache, given a certain number of elements in the array that are already prop...
A wrapper analysis pass for the legacy pass manager that exposes a MemoryDepnedenceResults instance...
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
bool IsPotentiallyPHITranslatable() const
IsPotentiallyPHITranslatable - If this needs PHI translation, return true if we have some hope of doi...
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
A memory dependence query can return one of three different answers.
unsigned getDefaultBlockScanLimit() const
Some methods limit the number of instructions they will examine.
void clear()
clear - Remove all information.
bool isTerminator() const
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
const Value * Ptr
The address of the start of the location.
Representation for a specific memory location.
A function analysis which provides an AssumptionCache.
MemDepResult getPointerDependencyFrom(const MemoryLocation &Loc, bool isLoad, BasicBlock::iterator ScanIt, BasicBlock *BB, Instruction *QueryInst=nullptr, unsigned *Limit=nullptr)
Returns the instruction on which a memory location depends.
Iterator for intrusive lists based on ilist_node.
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...
InstrTy * getInstruction() const
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.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
static bool isReadOnly(const GlobalValue *GV)
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
static MemDepResult getClobber(Instruction *Inst)
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
MemoryDependenceResults run(Function &F, FunctionAnalysisManager &AM)
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
LLVM_NODISCARD T pop_back_val()
bool isNonLocal() const
Tests if this MemDepResult represents a query that is transparent to the start of the block...
void getAnalysisUsage(AnalysisUsage &AU) const override
Does not modify anything. It uses Value Numbering and Alias Analysis.
const BasicBlock & getEntryBlock() const
Target - Wrapper for Target specific information.
void releaseMemory() override
Clean up memory in between runs.
ModRefInfo callCapturesBefore(const Instruction *I, const MemoryLocation &MemLoc, DominatorTree *DT, OrderedBasicBlock *OBB=nullptr)
Return information about whether a particular call site modifies or reads the specified memory locati...
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
void setPreservesAll()
Set by analyses that do not transform their input at all.
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are must-alias.
bool runOnFunction(Function &) override
Pass Implementation stuff. This doesn't do any analysis eagerly.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
static bool isStrongerThanUnordered(AtomicOrdering ao)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Instruction * getInst() const
If this is a normal dependency, returns the instruction that is depended on.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
AAMDNodes AATags
The metadata nodes which describes the aliasing of the location (each member is null if that kind of ...
static ModRefInfo GetLocation(const Instruction *Inst, MemoryLocation &Loc, const TargetLibraryInfo &TLI)
If the given instruction references a specific memory location, fill in Loc with the details...
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
void initializeMemoryDependenceWrapperPassPass(PassRegistry &)
unsigned getAlignment() const
Return the alignment of the access that is being performed.
DenseMapIterator< ValueIsLoadPair, NonLocalPointerInfo, DenseMapInfo< ValueIsLoadPair >, detail::DenseMapPair< ValueIsLoadPair, NonLocalPointerInfo > > iterator
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation in the new PM.
The access both references and modifies the value stored in memory.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
AnalysisUsage & addRequiredTransitive()
Memory Dependence Analysis
LLVM_NODISCARD bool empty() const
API to communicate dependencies between analyses during invalidation.
Analysis pass providing the TargetLibraryInfo.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This templated class represents "all analyses that operate over \<a particular IR unit\>" (e...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
void removeInstruction(Instruction *InstToRemove)
Removes an instruction from the dependence analysis, updating the dependence of instructions that pre...
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
static cl::opt< unsigned > BlockNumberLimit("memdep-block-number-limit", cl::Hidden, cl::init(1000), cl::desc("The number of blocks to scan during memory ""dependency analysis (default = 1000)"))
This is an entry in the NonLocalDepInfo cache.
A container for analyses that lazily runs them and caches their results.
static void AssertSorted(MemoryDependenceResults::NonLocalDepInfo &Cache, int Count=-1)
This method is used when -debug is specified to verify that cache arrays are properly kept sorted...
Legacy analysis pass which computes a DominatorTree.
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
static bool isVolatile(Instruction *Inst)
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Trigger the invalidation of some other analysis pass if not already handled and return whether it was...
Dependence - This class represents a dependence between two memory memory references in a function...
static MemDepResult getNonLocal()
static const unsigned int NumResultsLimit
A special type used by analysis passes to provide an address that identifies that particular analysis...
const BasicBlock * getParent() const
A 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...
MemDepResult getDependency(Instruction *QueryInst)
Returns the instruction on which a memory operation depends.