67 #define DEBUG_TYPE "memdep" 69 STATISTIC(NumCacheNonLocal,
"Number of fully cached non-local responses");
70 STATISTIC(NumCacheDirtyNonLocal,
"Number of dirty cached non-local responses");
71 STATISTIC(NumUncacheNonLocal,
"Number of uncached non-local responses");
74 "Number of fully cached non-local ptr responses");
76 "Number of cached, but dirty, non-local ptr responses");
77 STATISTIC(NumUncacheNonLocalPtr,
"Number of uncached non-local ptr responses");
79 "Number of block queries that were completely cached");
85 cl::desc(
"The number of instructions to scan in a block in memory " 86 "dependency analysis (default = 100)"));
90 cl::desc(
"The number of blocks to scan during memory " 91 "dependency analysis (default = 1000)"));
99 template <
typename KeyTy>
104 ReverseMap.
find(Inst);
105 assert(InstIt != ReverseMap.
end() &&
"Reverse map out of sync?");
106 bool Found = InstIt->second.
erase(Val);
107 assert(Found &&
"Invalid reverse map!");
109 if (InstIt->second.
empty())
110 ReverseMap.erase(InstIt);
120 if (
const LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
121 if (LI->isUnordered()) {
133 if (
const StoreInst *
SI = dyn_cast<StoreInst>(Inst)) {
134 if (
SI->isUnordered()) {
146 if (
const VAArgInst *V = dyn_cast<VAArgInst>(Inst)) {
157 if (
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
158 switch (II->getIntrinsicID()) {
159 case Intrinsic::lifetime_start:
160 case Intrinsic::lifetime_end:
161 case Intrinsic::invariant_start:
166 case Intrinsic::invariant_end:
185 MemDepResult MemoryDependenceResults::getCallSiteDependencyFrom(
191 while (ScanIt != BB->
begin()) {
194 if (isa<DbgInfoIntrinsic>(Inst))
218 if (isReadOnlyCall && !
isModSet(MR) &&
243 const Value *MemLocBase, int64_t MemLocOffs,
unsigned MemLocSize,
258 const Value *LIBase =
263 if (LIBase != MemLocBase)
273 if (MemLocOffs < LIOffs)
283 int64_t MemLocEnd = MemLocOffs + MemLocSize;
286 if (LIOffs + LoadAlign < MemLocEnd)
297 if (NewLoadByteSize > LoadAlign ||
301 if (LIOffs + NewLoadByteSize > MemLocEnd &&
303 Attribute::SanitizeAddress) ||
305 Attribute::SanitizeHWAddress)))
312 if (LIOffs + NewLoadByteSize >= MemLocEnd)
313 return NewLoadByteSize;
315 NewLoadByteSize <<= 1;
320 if (
auto *LI = dyn_cast<LoadInst>(Inst))
321 return LI->isVolatile();
322 if (
auto *
SI = dyn_cast<StoreInst>(Inst))
323 return SI->isVolatile();
324 if (
auto *AI = dyn_cast<AtomicCmpXchgInst>(Inst))
325 return AI->isVolatile();
333 if (QueryInst !=
nullptr) {
334 if (
auto *LI = dyn_cast<LoadInst>(QueryInst)) {
337 if (InvariantGroupDependency.
isDef())
338 return InvariantGroupDependency;
342 MemLoc, isLoad, ScanIt, BB, QueryInst, Limit);
343 if (SimpleDep.
isDef())
349 return InvariantGroupDependency;
352 "InvariantGroupDependency should be only unknown at this point");
371 if (isa<GlobalValue>(LoadOperand))
376 LoadOperandsQueue.
push_back(LoadOperand);
382 assert(
Other &&
"Must call it with not null instruction");
390 while (!LoadOperandsQueue.
empty()) {
392 assert(Ptr && !isa<GlobalValue>(Ptr) &&
393 "Null or GlobalValue should not be inserted");
395 for (
const Use &Us : Ptr->
uses()) {
397 if (!U || U == LI || !DT.
dominates(U, LI))
402 if (isa<BitCastInst>(U)) {
411 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(U))
412 if (
GEP->hasAllZeroIndices()) {
420 if ((isa<LoadInst>(U) || isa<StoreInst>(U)) &&
422 ClosestDependency = GetClosestDependency(ClosestDependency, U);
426 if (!ClosestDependency)
428 if (ClosestDependency->
getParent() == BB)
434 NonLocalDefsCache.try_emplace(
437 ReverseNonLocalDefsCache[ClosestDependency].
insert(LI);
444 bool isInvariantLoad =
false;
484 if (isLoad && QueryInst) {
487 isInvariantLoad =
true;
500 auto isNonSimpleLoadOrStore = [](
Instruction *
I) ->
bool {
501 if (
auto *LI = dyn_cast<LoadInst>(
I))
502 return !LI->isSimple();
503 if (
auto *
SI = dyn_cast<StoreInst>(
I))
504 return !
SI->isSimple();
511 return !isa<LoadInst>(
I) && !isa<StoreInst>(
I) &&
I->mayReadOrWriteMemory();
515 while (ScanIt != BB->
begin()) {
520 if (isa<DbgInfoIntrinsic>(II))
532 if (II->getIntrinsicID() == Intrinsic::lifetime_start) {
548 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
552 if (LI->isVolatile()) {
567 if (!QueryInst || isNonSimpleLoadOrStore(QueryInst) ||
568 isOtherMemAccess(QueryInst))
587 #if 0 // FIXME: Temporarily disabled. GVN is cleverly rewriting loads 619 if (!
SI->isUnordered() &&
SI->isAtomic()) {
620 if (!QueryInst || isNonSimpleLoadOrStore(QueryInst) ||
621 isOtherMemAccess(QueryInst))
631 if (
SI->isVolatile())
632 if (!QueryInst || isNonSimpleLoadOrStore(QueryInst) ||
633 isOtherMemAccess(QueryInst))
665 if (isa<AllocaInst>(Inst) ||
isNoAliasFn(Inst, &TLI)) {
667 if (AccessPtr == Inst || AA.
isMustAlias(Inst, AccessPtr))
679 if (
FenceInst *FI = dyn_cast<FenceInst>(Inst))
721 if (!LocalCache.isDirty())
748 if (
auto *II = dyn_cast<IntrinsicInst>(QueryInst))
749 isLoad |= II->getIntrinsicID() == Intrinsic::lifetime_start;
752 MemLoc, isLoad, ScanPos->
getIterator(), QueryParent, QueryInst);
753 }
else if (isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)) {
756 LocalCache = getCallSiteDependencyFrom(
757 QueryCS, isReadOnly, ScanPos->
getIterator(), QueryParent);
765 ReverseLocalDeps[
I].insert(QueryInst);
776 Count = Cache.size();
777 assert(std::is_sorted(Cache.begin(), Cache.begin() + Count) &&
778 "Cache isn't sorted!");
785 "getNonLocalCallDependency should only be used on calls with " 795 if (!Cache.empty()) {
798 if (!CacheP.second) {
805 for (
auto &Entry : Cache)
806 if (Entry.getResult().isDirty())
812 ++NumCacheDirtyNonLocal;
820 ++NumUncacheNonLocal;
828 unsigned NumSortedEntries = Cache.
size();
832 while (!DirtyBlocks.
empty()) {
837 if (!Visited.
insert(DirtyBB).second)
843 NonLocalDepInfo::iterator Entry =
844 std::upper_bound(Cache.begin(), Cache.begin() + NumSortedEntries,
846 if (Entry != Cache.begin() && std::prev(Entry)->getBB() == DirtyBB)
850 if (Entry != Cache.begin() + NumSortedEntries &&
851 Entry->getBB() == DirtyBB) {
854 if (!Entry->getResult().isDirty())
858 ExistingResult = &*Entry;
864 if (ExistingResult) {
866 ScanPos = Inst->getIterator();
876 if (ScanPos != DirtyBB->
begin()) {
878 getCallSiteDependencyFrom(QueryCS, isReadonlyCall, ScanPos, DirtyBB);
896 if (!Dep.isNonLocal()) {
916 bool isLoad = isa<LoadInst>(QueryInst);
921 "Can't get pointer deps of a non-pointer!");
925 auto NonLocalDefIt = NonLocalDefsCache.find(QueryInst);
926 if (NonLocalDefIt != NonLocalDefsCache.end()) {
928 ReverseNonLocalDefsCache[NonLocalDefIt->second.getResult().getInst()]
930 NonLocalDefsCache.erase(NonLocalDefIt);
943 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
944 return !LI->isUnordered();
945 }
else if (
StoreInst *
SI = dyn_cast<StoreInst>(Inst)) {
946 return !
SI->isUnordered();
952 const_cast<Value *>(Loc.
Ptr)));
955 const DataLayout &DL = FromBB->getModule()->getDataLayout();
963 if (getNonLocalPointerDepFromBB(QueryInst, Address, Loc, isLoad, FromBB,
964 Result, Visited,
true))
968 const_cast<Value *>(Loc.
Ptr)));
976 MemDepResult MemoryDependenceResults::GetNonLocalInfoForBlock(
982 NonLocalDepInfo::iterator Entry = std::upper_bound(
984 if (Entry != Cache->begin() && (Entry - 1)->getBB() == BB)
988 if (Entry != Cache->begin() + NumSortedEntries && Entry->getBB() == BB)
989 ExistingResult = &*Entry;
993 if (ExistingResult && !ExistingResult->
getResult().isDirty()) {
994 ++NumCacheNonLocalPtr;
1004 "Instruction invalidated?");
1005 ++NumCacheDirtyNonLocalPtr;
1012 ++NumUncacheNonLocalPtr;
1035 assert(Inst &&
"Didn't depend on anything?");
1037 ReverseNonLocalPtrDeps[Inst].
insert(CacheKey);
1047 unsigned NumSortedEntries) {
1048 switch (Cache.size() - NumSortedEntries) {
1056 MemoryDependenceResults::NonLocalDepInfo::iterator Entry =
1057 std::upper_bound(Cache.begin(), Cache.end() - 1, Val);
1058 Cache.insert(Entry, Val);
1063 if (Cache.size() != 1) {
1066 MemoryDependenceResults::NonLocalDepInfo::iterator Entry =
1067 std::upper_bound(Cache.begin(), Cache.end(), Val);
1068 Cache.insert(Entry, Val);
1091 bool MemoryDependenceResults::getNonLocalPointerDepFromBB(
1103 NonLocalPointerInfo InitialNLPI;
1104 InitialNLPI.Size = Loc.
Size;
1105 InitialNLPI.AATags = Loc.
AATags;
1109 std::pair<CachedNonLocalPointerInfo::iterator, bool> Pair =
1110 NonLocalPointerDeps.
insert(std::make_pair(CacheKey, InitialNLPI));
1111 NonLocalPointerInfo *CacheInfo = &Pair.first->second;
1116 if (CacheInfo->Size < Loc.
Size) {
1119 CacheInfo->Pair = BBSkipFirstBlockPair();
1120 CacheInfo->Size = Loc.
Size;
1121 for (
auto &Entry : CacheInfo->NonLocalDeps)
1122 if (
Instruction *Inst = Entry.getResult().getInst())
1124 CacheInfo->NonLocalDeps.clear();
1125 }
else if (CacheInfo->Size > Loc.
Size) {
1128 return getNonLocalPointerDepFromBB(
1130 StartBB, Result, Visited, SkipFirstBlock);
1136 if (CacheInfo->AATags != Loc.
AATags) {
1137 if (CacheInfo->AATags) {
1138 CacheInfo->Pair = BBSkipFirstBlockPair();
1140 for (
auto &Entry : CacheInfo->NonLocalDeps)
1141 if (
Instruction *Inst = Entry.getResult().getInst())
1143 CacheInfo->NonLocalDeps.clear();
1146 return getNonLocalPointerDepFromBB(
1148 Visited, SkipFirstBlock);
1156 if (CacheInfo->Pair == BBSkipFirstBlockPair(StartBB, SkipFirstBlock)) {
1162 if (!Visited.
empty()) {
1163 for (
auto &Entry : *Cache) {
1165 Visited.
find(Entry.getBB());
1166 if (VI == Visited.
end() || VI->second == Pointer.
getAddr())
1177 for (
auto &Entry : *Cache) {
1178 Visited.
insert(std::make_pair(Entry.getBB(), Addr));
1179 if (Entry.getResult().isNonLocal()) {
1188 ++NumCacheCompleteNonLocalPtr;
1197 CacheInfo->Pair = BBSkipFirstBlockPair(StartBB, SkipFirstBlock);
1199 CacheInfo->Pair = BBSkipFirstBlockPair();
1212 unsigned NumSortedEntries = Cache->size();
1214 bool GotWorklistLimit =
false;
1217 while (!Worklist.
empty()) {
1227 if (Cache && NumSortedEntries != Cache->size()) {
1234 CacheInfo->Pair = BBSkipFirstBlockPair();
1239 if (!SkipFirstBlock) {
1242 assert(Visited.
count(BB) &&
"Should check 'visited' before adding to WL");
1247 MemDepResult Dep = GetNonLocalInfoForBlock(QueryInst, Loc, isLoad, BB,
1248 Cache, NumSortedEntries);
1264 SkipFirstBlock =
false;
1268 std::pair<DenseMap<BasicBlock *, Value *>::iterator,
bool> InsertRes =
1270 if (InsertRes.second) {
1279 if (InsertRes.first->second != Pointer.
getAddr()) {
1282 for (
unsigned i = 0; i < NewBlocks.
size(); i++)
1283 Visited.
erase(NewBlocks[i]);
1284 goto PredTranslationFailure;
1287 if (NewBlocks.
size() > WorklistEntries) {
1290 for (
unsigned i = 0; i < NewBlocks.
size(); i++)
1291 Visited.
erase(NewBlocks[i]);
1292 GotWorklistLimit =
true;
1293 goto PredTranslationFailure;
1295 WorklistEntries -= NewBlocks.
size();
1303 goto PredTranslationFailure;
1310 if (Cache && NumSortedEntries != Cache->size()) {
1312 NumSortedEntries = Cache->size();
1318 PredList.
push_back(std::make_pair(Pred, Pointer));
1331 std::pair<DenseMap<BasicBlock *, Value *>::iterator,
bool> InsertRes =
1332 Visited.
insert(std::make_pair(Pred, PredPtrVal));
1334 if (!InsertRes.second) {
1340 if (InsertRes.first->second == PredPtrVal)
1349 for (
unsigned i = 0, n = PredList.
size(); i < n; ++i)
1350 Visited.
erase(PredList[i].first);
1352 goto PredTranslationFailure;
1361 for (
unsigned i = 0, n = PredList.
size(); i < n; ++i) {
1366 bool CanTranslate =
true;
1372 CanTranslate =
false;
1382 if (!CanTranslate ||
1383 !getNonLocalPointerDepFromBB(QueryInst, PredPointer,
1385 Pred, Result, Visited)) {
1388 Result.push_back(Entry);
1395 NonLocalPointerInfo &NLPI = NonLocalPointerDeps[CacheKey];
1396 NLPI.Pair = BBSkipFirstBlockPair();
1402 CacheInfo = &NonLocalPointerDeps[CacheKey];
1403 Cache = &CacheInfo->NonLocalDeps;
1404 NumSortedEntries = Cache->size();
1410 CacheInfo->Pair = BBSkipFirstBlockPair();
1411 SkipFirstBlock =
false;
1414 PredTranslationFailure:
1421 CacheInfo = &NonLocalPointerDeps[CacheKey];
1422 Cache = &CacheInfo->NonLocalDeps;
1423 NumSortedEntries = Cache->size();
1430 CacheInfo->Pair = BBSkipFirstBlockPair();
1440 bool foundBlock =
false;
1442 if (
I.getBB() != BB)
1445 assert((GotWorklistLimit ||
I.getResult().isNonLocal() ||
1447 "Should only be here with transparent block");
1454 (void)foundBlock; (void)GotWorklistLimit;
1455 assert((foundBlock || GotWorklistLimit) &&
"Current block not in cache?");
1465 void MemoryDependenceResults::RemoveCachedNonLocalPointerDependencies(
1466 ValueIsLoadPair
P) {
1469 if (!NonLocalDefsCache.empty()) {
1470 auto it = NonLocalDefsCache.find(P.getPointer());
1471 if (it != NonLocalDefsCache.end()) {
1473 it->second.getResult().getInst(), P.getPointer());
1474 NonLocalDefsCache.erase(it);
1477 if (
auto *
I = dyn_cast<Instruction>(P.getPointer())) {
1478 auto toRemoveIt = ReverseNonLocalDefsCache.
find(
I);
1479 if (toRemoveIt != ReverseNonLocalDefsCache.
end()) {
1480 for (
const auto &
entry : toRemoveIt->second)
1481 NonLocalDefsCache.erase(
entry);
1482 ReverseNonLocalDefsCache.
erase(toRemoveIt);
1488 if (It == NonLocalPointerDeps.
end())
1495 for (
unsigned i = 0, e = PInfo.size(); i != e; ++i) {
1506 NonLocalPointerDeps.
erase(It);
1529 if (NLDI != NonLocalDeps.
end()) {
1531 for (
auto &Entry : BlockMap)
1532 if (
Instruction *Inst = Entry.getResult().getInst())
1534 NonLocalDeps.
erase(NLDI);
1539 if (LocalDepEntry != LocalDeps.
end()) {
1541 if (
Instruction *Inst = LocalDepEntry->second.getInst())
1545 LocalDeps.
erase(LocalDepEntry);
1555 RemoveCachedNonLocalPointerDependencies(
ValueIsLoadPair(RemInst,
false));
1556 RemoveCachedNonLocalPointerDependencies(
ValueIsLoadPair(RemInst,
true));
1570 NewDirtyVal = MemDepResult::getDirty(&*++RemInst->
getIterator());
1573 if (ReverseDepIt != ReverseLocalDeps.
end()) {
1575 assert(!ReverseDepIt->second.empty() && !isa<TerminatorInst>(RemInst) &&
1576 "Nothing can locally depend on a terminator");
1578 for (
Instruction *InstDependingOnRemInst : ReverseDepIt->second) {
1579 assert(InstDependingOnRemInst != RemInst &&
1580 "Already removed our local dep info");
1582 LocalDeps[InstDependingOnRemInst] = NewDirtyVal;
1586 "There is no way something else can have " 1587 "a local dep on this if it is a terminator!");
1589 std::make_pair(NewDirtyVal.
getInst(), InstDependingOnRemInst));
1592 ReverseLocalDeps.
erase(ReverseDepIt);
1596 while (!ReverseDepsToAdd.
empty()) {
1597 ReverseLocalDeps[ReverseDepsToAdd.
back().first].
insert(
1598 ReverseDepsToAdd.
back().second);
1603 ReverseDepIt = ReverseNonLocalDeps.
find(RemInst);
1604 if (ReverseDepIt != ReverseNonLocalDeps.
end()) {
1606 assert(I != RemInst &&
"Already removed NonLocalDep info for RemInst");
1608 PerInstNLInfo &INLD = NonLocalDeps[
I];
1612 for (
auto &Entry : INLD.first) {
1613 if (Entry.getResult().getInst() != RemInst)
1617 Entry.setResult(NewDirtyVal);
1620 ReverseDepsToAdd.
push_back(std::make_pair(NextI, I));
1624 ReverseNonLocalDeps.
erase(ReverseDepIt);
1627 while (!ReverseDepsToAdd.
empty()) {
1628 ReverseNonLocalDeps[ReverseDepsToAdd.
back().first].
insert(
1629 ReverseDepsToAdd.
back().second);
1637 ReverseNonLocalPtrDeps.
find(RemInst);
1638 if (ReversePtrDepIt != ReverseNonLocalPtrDeps.
end()) {
1640 ReversePtrDepsToAdd;
1644 "Already removed NonLocalPointerDeps info for RemInst");
1652 for (
auto &Entry : NLPDI) {
1653 if (Entry.getResult().getInst() != RemInst)
1657 Entry.setResult(NewDirtyVal);
1660 ReversePtrDepsToAdd.
push_back(std::make_pair(NewDirtyInst, P));
1668 ReverseNonLocalPtrDeps.
erase(ReversePtrDepIt);
1670 while (!ReversePtrDepsToAdd.
empty()) {
1671 ReverseNonLocalPtrDeps[ReversePtrDepsToAdd.
back().first].
insert(
1672 ReversePtrDepsToAdd.
back().second);
1680 assert(!NonLocalDeps.
count(RemInst) &&
"RemInst got reinserted?");
1688 void MemoryDependenceResults::verifyRemoved(
Instruction *
D)
const {
1690 for (
const auto &DepKV : LocalDeps) {
1691 assert(DepKV.first != D &&
"Inst occurs in data structures");
1692 assert(DepKV.second.getInst() != D &&
"Inst occurs in data structures");
1695 for (
const auto &DepKV : NonLocalPointerDeps) {
1696 assert(DepKV.first.getPointer() != D &&
"Inst occurs in NLPD map key");
1697 for (
const auto &Entry : DepKV.second.NonLocalDeps)
1698 assert(Entry.getResult().getInst() != D &&
"Inst occurs as NLPD value");
1701 for (
const auto &DepKV : NonLocalDeps) {
1702 assert(DepKV.first != D &&
"Inst occurs in data structures");
1703 const PerInstNLInfo &INLD = DepKV.second;
1704 for (
const auto &Entry : INLD.first)
1705 assert(Entry.getResult().getInst() != D &&
1706 "Inst occurs in data structures");
1709 for (
const auto &DepKV : ReverseLocalDeps) {
1710 assert(DepKV.first != D &&
"Inst occurs in data structures");
1712 assert(Inst != D &&
"Inst occurs in data structures");
1715 for (
const auto &DepKV : ReverseNonLocalDeps) {
1716 assert(DepKV.first != D &&
"Inst occurs in data structures");
1718 assert(Inst != D &&
"Inst occurs in data structures");
1721 for (
const auto &DepKV : ReverseNonLocalPtrDeps) {
1722 assert(DepKV.first != D &&
"Inst occurs in rev NLPD map");
1726 "Inst occurs in ReverseNonLocalPtrDeps map");
1746 "Memory Dependence Analysis",
false,
true)
1798 auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
1799 auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
1800 auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
1801 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
1802 auto &PV = getAnalysis<PhiValuesWrapperPass>().getResult();
1803 MemDep.emplace(AA, AC, TLI, DT, PV);
The access may reference and may modify the value stored in memory.
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.
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Trigger the invalidation of some other analysis pass if not already handled and return whether it was...
iterator_range< use_iterator > uses()
The access neither references nor modifies the value stored in memory.
bool isStrongerThanUnordered(AtomicOrdering ao)
Provides a lazy, caching interface for making common memory aliasing information queries, backed by LLVM's alias analysis passes.
LLVM_NODISCARD ModRefInfo clearMust(const ModRefInfo MRI)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Atomic ordering constants.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Compute iterated dominance frontiers using a linear time algorithm.
PointerTy getPointer() const
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.
MemoryLocation getWithNewPtr(const Value *NewPtr) const
This class provides various memory handling functions that manipulate MemoryBlock instances...
This class represents a function call, abstracting a target machine's calling convention.
bool isNonLocal() const
Tests if this MemDepResult represents a query that is transparent to the start of the block...
An immutable pass that tracks lazily created AssumptionCache objects.
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)"))
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
The two locations do not alias at all.
bool onlyReadsMemory(ImmutableCallSite CS)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
bool isTerminator() const
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
STATISTIC(NumFunctions, "Total number of functions")
Analysis pass which computes a DominatorTree.
block Block Frequency true
An instruction for reading from memory.
This defines the Use class.
LLVM_NODISCARD bool isModAndRefSet(const ModRefInfo MRI)
The analysis pass which yields a PhiValues.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
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.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
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()
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
ArrayRef< BasicBlock * > get(BasicBlock *BB)
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool isDef() const
Tests if this MemDepResult represents a query that is an instruction definition dependency.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isClobber() const
Tests if this MemDepResult represents a query that is an instruction clobber dependency.
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...
static bool isLoad(int Opcode)
unsigned getDefaultBlockScanLimit() const
Some methods limit the number of instructions they will examine.
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.
The access may reference the value stored in memory.
This file contains the simple types necessary to represent the attributes associated with functions a...
InstrTy * getInstruction() const
An analysis that produces MemoryDependenceResults for a function.
MemoryDependenceResults(AliasAnalysis &AA, AssumptionCache &AC, const TargetLibraryInfo &TLI, DominatorTree &DT, PhiValues &PV)
static bool isOrdered(const Instruction *I)
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...
Type * getType() const
All values are typed, get the type of this value.
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...
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
An instruction for storing to memory.
Wrapper pass for the legacy pass manager.
~MemoryDependenceWrapperPass() override
AliasResult
The possible results of an alias query.
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()
const BasicBlock & getEntryBlock() const
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.
MemoryLocation getWithoutAATags() const
MemoryLocation getWithNewSize(LocationSize NewSize) const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
void invalidateValue(const Value *V)
Notify PhiValues that the cached information using V is no longer valid.
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)
Represent the analysis usage information of a pass.
static MemDepResult getNonFuncLocal()
FunctionPass class - This class is used to implement most global optimizations.
LocationSize Size
The maximum size of the location, in address-units, or UnknownSize if the size is not known...
Value * getPointerOperand()
self_iterator getIterator()
void setResult(const MemDepResult &R)
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
INITIALIZE_PASS_BEGIN(MemoryDependenceWrapperPass, "memdep", "Memory Dependence Analysis", false, true) INITIALIZE_PASS_END(MemoryDependenceWrapperPass
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...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
static MemoryLocation getForArgument(ImmutableCallSite CS, unsigned ArgIdx, const TargetLibraryInfo &TLI)
Return a location representing a particular argument of a call.
A memory dependence query can return one of three different answers.
void sort(IteratorTy Start, IteratorTy End)
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)"))
void clear()
clear - Remove all information.
const Value * Ptr
The address of the start of the location.
Representation for a specific memory location.
A function analysis which provides an AssumptionCache.
The two locations precisely alias each other.
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 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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
Module.h This file contains the declarations for the Module class.
Provides information about what library functions are available for the current target.
static MemDepResult getClobber(Instruction *Inst)
MemoryDependenceResults run(Function &F, FunctionAnalysisManager &AM)
const MemDepResult & getResult() const
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
LLVM_NODISCARD T pop_back_val()
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
void getAnalysisUsage(AnalysisUsage &AU) const override
Does not modify anything. It uses Value Numbering and Alias Analysis.
The access may modify the value stored in memory.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Target - Wrapper for Target specific information.
void releaseMemory() override
Clean up memory in between runs.
bool NeedsPHITranslationFromBlock(BasicBlock *BB) const
NeedsPHITranslationFromBlock - Return true if moving from the specified BasicBlock to its predecessor...
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.
LLVM_NODISCARD bool isNoModRef(const ModRefInfo MRI)
InstListType::iterator iterator
Instruction iterators...
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are must-alias.
std::vector< NonLocalDepEntry > NonLocalDepInfo
bool runOnFunction(Function &) override
Pass Implementation stuff. This doesn't do any analysis eagerly.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
LLVM_NODISCARD bool isModSet(const ModRefInfo MRI)
bool isUnknown() const
Tests if this MemDepResult represents a query which cannot and/or will not be computed.
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...
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Instruction * getInst() const
If this is a normal dependency, returns the instruction that is depended on.
void initializeMemoryDependenceWrapperPassPass(PassRegistry &)
LLVM_NODISCARD bool empty() const
DenseMapIterator< ValueIsLoadPair, NonLocalPointerInfo, DenseMapInfo< ValueIsLoadPair >, detail::DenseMapPair< ValueIsLoadPair, NonLocalPointerInfo > > iterator
This file provides utility analysis objects describing memory locations.
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation in the new PM.
const Function * getParent() const
Return the enclosing method, or null if none.
bool mayReadFromMemory() const
Return true if this instruction may read memory.
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()
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
LLVM_NODISCARD bool empty() const
bool IsPotentiallyPHITranslatable() const
IsPotentiallyPHITranslatable - If this needs PHI translation, return true if we have some hope of doi...
Memory Dependence Analysis
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...
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
print Instructions which execute on loop entry
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
This is an entry in the NonLocalDepInfo cache.
A container for analyses that lazily runs them and caches their results.
bool fitsInLegalInteger(unsigned Width) const
Returns true if the specified type fits in a native integer type supported by the CPU...
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.
LLVM_NODISCARD bool isModOrRefSet(const ModRefInfo MRI)
static bool isVolatile(Instruction *Inst)
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
The two locations alias, but only due to a partial overlap.
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...
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
MemDepResult getDependency(Instruction *QueryInst)
Returns the instruction on which a memory operation depends.