LLVM 20.0.0git
|
Provides a lazy, caching interface for making common memory aliasing information queries, backed by LLVM's alias analysis passes. More...
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
Public Types | |
using | NonLocalDepInfo = std::vector< NonLocalDepEntry > |
Public Member Functions | |
MemoryDependenceResults (AAResults &AA, AssumptionCache &AC, const TargetLibraryInfo &TLI, DominatorTree &DT, unsigned DefaultBlockScanLimit) | |
bool | invalidate (Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv) |
Handle invalidation in the new PM. | |
unsigned | getDefaultBlockScanLimit () const |
Some methods limit the number of instructions they will examine. | |
MemDepResult | getDependency (Instruction *QueryInst) |
Returns the instruction on which a memory operation depends. | |
const NonLocalDepInfo & | getNonLocalCallDependency (CallBase *QueryCall) |
Perform a full dependency query for the specified call, returning the set of blocks that the value is potentially live across. | |
void | getNonLocalPointerDependency (Instruction *QueryInst, SmallVectorImpl< NonLocalDepResult > &Result) |
Perform a full dependency query for an access to the QueryInst's specified memory location, returning the set of instructions that either define or clobber the value. | |
void | removeInstruction (Instruction *InstToRemove) |
Removes an instruction from the dependence analysis, updating the dependence of instructions that previously depended on it. | |
void | invalidateCachedPointerInfo (Value *Ptr) |
Invalidates cached information about the specified pointer, because it may be too conservative in memdep. | |
void | invalidateCachedPredecessors () |
Clears the PredIteratorCache info. | |
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. | |
MemDepResult | getPointerDependencyFrom (const MemoryLocation &Loc, bool isLoad, BasicBlock::iterator ScanIt, BasicBlock *BB, Instruction *QueryInst, unsigned *Limit, BatchAAResults &BatchAA) |
MemDepResult | getSimplePointerDependencyFrom (const MemoryLocation &MemLoc, bool isLoad, BasicBlock::iterator ScanIt, BasicBlock *BB, Instruction *QueryInst, unsigned *Limit, BatchAAResults &BatchAA) |
MemDepResult | getInvariantGroupPointerDependency (LoadInst *LI, BasicBlock *BB) |
This analysis looks for other loads and stores with invariant.group metadata and the same pointer operand. | |
void | releaseMemory () |
Release memory in caches. | |
std::optional< int32_t > | getClobberOffset (LoadInst *DepInst) const |
Return the clobber offset to dependent instruction. | |
Provides a lazy, caching interface for making common memory aliasing information queries, backed by LLVM's alias analysis passes.
The dependency information returned is somewhat unusual, but is pragmatic. If queried about a store or call that might modify memory, the analysis will return the instruction[s] that may either load from that memory or store to it. If queried with a load or call that can never modify memory, the analysis will return calls and stores that might modify the pointer, but generally does not return loads unless a) they are volatile, or b) they load from must-aliased pointers. Returning a dependence on must-alias'd pointers instead of all pointers interacts well with the internal caching mechanism.
Definition at line 271 of file MemoryDependenceAnalysis.h.
using llvm::MemoryDependenceResults::NonLocalDepInfo = std::vector<NonLocalDepEntry> |
Definition at line 277 of file MemoryDependenceAnalysis.h.
|
inline |
Definition at line 367 of file MemoryDependenceAnalysis.h.
|
inline |
Return the clobber offset to dependent instruction.
Definition at line 479 of file MemoryDependenceAnalysis.h.
unsigned MemoryDependenceResults::getDefaultBlockScanLimit | ( | ) | const |
Some methods limit the number of instructions they will examine.
The return value of this method is the default limit that will be used if no limit is explicitly passed in.
Definition at line 1766 of file MemoryDependenceAnalysis.cpp.
Referenced by getSimplePointerDependencyFrom().
MemDepResult MemoryDependenceResults::getDependency | ( | Instruction * | QueryInst | ) |
Returns the instruction on which a memory operation depends.
See the class comment for more details. It is illegal to call this on non-memory instructions.
Definition at line 647 of file MemoryDependenceAnalysis.cpp.
References llvm::BasicBlock::begin(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::clear(), llvm::Function::getEntryBlock(), llvm::MemDepResult::getInst(), llvm::ilist_node_impl< OptionsT >::getIterator(), GetLocation(), llvm::MemDepResult::getNonFuncLocal(), llvm::MemDepResult::getNonLocal(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getParent(), getPointerDependencyFrom(), llvm::MemDepResult::getUnknown(), I, II, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), isLoad(), llvm::isModSet(), llvm::AAResults::onlyReadsMemory(), llvm::MemoryLocation::Ptr, and RemoveFromReverseMap().
Referenced by getNonLocalCallDependency().
MemDepResult MemoryDependenceResults::getInvariantGroupPointerDependency | ( | LoadInst * | LI, |
BasicBlock * | BB | ||
) |
This analysis looks for other loads and stores with invariant.group metadata and the same pointer operand.
Returns Unknown if it does not find anything, and Def if it can be assumed that 2 instructions load or store the same value and NonLocal which indicate that non-local Def was found, which can be retrieved by calling getNonLocalPointerDependency with the same queried instruction.
Definition at line 277 of file MemoryDependenceAnalysis.cpp.
References assert(), llvm::DominatorTree::dominates(), llvm::MemDepResult::getDef(), llvm::MemDepResult::getNonLocal(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::LoadInst::getPointerOperand(), llvm::getPointerOperand(), llvm::MemDepResult::getUnknown(), llvm::Instruction::hasMetadata(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::Other, llvm::Value::stripPointerCasts(), and llvm::Value::uses().
Referenced by getPointerDependencyFrom().
const MemoryDependenceResults::NonLocalDepInfo & MemoryDependenceResults::getNonLocalCallDependency | ( | CallBase * | QueryCall | ) |
Perform a full dependency query for the specified call, returning the set of blocks that the value is potentially live across.
The returned set of results will include a "NonLocal" result for all blocks where the value is live across.
This method assumes the instruction returns a "NonLocal" dependency within its own block.
This returns a reference to an internal data structure that may be invalidated on the next non-local query or when an instruction is removed. Clients must copy this data if they want it around longer than that.
Definition at line 718 of file MemoryDependenceAnalysis.cpp.
References llvm::append_range(), assert(), AssertSorted(), llvm::BasicBlock::begin(), llvm::SmallVectorBase< Size_T >::empty(), llvm::BasicBlock::end(), llvm::PredIteratorCache::get(), getDependency(), llvm::Function::getEntryBlock(), llvm::MemDepResult::getInst(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::MemDepResult::getNonFuncLocal(), llvm::MemDepResult::getNonLocal(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getParent(), llvm::NonLocalDepEntry::getResult(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::MemDepResult::isNonLocal(), LLVM_DEBUG, llvm::AAResults::onlyReadsMemory(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::NonLocalDepEntry::setResult(), llvm::SmallPtrSetImplBase::size(), and llvm::sort().
void MemoryDependenceResults::getNonLocalPointerDependency | ( | Instruction * | QueryInst, |
SmallVectorImpl< NonLocalDepResult > & | Result | ||
) |
Perform a full dependency query for an access to the QueryInst's specified memory location, returning the set of instructions that either define or clobber the value.
Warning: For a volatile query instruction, the dependencies will be accurate, and thus usable for reordering, but it is never legal to remove the query instruction.
This method assumes the pointer has a "NonLocal" dependency within QueryInst's parent basic block.
Definition at line 842 of file MemoryDependenceAnalysis.cpp.
References llvm::Address, assert(), DL, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::erase(), llvm::MemoryLocation::get(), llvm::BasicBlock::getDataLayout(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::Value::getType(), llvm::MemDepResult::getUnknown(), isLoad(), isOrdered(), llvm::Type::isPointerTy(), llvm::Instruction::isVolatile(), and llvm::MemoryLocation::Ptr.
MemDepResult MemoryDependenceResults::getPointerDependencyFrom | ( | const MemoryLocation & | Loc, |
bool | isLoad, | ||
BasicBlock::iterator | ScanIt, | ||
BasicBlock * | BB, | ||
Instruction * | QueryInst, | ||
unsigned * | Limit, | ||
BatchAAResults & | BatchAA | ||
) |
Definition at line 240 of file MemoryDependenceAnalysis.cpp.
References assert(), getInvariantGroupPointerDependency(), getSimplePointerDependencyFrom(), llvm::MemDepResult::getUnknown(), llvm::MemDepResult::isDef(), isLoad(), llvm::MemDepResult::isNonLocal(), and llvm::MemDepResult::isUnknown().
MemDepResult MemoryDependenceResults::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.
If isLoad is true, this routine ignores may-aliases with read-only operations. If isLoad is false, this routine ignores may-aliases with reads from read-only locations. If possible, pass the query instruction as well; this function may take advantage of the metadata annotated to the query instruction to refine the result. Limit
can be used to set the maximum number of instructions that will be examined to find the pointer dependency. On return, it will be set to the number of instructions left to examine. If a null pointer is passed in, the limit will default to the value of -memdep-block-scan-limit.
Note that this is an uncached query, and thus may be inefficient.
Definition at line 268 of file MemoryDependenceAnalysis.cpp.
References getPointerDependencyFrom(), and isLoad().
Referenced by getDependency(), and getPointerDependencyFrom().
MemDepResult MemoryDependenceResults::getSimplePointerDependencyFrom | ( | const MemoryLocation & | MemLoc, |
bool | isLoad, | ||
BasicBlock::iterator | ScanIt, | ||
BasicBlock * | BB, | ||
Instruction * | QueryInst, | ||
unsigned * | Limit, | ||
BatchAAResults & | BatchAA | ||
) |
Definition at line 367 of file MemoryDependenceAnalysis.cpp.
References llvm::BatchAAResults::alias(), llvm::BasicBlock::begin(), canSkipClobberingStore(), llvm::MemoryLocation::get(), llvm::MemoryLocation::getAfter(), llvm::MemDepResult::getClobber(), llvm::BasicBlock::getDataLayout(), llvm::MemDepResult::getDef(), getDefaultBlockScanLimit(), llvm::Function::getEntryBlock(), GetLocation(), llvm::BatchAAResults::getModRefInfo(), llvm::BatchAAResults::getModRefInfoMask(), llvm::MemDepResult::getNonFuncLocal(), llvm::MemDepResult::getNonLocal(), llvm::BasicBlock::getParent(), llvm::Value::getPointerAlignment(), llvm::getUnderlyingObject(), llvm::MemDepResult::getUnknown(), I, II, isLoad(), llvm::isModOrRefSet(), llvm::isModSet(), llvm::BatchAAResults::isMustAlias(), llvm::isNoAliasCall(), llvm::isStrongerThan(), llvm::isStrongerThanUnordered(), llvm::Instruction::isVolatile(), llvm::Mod, llvm::Monotonic, llvm::AliasResult::MustAlias, llvm::AliasResult::NoAlias, llvm::NoModRef, llvm::NotAtomic, llvm::AliasResult::PartialAlias, llvm::MemoryLocation::Ptr, llvm::Ref, llvm::Release, and llvm::Unordered.
Referenced by getPointerDependencyFrom().
bool MemoryDependenceResults::invalidate | ( | Function & | F, |
const PreservedAnalyses & | PA, | ||
FunctionAnalysisManager::Invalidator & | Inv | ||
) |
Handle invalidation in the new PM.
Definition at line 1748 of file MemoryDependenceAnalysis.cpp.
References F, llvm::PreservedAnalyses::getChecker(), and llvm::AnalysisManager< IRUnitT, ExtraArgTs >::Invalidator::invalidate().
void MemoryDependenceResults::invalidateCachedPointerInfo | ( | Value * | Ptr | ) |
Invalidates cached information about the specified pointer, because it may be too conservative in memdep.
This is an optional call that can be used when the client detects an equivalence between the pointer and some other value and replaces the other value with ptr. This can make Ptr available in more places that cached info does not necessarily keep.
Definition at line 1476 of file MemoryDependenceAnalysis.cpp.
References Ptr.
void MemoryDependenceResults::invalidateCachedPredecessors | ( | ) |
Clears the PredIteratorCache info.
This needs to be done when the CFG changes, e.g., due to splitting critical edges.
Definition at line 1486 of file MemoryDependenceAnalysis.cpp.
References llvm::PredIteratorCache::clear().
Referenced by llvm::MergeBlockIntoPredecessor().
void llvm::MemoryDependenceResults::releaseMemory | ( | ) |
Release memory in caches.
void MemoryDependenceResults::removeInstruction | ( | Instruction * | InstToRemove | ) |
Removes an instruction from the dependence analysis, updating the dependence of instructions that previously depended on it.
Definition at line 1490 of file MemoryDependenceAnalysis.cpp.
References assert(), llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::count(), llvm::SmallVectorBase< Size_T >::empty(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::erase(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::MemDepResult::getInst(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Value::getType(), I, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::Type::isPointerTy(), llvm::Instruction::isTerminator(), LLVM_DEBUG, P, llvm::SmallVectorTemplateBase< T, bool >::pop_back(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), RemoveFromReverseMap(), llvm::EarliestEscapeAnalysis::removeInstruction(), and llvm::sort().
Referenced by llvm::FoldSingleEntryPHINodes().