58#define DEBUG_TYPE "memdep"
60STATISTIC(NumCacheNonLocal,
"Number of fully cached non-local responses");
61STATISTIC(NumCacheDirtyNonLocal,
"Number of dirty cached non-local responses");
62STATISTIC(NumUncacheNonLocal,
"Number of uncached non-local responses");
65 "Number of fully cached non-local ptr responses");
67 "Number of cached, but dirty, non-local ptr responses");
68STATISTIC(NumUncacheNonLocalPtr,
"Number of uncached non-local ptr responses");
70 "Number of block queries that were completely cached");
76 cl::desc(
"The number of instructions to scan in a block in memory "
77 "dependency analysis (default = 100)"));
81 cl::desc(
"The number of blocks to scan during memory "
82 "dependency analysis (default = 200)"));
86 cl::desc(
"The max number of entries allowed in a cache (default = 10000)"));
94template <
typename KeyTy>
99 ReverseMap.find(Inst);
100 assert(InstIt != ReverseMap.
end() &&
"Reverse map out of sync?");
101 bool Found = InstIt->second.
erase(Val);
102 assert(Found &&
"Invalid reverse map!");
104 if (InstIt->second.
empty())
105 ReverseMap.erase(InstIt);
116 if (LI->isUnordered()) {
129 if (
SI->isUnordered()) {
155 switch (
II->getIntrinsicID()) {
156 case Intrinsic::lifetime_start:
157 case Intrinsic::lifetime_end:
162 case Intrinsic::invariant_start:
167 case Intrinsic::invariant_end:
172 case Intrinsic::masked_load:
175 case Intrinsic::masked_store:
192MemDepResult MemoryDependenceResults::getCallDependencyFrom(
196 bool IsInvariantLoad =
Call->
hasMetadata(LLVMContext::MD_invariant_load);
199 while (ScanIt != BB->
begin()) {
222 bool IsIdenticalReadOnlyCall = isReadOnlyCall && !
isModSet(MR) &&
227 if (IsInvariantLoad && IsIdenticalReadOnlyCall)
234 if (IsIdenticalReadOnlyCall)
240 }
else if (IsInvariantLoad) {
265 if (QueryInst !=
nullptr) {
269 if (InvariantGroupDependency.
isDef())
270 return InvariantGroupDependency;
274 MemLoc,
isLoad, ScanIt, BB, QueryInst, Limit, BatchAA);
275 if (SimpleDep.
isDef())
281 return InvariantGroupDependency;
284 "InvariantGroupDependency should be only unknown at this point");
300 if (!LI->
hasMetadata(LLVMContext::MD_invariant_group))
318 assert(
Other &&
"Must call it with not null instruction");
319 if (Best ==
nullptr || DT.dominates(Best,
Other))
324 for (
const Use &Us : LoadOperand->
uses()) {
326 if (!U || U == LI || !DT.dominates(U, LI))
335 U->hasMetadata(LLVMContext::MD_invariant_group))
336 ClosestDependency = GetClosestDependency(ClosestDependency, U);
339 if (!ClosestDependency)
341 if (ClosestDependency->
getParent() == BB)
347 NonLocalDefsCache.try_emplace(
350 ReverseNonLocalDefsCache[ClosestDependency].insert(LI);
362 unsigned ScanLimit) {
369 if (std::min(MemLocAlign,
SI->getAlign()).value() <
374 if (!LI || LI->getParent() !=
SI->getParent())
378 unsigned NumVisitedInsts = 0;
380 if (++NumVisitedInsts > ScanLimit ||
397 Limit = &DefaultLimit;
431 if (
isLoad && QueryInst) {
434 MemLocAlign = LI->getAlign();
447 return I->mayReadOrWriteMemory();
451 while (ScanIt != BB->
begin()) {
465 case Intrinsic::lifetime_start: {
471 case Intrinsic::masked_load:
472 case Intrinsic::masked_store: {
480 if (
ID == Intrinsic::masked_load)
496 if (LI->isVolatile()) {
534 ClobberOffsets[LI] = R.getOffset();
555 if (!
SI->isUnordered() &&
SI->isAtomic()) {
573 if (
SI->isVolatile())
610 if (AccessPtr == Inst || BatchAA.
isMustAlias(Inst, AccessPtr))
658 ClobberOffsets.clear();
666 if (!LocalCache.isDirty())
694 isLoad |=
II->getIntrinsicID() == Intrinsic::lifetime_start;
698 QueryParent, QueryInst,
nullptr);
700 bool isReadOnly = AA.onlyReadsMemory(QueryCall);
701 LocalCache = getCallDependencyFrom(QueryCall, isReadOnly,
710 ReverseLocalDeps[
I].insert(QueryInst);
721 Count = Cache.size();
722 assert(std::is_sorted(Cache.begin(), Cache.begin() +
Count) &&
723 "Cache isn't sorted!");
730 "getNonLocalCallDependency should only be used on calls with "
732 PerInstNLInfo &CacheP = NonLocalDepsMap[QueryCall];
740 if (!Cache.empty()) {
743 if (!CacheP.second) {
750 for (
auto &Entry : Cache)
751 if (Entry.getResult().isDirty())
757 ++NumCacheDirtyNonLocal;
762 ++NumUncacheNonLocal;
766 bool isReadonlyCall = AA.onlyReadsMemory(QueryCall);
770 unsigned NumSortedEntries = Cache.
size();
774 while (!DirtyBlocks.
empty()) {
778 if (!Visited.
insert(DirtyBB).second)
784 NonLocalDepInfo::iterator Entry =
785 std::upper_bound(Cache.begin(), Cache.begin() + NumSortedEntries,
787 if (Entry != Cache.begin() && std::prev(Entry)->getBB() == DirtyBB)
791 if (Entry != Cache.begin() + NumSortedEntries &&
792 Entry->getBB() == DirtyBB) {
795 if (!Entry->getResult().isDirty())
799 ExistingResult = &*Entry;
805 if (ExistingResult) {
817 if (ScanPos != DirtyBB->
begin()) {
818 Dep = getCallDependencyFrom(QueryCall, isReadonlyCall, ScanPos, DirtyBB);
840 ReverseNonLocalDeps[Inst].insert(QueryCall);
859 assert(
Loc.Ptr->getType()->isPointerTy() &&
860 "Can't get pointer deps of a non-pointer!");
864 auto NonLocalDefIt = NonLocalDefsCache.find(QueryInst);
865 if (NonLocalDefIt != NonLocalDefsCache.end()) {
866 Result.push_back(NonLocalDefIt->second);
867 ReverseNonLocalDefsCache[NonLocalDefIt->second.getResult().getInst()]
869 NonLocalDefsCache.erase(NonLocalDefIt);
883 return !LI->isUnordered();
885 return !
SI->isUnordered();
901 ++NonLocalPointerDepEpoch;
902 assert(NonLocalPointerDepEpoch > 0 &&
903 "NonLocalPointerDepVisitedEpoch overflow");
918MemDepResult MemoryDependenceResults::getNonLocalInfoForBlock(
920 BasicBlock *BB, NonLocalDepInfo *Cache,
unsigned NumSortedEntries,
930 NonLocalDepInfo::iterator Entry = std::upper_bound(
932 if (Entry != Cache->begin() && (Entry - 1)->getBB() == BB)
936 if (Entry != Cache->begin() + NumSortedEntries && Entry->getBB() == BB)
937 ExistingResult = &*Entry;
944 ExistingResult =
nullptr;
948 if (ExistingResult && !ExistingResult->
getResult().isDirty()) {
949 ++NumCacheNonLocalPtr;
959 "Instruction invalidated?");
960 ++NumCacheDirtyNonLocalPtr;
964 ValueIsLoadPair CacheKey(
Loc.Ptr,
isLoad);
967 ++NumUncacheNonLocalPtr;
972 QueryInst,
nullptr, BatchAA);
983 Cache->push_back(NonLocalDepEntry(BB, Dep));
994 assert(Inst &&
"Didn't depend on anything?");
995 ValueIsLoadPair CacheKey(Loc.
Ptr,
isLoad);
996 ReverseNonLocalPtrDeps[Inst].insert(CacheKey);
1006 unsigned NumSortedEntries) {
1009 if (Cache.size() < 2)
1012 unsigned s = Cache.size() - NumSortedEntries;
1019 if (NumSortedEntries == 0) {
1027 if (s <
Log2_32(Cache.size())) {
1031 MemoryDependenceResults::NonLocalDepInfo::iterator Entry =
1032 std::upper_bound(Cache.begin(), Cache.end() - s + 1, Val);
1033 Cache.insert(Entry, Val);
1041void MemoryDependenceResults::setNonLocalPointerDepVisited(
BasicBlock *BB,
1043 NonLocalPointerDepVisited[BB->
getNumber()] = {
V, NonLocalPointerDepEpoch};
1046bool MemoryDependenceResults::isNonLocalPointerDepVisited(
1048 return NonLocalPointerDepVisited[BB->
getNumber()].second ==
1049 NonLocalPointerDepEpoch;
1053MemoryDependenceResults::lookupNonLocalPointerDepVisited(
BasicBlock *BB)
const {
1054 assert(isNonLocalPointerDepVisited(BB) &&
1055 "Visited value requested for unseen block");
1056 return NonLocalPointerDepVisited[BB->
getNumber()].first;
1072bool MemoryDependenceResults::getNonLocalPointerDepFromBB(
1076 bool IsIncomplete) {
1084 NonLocalPointerInfo InitialNLPI;
1085 InitialNLPI.Size = Loc.
Size;
1086 InitialNLPI.AATags = Loc.
AATags;
1094 std::pair<CachedNonLocalPointerInfo::iterator, bool> Pair =
1095 NonLocalPointerDeps.insert(std::make_pair(CacheKey, InitialNLPI));
1096 NonLocalPointerInfo *CacheInfo = &Pair.first->second;
1102 if (CacheInfo->Size != Loc.
Size) {
1105 CacheInfo->Pair = BBSkipFirstBlockPair();
1106 CacheInfo->Size = Loc.
Size;
1107 for (
auto &Entry : CacheInfo->NonLocalDeps)
1108 if (Instruction *Inst =
Entry.getResult().getInst())
1110 CacheInfo->NonLocalDeps.clear();
1114 IsIncomplete =
true;
1120 if (CacheInfo->AATags != Loc.
AATags) {
1121 if (CacheInfo->AATags) {
1122 CacheInfo->Pair = BBSkipFirstBlockPair();
1123 CacheInfo->AATags = AAMDNodes();
1124 for (
auto &Entry : CacheInfo->NonLocalDeps)
1125 if (Instruction *Inst =
Entry.getResult().getInst())
1127 CacheInfo->NonLocalDeps.clear();
1131 IsIncomplete =
true;
1134 return getNonLocalPointerDepFromBB(
1136 SkipFirstBlock, IsIncomplete);
1147 CacheInfo->Pair == BBSkipFirstBlockPair(StartBB, SkipFirstBlock)) {
1153 for (
auto &Entry : *Cache) {
1154 if (!isNonLocalPointerDepVisited(
Entry.getBB()))
1156 Value *Prev = lookupNonLocalPointerDepVisited(
Entry.getBB());
1157 if (Prev ==
Pointer.getAddr())
1167 for (
auto &Entry : *Cache) {
1168 setNonLocalPointerDepVisited(
Entry.getBB(), Addr);
1169 if (
Entry.getResult().isNonLocal()) {
1173 if (DT.isReachableFromEntry(
Entry.getBB())) {
1175 NonLocalDepResult(
Entry.getBB(),
Entry.getResult(), Addr));
1178 ++NumCacheCompleteNonLocalPtr;
1194 if (!IsIncomplete && Cache->empty())
1195 CacheInfo->Pair = BBSkipFirstBlockPair(StartBB, SkipFirstBlock);
1197 CacheInfo->Pair = BBSkipFirstBlockPair();
1211 unsigned NumSortedEntries = Cache->size();
1213 bool GotWorklistLimit =
false;
1216 BatchAAResults BatchAA(AA, &EEA);
1217 while (!Worklist.
empty()) {
1226 if (Cache && NumSortedEntries != Cache->size()) {
1233 CacheInfo->Pair = BBSkipFirstBlockPair();
1238 if (!SkipFirstBlock) {
1241 assert(isNonLocalPointerDepVisited(BB) &&
1242 "Should check 'visited' before adding to WL");
1247 MemDepResult Dep = getNonLocalInfoForBlock(
1248 QueryInst, Loc,
isLoad, BB, Cache, NumSortedEntries, BatchAA);
1252 if (DT.isReachableFromEntry(BB)) {
1253 Result.push_back(NonLocalDepResult(BB, Dep,
Pointer.getAddr()));
1263 if (!
Pointer.needsPHITranslationFromBlock(BB)) {
1264 SkipFirstBlock =
false;
1265 SmallVector<BasicBlock *, 16> NewBlocks;
1266 for (BasicBlock *Pred : PredCache.get(BB)) {
1268 if (!isNonLocalPointerDepVisited(Pred)) {
1269 setNonLocalPointerDepVisited(Pred,
Pointer.getAddr());
1274 Value *Prev = lookupNonLocalPointerDepVisited(Pred);
1278 if (Prev !=
Pointer.getAddr()) {
1281 for (
auto *NewBlock : NewBlocks)
1282 setNonLocalPointerDepVisited(NewBlock,
nullptr);
1283 goto PredTranslationFailure;
1286 if (NewBlocks.
size() > WorklistEntries) {
1289 for (
auto *NewBlock : NewBlocks)
1290 setNonLocalPointerDepVisited(NewBlock,
nullptr);
1291 GotWorklistLimit =
true;
1292 goto PredTranslationFailure;
1294 WorklistEntries -= NewBlocks.
size();
1301 if (!
Pointer.isPotentiallyPHITranslatable())
1302 goto PredTranslationFailure;
1309 if (Cache && NumSortedEntries != Cache->size()) {
1311 NumSortedEntries = Cache->size();
1316 for (BasicBlock *Pred : PredCache.get(BB)) {
1317 PredList.
push_back(std::make_pair(Pred, Pointer));
1321 PHITransAddr &PredPointer = PredList.
back().second;
1330 if (!isNonLocalPointerDepVisited(Pred)) {
1331 setNonLocalPointerDepVisited(Pred, PredPtrVal);
1334 Value *PrevVal = lookupNonLocalPointerDepVisited(Pred);
1341 if (PrevVal == PredPtrVal)
1350 for (
const auto &Pred : PredList)
1351 setNonLocalPointerDepVisited(Pred.first,
nullptr);
1353 goto PredTranslationFailure;
1361 for (
auto &
I : PredList) {
1363 PHITransAddr &PredPointer =
I.second;
1366 bool CanTranslate =
true;
1380 PHITransAddr(Pointer).translateValue(BB, Pred, &DT,
Cond);
1381 if (SelAddrs.first && SelAddrs.second) {
1383 SelectAddr(
Cond, SelAddrs)));
1384 NonLocalPointerInfo &NLPI = NonLocalPointerDeps[CacheKey];
1385 NLPI.Pair = BBSkipFirstBlockPair();
1389 CanTranslate =
false;
1400 if (!CanTranslate ||
1401 !getNonLocalPointerDepFromBB(QueryInst, PredPointer,
1413 NonLocalPointerInfo &NLPI = NonLocalPointerDeps[CacheKey];
1414 NLPI.Pair = BBSkipFirstBlockPair();
1420 CacheInfo = &NonLocalPointerDeps[CacheKey];
1421 Cache = &CacheInfo->NonLocalDeps;
1422 NumSortedEntries = Cache->size();
1428 CacheInfo->Pair = BBSkipFirstBlockPair();
1429 SkipFirstBlock =
false;
1432 PredTranslationFailure:
1439 CacheInfo = &NonLocalPointerDeps[CacheKey];
1440 Cache = &CacheInfo->NonLocalDeps;
1441 NumSortedEntries = Cache->size();
1448 CacheInfo->Pair = BBSkipFirstBlockPair();
1462 if (
I.getBB() != BB)
1465 assert((GotWorklistLimit ||
I.getResult().isNonLocal() ||
1466 !DT.isReachableFromEntry(BB)) &&
1467 "Should only be here with transparent block");
1475 (void)GotWorklistLimit;
1488void MemoryDependenceResults::removeCachedNonLocalPointerDependencies(
1489 ValueIsLoadPair
P) {
1492 if (!NonLocalDefsCache.empty()) {
1493 auto it = NonLocalDefsCache.find(
P.getPointer());
1494 if (it != NonLocalDefsCache.end()) {
1496 it->second.getResult().getInst(),
P.getPointer());
1497 NonLocalDefsCache.erase(it);
1501 auto toRemoveIt = ReverseNonLocalDefsCache.find(
I);
1502 if (toRemoveIt != ReverseNonLocalDefsCache.end()) {
1503 for (
const auto *entry : toRemoveIt->second)
1504 NonLocalDefsCache.erase(entry);
1505 ReverseNonLocalDefsCache.erase(toRemoveIt);
1511 if (It == NonLocalPointerDeps.end())
1518 for (
const NonLocalDepEntry &DE : PInfo) {
1529 NonLocalPointerDeps.erase(It);
1537 removeCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr,
false));
1539 removeCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr,
true));
1547 EEA.removeInstruction(RemInst);
1552 if (NLDI != NonLocalDepsMap.end()) {
1554 for (
auto &Entry : BlockMap)
1555 if (
Instruction *Inst = Entry.getResult().getInst())
1557 NonLocalDepsMap.erase(NLDI);
1562 if (LocalDepEntry != LocalDeps.end()) {
1564 if (
Instruction *Inst = LocalDepEntry->second.getInst())
1568 LocalDeps.erase(LocalDepEntry);
1577 removeCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst,
false));
1578 removeCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst,
true));
1582 auto toRemoveIt = NonLocalDefsCache.find(RemInst);
1583 if (toRemoveIt != NonLocalDefsCache.end()) {
1585 "only load instructions should be added directly");
1586 const Instruction *DepV = toRemoveIt->second.getResult().getInst();
1587 ReverseNonLocalDefsCache.find(DepV)->second.erase(RemInst);
1588 NonLocalDefsCache.erase(toRemoveIt);
1603 NewDirtyVal = MemDepResult::getDirty(&*++RemInst->
getIterator());
1605 ReverseDepMapType::iterator ReverseDepIt = ReverseLocalDeps.find(RemInst);
1606 if (ReverseDepIt != ReverseLocalDeps.end()) {
1609 "Nothing can locally depend on a terminator");
1611 for (
Instruction *InstDependingOnRemInst : ReverseDepIt->second) {
1612 assert(InstDependingOnRemInst != RemInst &&
1613 "Already removed our local dep info");
1615 LocalDeps[InstDependingOnRemInst] = NewDirtyVal;
1619 "There is no way something else can have "
1620 "a local dep on this if it is a terminator!");
1622 std::make_pair(NewDirtyVal.
getInst(), InstDependingOnRemInst));
1625 ReverseLocalDeps.erase(ReverseDepIt);
1629 while (!ReverseDepsToAdd.
empty()) {
1630 ReverseLocalDeps[ReverseDepsToAdd.
back().first].insert(
1631 ReverseDepsToAdd.
back().second);
1636 ReverseDepIt = ReverseNonLocalDeps.find(RemInst);
1637 if (ReverseDepIt != ReverseNonLocalDeps.end()) {
1639 assert(
I != RemInst &&
"Already removed NonLocalDep info for RemInst");
1641 PerInstNLInfo &INLD = NonLocalDepsMap[
I];
1645 for (
auto &Entry : INLD.first) {
1646 if (Entry.getResult().getInst() != RemInst)
1650 Entry.setResult(NewDirtyVal);
1653 ReverseDepsToAdd.
push_back(std::make_pair(NextI,
I));
1657 ReverseNonLocalDeps.erase(ReverseDepIt);
1660 while (!ReverseDepsToAdd.
empty()) {
1661 ReverseNonLocalDeps[ReverseDepsToAdd.
back().first].insert(
1662 ReverseDepsToAdd.
back().second);
1669 ReverseNonLocalPtrDepTy::iterator ReversePtrDepIt =
1670 ReverseNonLocalPtrDeps.find(RemInst);
1671 if (ReversePtrDepIt != ReverseNonLocalPtrDeps.end()) {
1673 ReversePtrDepsToAdd;
1675 for (ValueIsLoadPair
P : ReversePtrDepIt->second) {
1676 assert(
P.getPointer() != RemInst &&
1677 "Already removed NonLocalPointerDeps info for RemInst");
1679 auto &NLPD = NonLocalPointerDeps[
P];
1684 NLPD.Pair = BBSkipFirstBlockPair();
1687 for (
auto &Entry : NLPDI) {
1688 if (Entry.getResult().getInst() != RemInst)
1692 Entry.setResult(NewDirtyVal);
1695 ReversePtrDepsToAdd.
push_back(std::make_pair(NewDirtyInst,
P));
1703 ReverseNonLocalPtrDeps.
erase(ReversePtrDepIt);
1705 while (!ReversePtrDepsToAdd.
empty()) {
1706 ReverseNonLocalPtrDeps[ReversePtrDepsToAdd.
back().first].insert(
1707 ReversePtrDepsToAdd.
back().second);
1712 assert(!NonLocalDepsMap.count(RemInst) &&
"RemInst got reinserted?");
1720void MemoryDependenceResults::verifyRemoved(
Instruction *
D)
const {
1722 for (
const auto &DepKV : LocalDeps) {
1723 assert(DepKV.first !=
D &&
"Inst occurs in data structures");
1724 assert(DepKV.second.getInst() !=
D &&
"Inst occurs in data structures");
1727 for (
const auto &DepKV : NonLocalPointerDeps) {
1728 assert(DepKV.first.getPointer() !=
D &&
"Inst occurs in NLPD map key");
1729 for (
const auto &Entry : DepKV.second.NonLocalDeps)
1730 assert(Entry.getResult().getInst() !=
D &&
"Inst occurs as NLPD value");
1733 for (
const auto &DepKV : NonLocalDepsMap) {
1734 assert(DepKV.first !=
D &&
"Inst occurs in data structures");
1735 const PerInstNLInfo &INLD = DepKV.second;
1736 for (
const auto &Entry : INLD.first)
1738 "Inst occurs in data structures");
1741 for (
const auto &DepKV : ReverseLocalDeps) {
1742 assert(DepKV.first !=
D &&
"Inst occurs in data structures");
1743 for (Instruction *Inst : DepKV.second)
1744 assert(Inst !=
D &&
"Inst occurs in data structures");
1747 for (
const auto &DepKV : ReverseNonLocalDeps) {
1748 assert(DepKV.first !=
D &&
"Inst occurs in data structures");
1749 for (Instruction *Inst : DepKV.second)
1750 assert(Inst !=
D &&
"Inst occurs in data structures");
1753 for (
const auto &DepKV : ReverseNonLocalPtrDeps) {
1754 assert(DepKV.first !=
D &&
"Inst occurs in rev NLPD map");
1756 for (ValueIsLoadPair
P : DepKV.second)
1757 assert(
P != ValueIsLoadPair(
D,
false) &&
P != ValueIsLoadPair(
D,
true) &&
1758 "Inst occurs in ReverseNonLocalPtrDeps map");
1780 "Memory Dependence Analysis",
false,
true)
1805 FunctionAnalysisManager::Invalidator &Inv) {
1823 return DefaultBlockScanLimit;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isLoad(int Opcode)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file defines the DenseMap class.
Module.h This file contains the declarations for the Module class.
This defines the Use class.
static const unsigned int NumResultsLimit
static cl::opt< unsigned > CacheGlobalLimit("memdep-cache-global-limit", cl::Hidden, cl::init(10000), cl::desc("The max number of entries allowed in a cache (default = 10000)"))
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,...
static cl::opt< unsigned > BlockNumberLimit("memdep-block-number-limit", cl::Hidden, cl::init(200), cl::desc("The number of blocks to scan during memory " "dependency analysis (default = 200)"))
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.
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...
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.
static bool canSkipClobberingStore(const StoreInst *SI, const MemoryLocation &MemLoc, Align MemLocAlign, BatchAAResults &BatchAA, unsigned ScanLimit)
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)"))
This file provides utility analysis objects describing memory locations.
static bool isOrdered(const Instruction *I)
static bool isInvariantLoad(const Instruction *I, const Value *Ptr, const bool IsKernelFn)
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
const SmallVectorImpl< MachineOperand > & Cond
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
A manager for alias analyses.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
The possible results of an alias query.
@ NoAlias
The two locations do not alias at all.
@ PartialAlias
The two locations alias, but only due to a partial overlap.
@ MustAlias
The two locations precisely alias each other.
This templated class represents "all analyses that operate over <aparticular IR unit>" (e....
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
AnalysisUsage & addRequiredTransitive()
A function analysis which provides an AssumptionCache.
An immutable pass that tracks lazily created AssumptionCache objects.
LLVM Basic Block Representation.
unsigned getNumber() const
iterator begin()
Instruction iterator methods.
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
InstListType::iterator iterator
Instruction iterators...
This class is a wrapper over an AAResults, and it is intended to be used only when there are no IR ch...
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
ModRefInfo getModRefInfo(const Instruction *I, const std::optional< MemoryLocation > &OptLoc)
ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, bool IgnoreLocals=false)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
A parsed version of the target data layout string in and methods for querying it.
bool erase(const KeyT &Val)
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
Analysis pass which computes a DominatorTree.
Legacy analysis pass which computes a DominatorTree.
An instruction for ordering other memory operations.
const BasicBlock & getEntryBlock() const
unsigned getMaxBlockNumber() const
Return a value larger than the largest block number.
LLVM_ABI bool mayWriteToMemory() const LLVM_READONLY
Return true if this instruction may modify memory.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
LLVM_ABI bool isIdenticalToWhenDefined(const Instruction *I, bool IntersectAttrs=false) const LLVM_READONLY
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags,...
bool isTerminator() const
LLVM_ABI bool mayReadFromMemory() const LLVM_READONLY
Return true if this instruction may read memory.
LLVM_ABI bool isVolatile() const LLVM_READONLY
Return true if this instruction has a volatile memory access.
A wrapper class for inspecting calls to intrinsic functions.
An instruction for reading from memory.
Value * getPointerOperand()
TypeSize getValue() const
A memory dependence query can return one of three different answers.
bool isNonLocal() const
Tests if this MemDepResult represents a query that is transparent to the start of the block,...
static MemDepResult getNonLocal()
bool isNonFuncLocal() const
Tests if this MemDepResult represents a query that is transparent to the start of the function.
static MemDepResult getSelect()
static MemDepResult getClobber(Instruction *Inst)
bool isDef() const
Tests if this MemDepResult represents a query that is an instruction definition dependency.
static MemDepResult getUnknown()
bool isLocal() const
Tests if this MemDepResult represents a valid local query (Clobber/Def).
bool isUnknown() const
Tests if this MemDepResult represents a query which cannot and/or will not be computed.
static MemDepResult getNonFuncLocal()
static MemDepResult getDef(Instruction *Inst)
get methods: These are static ctor methods for creating various MemDepResult kinds.
Instruction * getInst() const
If this is a normal dependency, returns the instruction that is depended on.
An analysis that produces MemoryDependenceResults for a function.
LLVM_ABI MemoryDependenceResults run(Function &F, FunctionAnalysisManager &AM)
LLVM_ABI MemoryDependenceAnalysis()
Provides a lazy, caching interface for making common memory aliasing information queries,...
LLVM_ABI MemDepResult getSimplePointerDependencyFrom(const MemoryLocation &MemLoc, bool isLoad, BasicBlock::iterator ScanIt, BasicBlock *BB, Instruction *QueryInst, unsigned *Limit, BatchAAResults &BatchAA)
std::vector< NonLocalDepEntry > NonLocalDepInfo
LLVM_ABI void invalidateCachedPredecessors()
Clears the PredIteratorCache info.
LLVM_ABI void invalidateCachedPointerInfo(Value *Ptr)
Invalidates cached information about the specified pointer, because it may be too conservative in mem...
LLVM_ABI 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.
LLVM_ABI void removeInstruction(Instruction *InstToRemove)
Removes an instruction from the dependence analysis, updating the dependence of instructions that pre...
LLVM_ABI MemDepResult getInvariantGroupPointerDependency(LoadInst *LI, BasicBlock *BB)
This analysis looks for other loads and stores with invariant.group metadata and the same pointer ope...
LLVM_ABI unsigned getDefaultBlockScanLimit() const
Some methods limit the number of instructions they will examine.
LLVM_ABI MemDepResult getDependency(Instruction *QueryInst)
Returns the instruction on which a memory operation depends.
LLVM_ABI const NonLocalDepInfo & getNonLocalCallDependency(CallBase *QueryCall)
Perform a full dependency query for the specified call, returning the set of blocks that the value is...
LLVM_ABI void getNonLocalPointerDependency(Instruction *QueryInst, SmallVectorImpl< NonLocalDepResult > &Result)
Perform a full dependency query for an access to the QueryInst's specified memory location,...
LLVM_ABI bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation in the new PM.
A wrapper analysis pass for the legacy pass manager that exposes a MemoryDepnedenceResults instance.
bool runOnFunction(Function &) override
Pass Implementation stuff. This doesn't do any analysis eagerly.
~MemoryDependenceWrapperPass() override
void getAnalysisUsage(AnalysisUsage &AU) const override
Does not modify anything. It uses Value Numbering and Alias Analysis.
void releaseMemory() override
Clean up memory in between runs.
MemoryDependenceWrapperPass()
Representation for a specific memory location.
MemoryLocation getWithoutAATags() const
static LLVM_ABI MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
LocationSize Size
The maximum size of the location, in address-units, or UnknownSize if the size is not known.
static MemoryLocation getAfter(const Value *Ptr, const AAMDNodes &AATags=AAMDNodes())
Return a location that may access any location after Ptr, while remaining within the underlying objec...
MemoryLocation getWithNewPtr(const Value *NewPtr) const
AAMDNodes AATags
The metadata nodes which describes the aliasing of the location (each member is null if that kind of ...
const Value * Ptr
The address of the start of the location.
static LLVM_ABI MemoryLocation getForArgument(const CallBase *Call, unsigned ArgIdx, const TargetLibraryInfo *TLI)
Return a location representing a particular argument of a call.
This is an entry in the NonLocalDepInfo cache.
void setResult(const MemDepResult &R)
const MemDepResult & getResult() const
This is a result from a NonLocal dependence query.
PHITransAddr - An address value which tracks and handles phi translation.
LLVM_ABI Value * translateValue(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree *DT, bool MustDominate)
translateValue - PHI translate the current address up the CFG from CurBB to Pred, updating our state ...
LLVM_ABI Value * getSelectCondition() const
If the address expression depends on a select instruction (possibly through casts or GEPs),...
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
A set of analyses that are preserved following a run of a transformation pass.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
std::pair< Value *, Value * > SelectAddrs
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
bool isPointerTy() const
True if this is an instance of PointerType.
A Use represents the edge between a Value definition and its users.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
iterator_range< use_iterator > uses()
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
const ParentTy * getParent() const
self_iterator getIterator()
Abstract Attribute helper functions.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ BasicBlock
Various leaf nodes.
initializer< Ty > init(const Ty &Val)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
bool isStrongerThanUnordered(AtomicOrdering AO)
LLVM_ABI bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
const Value * getPointerOperand(const Value *V)
A helper function that returns the pointer operand of a load, store or GEP instruction.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
auto reverse(ContainerTy &&C)
bool isModSet(const ModRefInfo MRI)
void sort(IteratorTy Start, IteratorTy End)
bool isModOrRefSet(const ModRefInfo MRI)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
AtomicOrdering
Atomic ordering for LLVM's memory model.
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
@ Ref
The access may reference the value stored in memory.
@ ModRef
The access may reference and may modify the value stored in memory.
@ Mod
The access may modify the value stored in memory.
@ NoModRef
The access neither references nor modifies the value stored in memory.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
LLVM_ABI Value * getFreedOperand(const CallBase *CB, const TargetLibraryInfo *TLI)
If this if a call to a free function, return the freed operand.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=MaxLookupSearchDepth)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
bool isNoModRef(const ModRefInfo MRI)
bool isStrongerThan(AtomicOrdering AO, AtomicOrdering Other)
Returns true if ao is stronger than other as defined by the AtomicOrdering lattice,...
This struct is a compact representation of a valid (non-zero power of two) alignment.
A special type used by analysis passes to provide an address that identifies that particular analysis...