66 #define DEBUG_TYPE "memdep" 68 STATISTIC(NumCacheNonLocal,
"Number of fully cached non-local responses");
69 STATISTIC(NumCacheDirtyNonLocal,
"Number of dirty cached non-local responses");
70 STATISTIC(NumUncacheNonLocal,
"Number of uncached non-local responses");
73 "Number of fully cached non-local ptr responses");
75 "Number of cached, but dirty, non-local ptr responses");
76 STATISTIC(NumUncacheNonLocalPtr,
"Number of uncached non-local ptr responses");
78 "Number of block queries that were completely cached");
84 cl::desc(
"The number of instructions to scan in a block in memory " 85 "dependency analysis (default = 100)"));
89 cl::desc(
"The number of blocks to scan during memory " 90 "dependency analysis (default = 1000)"));
98 template <
typename KeyTy>
103 ReverseMap.
find(Inst);
104 assert(InstIt != ReverseMap.
end() &&
"Reverse map out of sync?");
105 bool Found = InstIt->second.
erase(Val);
106 assert(Found &&
"Invalid reverse map!");
108 if (InstIt->second.
empty())
109 ReverseMap.erase(InstIt);
119 if (
const LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
120 if (LI->isUnordered()) {
132 if (
const StoreInst *
SI = dyn_cast<StoreInst>(Inst)) {
133 if (
SI->isUnordered()) {
145 if (
const VAArgInst *V = dyn_cast<VAArgInst>(Inst)) {
156 if (
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
157 switch (II->getIntrinsicID()) {
158 case Intrinsic::lifetime_start:
159 case Intrinsic::lifetime_end:
160 case Intrinsic::invariant_start:
165 case Intrinsic::invariant_end:
184 MemDepResult MemoryDependenceResults::getCallDependencyFrom(
190 while (ScanIt != BB->
begin()) {
193 if (isa<DbgInfoIntrinsic>(Inst))
212 if (
auto *CallB = dyn_cast<CallBase>(Inst)) {
217 if (isReadOnlyCall && !
isModSet(MR) &&
242 const Value *MemLocBase, int64_t MemLocOffs,
unsigned MemLocSize,
257 const Value *LIBase =
262 if (LIBase != MemLocBase)
272 if (MemLocOffs < LIOffs)
282 int64_t MemLocEnd = MemLocOffs + MemLocSize;
285 if (LIOffs + LoadAlign < MemLocEnd)
296 if (NewLoadByteSize > LoadAlign ||
300 if (LIOffs + NewLoadByteSize > MemLocEnd &&
302 Attribute::SanitizeAddress) ||
304 Attribute::SanitizeHWAddress)))
311 if (LIOffs + NewLoadByteSize >= MemLocEnd)
312 return NewLoadByteSize;
314 NewLoadByteSize <<= 1;
319 if (
auto *LI = dyn_cast<LoadInst>(Inst))
320 return LI->isVolatile();
321 if (
auto *
SI = dyn_cast<StoreInst>(Inst))
322 return SI->isVolatile();
323 if (
auto *AI = dyn_cast<AtomicCmpXchgInst>(Inst))
324 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, OBB);
343 if (SimpleDep.
isDef())
349 return InvariantGroupDependency;
352 "InvariantGroupDependency should be only unknown at this point");
360 if (!LI->
hasMetadata(LLVMContext::MD_invariant_group))
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)) &&
421 U->hasMetadata(LLVMContext::MD_invariant_group))
422 ClosestDependency = GetClosestDependency(ClosestDependency, U);
426 if (!ClosestDependency)
428 if (ClosestDependency->
getParent() == BB)
434 NonLocalDefsCache.try_emplace(
437 ReverseNonLocalDefsCache[ClosestDependency].
insert(LI);
445 bool isInvariantLoad =
false;
449 Limit = &DefaultLimit;
483 if (isLoad && QueryInst) {
485 if (LI && LI->
hasMetadata(LLVMContext::MD_invariant_load))
486 isInvariantLoad =
true;
502 auto isNonSimpleLoadOrStore = [](
Instruction *
I) ->
bool {
503 if (
auto *LI = dyn_cast<LoadInst>(
I))
504 return !LI->isSimple();
505 if (
auto *
SI = dyn_cast<StoreInst>(
I))
506 return !
SI->isSimple();
513 return !isa<LoadInst>(
I) && !isa<StoreInst>(
I) &&
I->mayReadOrWriteMemory();
517 while (ScanIt != BB->
begin()) {
522 if (isa<DbgInfoIntrinsic>(II))
534 if (II->getIntrinsicID() == Intrinsic::lifetime_start) {
550 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
554 if (LI->isVolatile()) {
569 if (!QueryInst || isNonSimpleLoadOrStore(QueryInst) ||
570 isOtherMemAccess(QueryInst))
589 #if 0 // FIXME: Temporarily disabled. GVN is cleverly rewriting loads 621 if (!
SI->isUnordered() &&
SI->isAtomic()) {
622 if (!QueryInst || isNonSimpleLoadOrStore(QueryInst) ||
623 isOtherMemAccess(QueryInst))
633 if (
SI->isVolatile())
634 if (!QueryInst || isNonSimpleLoadOrStore(QueryInst) ||
635 isOtherMemAccess(QueryInst))
667 if (isa<AllocaInst>(Inst) ||
isNoAliasFn(Inst, &TLI)) {
669 if (AccessPtr == Inst || AA.
isMustAlias(Inst, AccessPtr))
681 if (
FenceInst *FI = dyn_cast<FenceInst>(Inst))
724 if (!LocalCache.isDirty())
751 if (
auto *II = dyn_cast<IntrinsicInst>(QueryInst))
752 isLoad |= II->getIntrinsicID() == Intrinsic::lifetime_start;
756 QueryParent, QueryInst,
nullptr, OBB);
757 }
else if (
auto *QueryCall = dyn_cast<CallBase>(QueryInst)) {
759 LocalCache = getCallDependencyFrom(QueryCall, isReadOnly,
768 ReverseLocalDeps[
I].insert(QueryInst);
779 Count = Cache.size();
780 assert(std::is_sorted(Cache.begin(), Cache.begin() + Count) &&
781 "Cache isn't sorted!");
788 "getNonLocalCallDependency should only be used on calls with " 790 PerInstNLInfo &CacheP = NonLocalDeps[QueryCall];
798 if (!Cache.empty()) {
801 if (!CacheP.second) {
808 for (
auto &
Entry : Cache)
809 if (
Entry.getResult().isDirty())
815 ++NumCacheDirtyNonLocal;
823 ++NumUncacheNonLocal;
831 unsigned NumSortedEntries = Cache.
size();
835 while (!DirtyBlocks.
empty()) {
840 if (!Visited.
insert(DirtyBB).second)
846 NonLocalDepInfo::iterator
Entry =
849 if (Entry != Cache.begin() && std::prev(Entry)->getBB() == DirtyBB)
853 if (Entry != Cache.begin() + NumSortedEntries &&
854 Entry->getBB() == DirtyBB) {
857 if (!Entry->getResult().isDirty())
861 ExistingResult = &*Entry;
867 if (ExistingResult) {
869 ScanPos = Inst->getIterator();
871 RemoveFromReverseMap<Instruction *>(ReverseNonLocalDeps, Inst,
879 if (ScanPos != DirtyBB->
begin()) {
880 Dep = getCallDependencyFrom(QueryCall, isReadonlyCall, ScanPos, DirtyBB);
898 if (!Dep.isNonLocal()) {
902 ReverseNonLocalDeps[Inst].insert(QueryCall);
918 bool isLoad = isa<LoadInst>(QueryInst);
923 "Can't get pointer deps of a non-pointer!");
927 auto NonLocalDefIt = NonLocalDefsCache.find(QueryInst);
928 if (NonLocalDefIt != NonLocalDefsCache.end()) {
930 ReverseNonLocalDefsCache[NonLocalDefIt->second.getResult().getInst()]
932 NonLocalDefsCache.erase(NonLocalDefIt);
945 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
946 return !LI->isUnordered();
947 }
else if (
StoreInst *
SI = dyn_cast<StoreInst>(Inst)) {
948 return !
SI->isUnordered();
954 const_cast<Value *>(Loc.
Ptr)));
957 const DataLayout &DL = FromBB->getModule()->getDataLayout();
965 if (getNonLocalPointerDepFromBB(QueryInst, Address, Loc, isLoad, FromBB,
966 Result, Visited,
true))
970 const_cast<Value *>(Loc.
Ptr)));
978 MemDepResult MemoryDependenceResults::GetNonLocalInfoForBlock(
986 if (Entry != Cache->begin() && (Entry - 1)->getBB() == BB)
990 if (Entry != Cache->begin() + NumSortedEntries && Entry->getBB() == BB)
991 ExistingResult = &*Entry;
995 if (ExistingResult && !ExistingResult->
getResult().isDirty()) {
996 ++NumCacheNonLocalPtr;
1006 "Instruction invalidated?");
1007 ++NumCacheDirtyNonLocalPtr;
1014 ++NumUncacheNonLocalPtr;
1037 assert(Inst &&
"Didn't depend on anything?");
1039 ReverseNonLocalPtrDeps[Inst].
insert(CacheKey);
1049 unsigned NumSortedEntries) {
1050 switch (Cache.size() - NumSortedEntries) {
1058 MemoryDependenceResults::NonLocalDepInfo::iterator
Entry =
1060 Cache.insert(Entry, Val);
1065 if (Cache.size() != 1) {
1068 MemoryDependenceResults::NonLocalDepInfo::iterator
Entry =
1070 Cache.insert(Entry, Val);
1093 bool MemoryDependenceResults::getNonLocalPointerDepFromBB(
1105 NonLocalPointerInfo InitialNLPI;
1106 InitialNLPI.Size = Loc.
Size;
1107 InitialNLPI.AATags = Loc.
AATags;
1111 std::pair<CachedNonLocalPointerInfo::iterator, bool> Pair =
1112 NonLocalPointerDeps.
insert(std::make_pair(CacheKey, InitialNLPI));
1113 NonLocalPointerInfo *CacheInfo = &Pair.first->second;
1118 if (CacheInfo->Size != Loc.
Size) {
1119 bool ThrowOutEverything;
1120 if (CacheInfo->Size.hasValue() && Loc.
Size.
hasValue()) {
1124 ThrowOutEverything =
1132 if (ThrowOutEverything) {
1135 CacheInfo->Pair = BBSkipFirstBlockPair();
1136 CacheInfo->Size = Loc.
Size;
1137 for (
auto &
Entry : CacheInfo->NonLocalDeps)
1140 CacheInfo->NonLocalDeps.clear();
1144 return getNonLocalPointerDepFromBB(
1146 StartBB, Result, Visited, SkipFirstBlock);
1153 if (CacheInfo->AATags != Loc.
AATags) {
1154 if (CacheInfo->AATags) {
1155 CacheInfo->Pair = BBSkipFirstBlockPair();
1157 for (
auto &
Entry : CacheInfo->NonLocalDeps)
1160 CacheInfo->NonLocalDeps.clear();
1163 return getNonLocalPointerDepFromBB(
1165 Visited, SkipFirstBlock);
1173 if (CacheInfo->Pair == BBSkipFirstBlockPair(StartBB, SkipFirstBlock)) {
1179 if (!Visited.
empty()) {
1180 for (
auto &
Entry : *Cache) {
1183 if (VI == Visited.
end() || VI->second == Pointer.
getAddr())
1194 for (
auto &
Entry : *Cache) {
1195 Visited.
insert(std::make_pair(
Entry.getBB(), Addr));
1196 if (
Entry.getResult().isNonLocal()) {
1205 ++NumCacheCompleteNonLocalPtr;
1214 CacheInfo->Pair = BBSkipFirstBlockPair(StartBB, SkipFirstBlock);
1216 CacheInfo->Pair = BBSkipFirstBlockPair();
1229 unsigned NumSortedEntries = Cache->size();
1231 bool GotWorklistLimit =
false;
1234 while (!Worklist.
empty()) {
1244 if (Cache && NumSortedEntries != Cache->size()) {
1251 CacheInfo->Pair = BBSkipFirstBlockPair();
1256 if (!SkipFirstBlock) {
1259 assert(Visited.
count(BB) &&
"Should check 'visited' before adding to WL");
1264 MemDepResult Dep = GetNonLocalInfoForBlock(QueryInst, Loc, isLoad, BB,
1265 Cache, NumSortedEntries);
1281 SkipFirstBlock =
false;
1285 std::pair<DenseMap<BasicBlock *, Value *>::iterator,
bool> InsertRes =
1287 if (InsertRes.second) {
1296 if (InsertRes.first->second != Pointer.
getAddr()) {
1299 for (
unsigned i = 0; i < NewBlocks.
size(); i++)
1300 Visited.
erase(NewBlocks[i]);
1301 goto PredTranslationFailure;
1304 if (NewBlocks.
size() > WorklistEntries) {
1307 for (
unsigned i = 0; i < NewBlocks.
size(); i++)
1308 Visited.
erase(NewBlocks[i]);
1309 GotWorklistLimit =
true;
1310 goto PredTranslationFailure;
1312 WorklistEntries -= NewBlocks.
size();
1320 goto PredTranslationFailure;
1327 if (Cache && NumSortedEntries != Cache->size()) {
1329 NumSortedEntries = Cache->size();
1335 PredList.
push_back(std::make_pair(Pred, Pointer));
1348 std::pair<DenseMap<BasicBlock *, Value *>::iterator,
bool> InsertRes =
1349 Visited.
insert(std::make_pair(Pred, PredPtrVal));
1351 if (!InsertRes.second) {
1357 if (InsertRes.first->second == PredPtrVal)
1366 for (
unsigned i = 0, n = PredList.
size(); i < n; ++i)
1367 Visited.
erase(PredList[i].first);
1369 goto PredTranslationFailure;
1378 for (
unsigned i = 0, n = PredList.
size(); i < n; ++i) {
1383 bool CanTranslate =
true;
1389 CanTranslate =
false;
1399 if (!CanTranslate ||
1400 !getNonLocalPointerDepFromBB(QueryInst, PredPointer,
1402 Pred, Result, Visited)) {
1405 Result.push_back(Entry);
1412 NonLocalPointerInfo &NLPI = NonLocalPointerDeps[CacheKey];
1413 NLPI.Pair = BBSkipFirstBlockPair();
1419 CacheInfo = &NonLocalPointerDeps[CacheKey];
1420 Cache = &CacheInfo->NonLocalDeps;
1421 NumSortedEntries = Cache->size();
1427 CacheInfo->Pair = BBSkipFirstBlockPair();
1428 SkipFirstBlock =
false;
1431 PredTranslationFailure:
1438 CacheInfo = &NonLocalPointerDeps[CacheKey];
1439 Cache = &CacheInfo->NonLocalDeps;
1440 NumSortedEntries = Cache->size();
1447 CacheInfo->Pair = BBSkipFirstBlockPair();
1457 bool foundBlock =
false;
1459 if (
I.getBB() != BB)
1462 assert((GotWorklistLimit ||
I.getResult().isNonLocal() ||
1464 "Should only be here with transparent block");
1471 (void)foundBlock; (void)GotWorklistLimit;
1472 assert((foundBlock || GotWorklistLimit) &&
"Current block not in cache?");
1482 void MemoryDependenceResults::RemoveCachedNonLocalPointerDependencies(
1483 ValueIsLoadPair
P) {
1486 if (!NonLocalDefsCache.empty()) {
1487 auto it = NonLocalDefsCache.find(P.getPointer());
1488 if (it != NonLocalDefsCache.end()) {
1490 it->second.getResult().getInst(), P.getPointer());
1491 NonLocalDefsCache.erase(it);
1494 if (
auto *
I = dyn_cast<Instruction>(P.getPointer())) {
1495 auto toRemoveIt = ReverseNonLocalDefsCache.
find(
I);
1496 if (toRemoveIt != ReverseNonLocalDefsCache.
end()) {
1497 for (
const auto *
entry : toRemoveIt->second)
1498 NonLocalDefsCache.erase(
entry);
1499 ReverseNonLocalDefsCache.
erase(toRemoveIt);
1505 if (It == NonLocalPointerDeps.
end())
1512 for (
unsigned i = 0,
e = PInfo.size(); i !=
e; ++i) {
1523 NonLocalPointerDeps.
erase(It);
1546 if (NLDI != NonLocalDeps.
end()) {
1548 for (
auto &
Entry : BlockMap)
1551 NonLocalDeps.
erase(NLDI);
1556 if (LocalDepEntry != LocalDeps.
end()) {
1558 if (
Instruction *Inst = LocalDepEntry->second.getInst())
1562 LocalDeps.
erase(LocalDepEntry);
1572 RemoveCachedNonLocalPointerDependencies(
ValueIsLoadPair(RemInst,
false));
1573 RemoveCachedNonLocalPointerDependencies(
ValueIsLoadPair(RemInst,
true));
1587 NewDirtyVal = MemDepResult::getDirty(&*++RemInst->
getIterator());
1590 if (ReverseDepIt != ReverseLocalDeps.
end()) {
1593 "Nothing can locally depend on a terminator");
1595 for (
Instruction *InstDependingOnRemInst : ReverseDepIt->second) {
1596 assert(InstDependingOnRemInst != RemInst &&
1597 "Already removed our local dep info");
1599 LocalDeps[InstDependingOnRemInst] = NewDirtyVal;
1603 "There is no way something else can have " 1604 "a local dep on this if it is a terminator!");
1606 std::make_pair(NewDirtyVal.
getInst(), InstDependingOnRemInst));
1609 ReverseLocalDeps.
erase(ReverseDepIt);
1613 while (!ReverseDepsToAdd.
empty()) {
1614 ReverseLocalDeps[ReverseDepsToAdd.
back().first].
insert(
1615 ReverseDepsToAdd.
back().second);
1620 ReverseDepIt = ReverseNonLocalDeps.
find(RemInst);
1621 if (ReverseDepIt != ReverseNonLocalDeps.
end()) {
1623 assert(I != RemInst &&
"Already removed NonLocalDep info for RemInst");
1625 PerInstNLInfo &INLD = NonLocalDeps[
I];
1629 for (
auto &
Entry : INLD.first) {
1630 if (
Entry.getResult().getInst() != RemInst)
1634 Entry.setResult(NewDirtyVal);
1637 ReverseDepsToAdd.
push_back(std::make_pair(NextI, I));
1641 ReverseNonLocalDeps.
erase(ReverseDepIt);
1644 while (!ReverseDepsToAdd.
empty()) {
1645 ReverseNonLocalDeps[ReverseDepsToAdd.
back().first].
insert(
1646 ReverseDepsToAdd.
back().second);
1654 ReverseNonLocalPtrDeps.
find(RemInst);
1655 if (ReversePtrDepIt != ReverseNonLocalPtrDeps.
end()) {
1657 ReversePtrDepsToAdd;
1661 "Already removed NonLocalPointerDeps info for RemInst");
1669 for (
auto &
Entry : NLPDI) {
1670 if (
Entry.getResult().getInst() != RemInst)
1674 Entry.setResult(NewDirtyVal);
1677 ReversePtrDepsToAdd.
push_back(std::make_pair(NewDirtyInst, P));
1685 ReverseNonLocalPtrDeps.
erase(ReversePtrDepIt);
1687 while (!ReversePtrDepsToAdd.
empty()) {
1688 ReverseNonLocalPtrDeps[ReversePtrDepsToAdd.
back().first].
insert(
1689 ReversePtrDepsToAdd.
back().second);
1697 assert(!NonLocalDeps.
count(RemInst) &&
"RemInst got reinserted?");
1705 void MemoryDependenceResults::verifyRemoved(
Instruction *
D)
const {
1707 for (
const auto &DepKV : LocalDeps) {
1708 assert(DepKV.first != D &&
"Inst occurs in data structures");
1709 assert(DepKV.second.getInst() != D &&
"Inst occurs in data structures");
1712 for (
const auto &DepKV : NonLocalPointerDeps) {
1713 assert(DepKV.first.getPointer() != D &&
"Inst occurs in NLPD map key");
1714 for (
const auto &
Entry : DepKV.second.NonLocalDeps)
1715 assert(
Entry.getResult().getInst() != D &&
"Inst occurs as NLPD value");
1718 for (
const auto &DepKV : NonLocalDeps) {
1719 assert(DepKV.first != D &&
"Inst occurs in data structures");
1720 const PerInstNLInfo &INLD = DepKV.second;
1721 for (
const auto &
Entry : INLD.first)
1723 "Inst occurs in data structures");
1726 for (
const auto &DepKV : ReverseLocalDeps) {
1727 assert(DepKV.first != D &&
"Inst occurs in data structures");
1729 assert(Inst != D &&
"Inst occurs in data structures");
1732 for (
const auto &DepKV : ReverseNonLocalDeps) {
1733 assert(DepKV.first != D &&
"Inst occurs in data structures");
1735 assert(Inst != D &&
"Inst occurs in data structures");
1738 for (
const auto &DepKV : ReverseNonLocalPtrDeps) {
1739 assert(DepKV.first != D &&
"Inst occurs in rev NLPD map");
1743 "Inst occurs in ReverseNonLocalPtrDeps map");
1766 "Memory Dependence Analysis",
false,
true)
1814 return DefaultBlockScanLimit;
1818 auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
1819 auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
1820 auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
1821 auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
1822 auto &PV = getAnalysis<PhiValuesWrapperPass>().getResult();
The access may reference and may modify the value stored in memory.
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)
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL, bool AllowNonInbounds=true)
Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset...
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.
This class represents lattice values for constants.
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...
void push_back(const T &Elt)
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 isTerminator() const
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
MemDepResult getDependency(Instruction *QueryInst, OrderedBasicBlock *OBB=nullptr)
Returns the instruction on which a memory operation depends.
STATISTIC(NumFunctions, "Total number of functions")
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
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.
static AnalysisKey * ID()
Returns an opaque, unique ID for this analysis type.
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...
An analysis that produces MemoryDependenceResults for a function.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
static MemoryLocation getForArgument(const CallBase *Call, unsigned ArgIdx, const TargetLibraryInfo *TLI)
Return a location representing a particular argument of a call.
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.
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)
uint64_t getValue() const
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)
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.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
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
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.
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)
MemDepResult getPointerDependencyFrom(const MemoryLocation &Loc, bool isLoad, BasicBlock::iterator ScanIt, BasicBlock *BB, Instruction *QueryInst=nullptr, unsigned *Limit=nullptr, OrderedBasicBlock *OBB=nullptr)
Returns the instruction on which a memory location depends.
bool onlyReadsMemory(const CallBase *Call)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
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 address space casts.
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
MemoryDependenceAnalysis()
A memory dependence query can return one of three different answers.
MemDepResult getSimplePointerDependencyFrom(const MemoryLocation &MemLoc, bool isLoad, BasicBlock::iterator ScanIt, BasicBlock *BB, Instruction *QueryInst, unsigned *Limit, OrderedBasicBlock *OBB)
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.
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...
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.
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 >, llvm::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...
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...
LLVM Value Representation.
const NonLocalDepInfo & getNonLocalCallDependency(CallBase *QueryCall)
Perform a full dependency query for the specified call, returning the set of blocks that the value is...
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.
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
print Instructions which execute on loop entry
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...
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
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...
auto upper_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const