38 #ifndef LLVM_ANALYSIS_ALIASANALYSIS_H
39 #define LLVM_ANALYSIS_ALIASANALYSIS_H
55 class MemTransferInst;
58 class OrderedBasicBlock;
193 template <
typename AAResultT>
void addAAResult(AAResultT &AAResult) {
197 AAs.emplace_back(
new Model<AAResultT>(AAResult, *
this));
545 case Instruction::AtomicCmpXchg:
547 case Instruction::AtomicRMW:
551 case Instruction::CatchPad:
553 case Instruction::CatchRet:
629 std::vector<std::unique_ptr<Concept>> AAs;
631 std::vector<AnalysisKey *> AADeps;
682 unsigned ArgIdx) = 0;
714 explicit Model(AAResultT &Result,
AAResults &AAR) : Result(Result) {
715 Result.setAAResults(&AAR);
719 void setAAResults(
AAResults *NewAAR)
override { Result.setAAResults(NewAAR); }
722 const MemoryLocation &LocB)
override {
723 return Result.alias(LocA, LocB);
727 bool OrLocal)
override {
728 return Result.pointsToConstantMemory(Loc, OrLocal);
732 return Result.getArgModRefInfo(CS, ArgIdx);
736 return Result.getModRefBehavior(CS);
740 return Result.getModRefBehavior(F);
744 const MemoryLocation &Loc)
override {
745 return Result.getModRefInfo(CS, Loc);
749 ImmutableCallSite CS2)
override {
750 return Result.getModRefInfo(CS1, CS2);
778 DerivedT &derived() {
return static_cast<DerivedT &
>(*this); }
782 void setAAResults(
AAResults *NewAAR) { AAR = NewAAR; }
790 DerivedT &CurrentResult;
794 : AAR(AAR), CurrentResult(CurrentResult) {}
797 return AAR ? AAR->
alias(LocA, LocB) : CurrentResult.alias(LocA, LocB);
802 : CurrentResult.pointsToConstantMemory(Loc, OrLocal);
806 return AAR ? AAR->
getArgModRefInfo(CS, ArgIdx) : CurrentResult.getArgModRefInfo(CS, ArgIdx);
819 : CurrentResult.getModRefInfo(CS, Loc);
823 return AAR ? AAR->
getModRefInfo(CS1, CS2) : CurrentResult.getModRefInfo(CS1, CS2);
917 ResultGetters.push_back(&getFunctionAAResultImpl<AnalysisT>);
922 ResultGetters.push_back(&getModuleAAResultImpl<AnalysisT>);
927 for (
auto &Getter : ResultGetters)
940 template <
typename AnalysisT>
941 static void getFunctionAAResultImpl(
Function &F,
944 AAResults.
addAAResult(AM.template getResult<AnalysisT>(F));
948 template <
typename AnalysisT>
950 AAResults &AAResults) {
952 auto &MAM = MAMProxy.getManager();
953 if (
auto *R = MAM.template getCachedResult<AnalysisT>(*F.getParent())) {
954 AAResults.addAAResult(*R);
956 .template registerOuterAnalysisInvalidation<AnalysisT, AAManager>();
964 std::unique_ptr<AAResults> AAR;
ModRefInfo getModRefInfo(const LoadInst *L, const Value *P, uint64_t Size)
getModRefInfo (for loads) - A convenience wrapper.
The two locations precisely alias each other.
const AAResults & getAAResults() const
static bool onlyAccessesInaccessibleMem(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from memory that ...
ModRefInfo getModRefInfo(const Instruction *I, const Value *P, uint64_t Size)
A convenience wrapper for constructing the memory location.
void addAAResult(AAResultT &AAResult)
Register a specific AA result.
bool canInstructionRangeModRef(const Instruction &I1, const Instruction &I2, const Value *Ptr, uint64_t Size, const ModRefInfo Mode)
A convenience wrapper synthesizing a memory location.
ModRefInfo getModRefInfo(const AtomicRMWInst *RMW, const Value *P, unsigned Size)
getModRefInfo (for atomicrmws) - A convenience wrapper.
AAResults AliasAnalysis
Temporary typedef for legacy code that uses a generic AliasAnalysis pointer or reference.
AAResultsProxy(AAResults *AAR, DerivedT &CurrentResult)
virtual ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc)=0
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
An instruction for ordering other memory operations.
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
bool isNoAlias(const Value *V1, uint64_t V1Size, const Value *V2, uint64_t V2Size)
A convenience wrapper around the isNoAlias helper interface.
The two locations alias, but only due to a partial overlap.
bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are no-alias. ...
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
ModRefInfo getModRefInfo(const CatchReturnInst *I, const Value *P, uint64_t Size)
getModRefInfo (for catchrets) - A convenience wrapper.
This class represents a function call, abstracting a target machine's calling convention.
bool doesNotAccessMemory(const Function *F)
Checks if the specified function is known to never read or write memory.
void registerModuleAnalysis()
Register a specific AA result.
bool onlyReadsMemory(ImmutableCallSite CS)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
static bool onlyAccessesInaccessibleOrArgMem(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from memory that ...
bool pointsToConstantMemory(const Value *P, bool OrLocal=false)
A convenience wrapper around the primary pointsToConstantMemory interface.
The two locations do not alias at all.
bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
An instruction for reading from memory.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
ModRefInfo getModRefInfo(const AtomicCmpXchgInst *CX, const Value *P, unsigned Size)
getModRefInfo (for cmpxchges) - A convenience wrapper.
ModRefInfo getModRefInfo(const CatchPadInst *I, const Value *P, uint64_t Size)
getModRefInfo (for catchpads) - A convenience wrapper.
The access modifies the value stored in memory.
The two locations may or may not alias. This is the least precise result.
This indicates that the function could not be classified into one of the behaviors above...
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
The only memory references in this function (if it has any) are references of memory that is otherwis...
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
FunctionPass * createAAResultsWrapperPass()
static bool doesNotReadMemory(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to only write memory (or not access memory ...
bool isNoAlias(const Value *V1, const Value *V2)
A convenience wrapper around the isNoAlias helper interface.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
The only memory references in this function (if it has any) are non-volatile loads from objects point...
The access references the value stored in memory.
AAResults createLegacyPMAAResults(Pass &P, Function &F, BasicAAResult &BAR)
A helper for the legacy pass manager to create a AAResults object populated to the best of our abilit...
The function may perform non-volatile loads and stores of objects pointed to by its pointer-typed arg...
virtual bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)=0
Checks whether the given location points to constant memory, or if OrLocal is true whether it points ...
bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
AAResults & getAAResults()
A CRTP-driven "mixin" base class to help implement the function alias analysis results concept...
AliasResult alias(const Value *V1, const Value *V2)
A convenience wrapper around the primary alias interface.
virtual void setAAResults(AAResults *NewAAR)=0
An update API used internally by the AAResults to provide a handle back to the top level aggregation...
AliasResult alias(const Value *V1, uint64_t V1Size, const Value *V2, uint64_t V2Size)
A convenience wrapper around the primary alias interface.
ModRefInfo getModRefInfo(const InvokeInst *I, const Value *P, uint64_t Size)
getModRefInfo (for invokes) - A convenience wrapper.
Access to memory via argument pointers.
FunctionModRefBehavior
Summary of how a function affects memory in the program.
bool runOnFunction(Function &F) override
Run the wrapper pass to rebuild an aggregation over known AA passes.
ModRefInfo getModRefInfo(const FenceInst *S, const Value *P, uint64_t Size)
getModRefInfo (for fences) - A convenience wrapper.
AAResultBase(AAResultBase &&Arg)
An instruction for storing to memory.
void registerFunctionAnalysis()
Register a specific AA result.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
A private abstract base class describing the concept of an individual alias analysis implementation...
static bool onlyReadsMemory(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to only read from non-volatile memory (or n...
ModRefInfo getModRefInfo(const VAArgInst *I, const Value *P, uint64_t Size)
getModRefInfo (for va_args) - A convenience wrapper.
ModRefInfo getModRefInfo(const Instruction *I, const MemoryLocation &Loc)
Check whether or not an instruction may read or write the specified memory location.
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS)
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
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 ...
The access neither references nor modifies the value stored in memory.
ImmutablePass * createExternalAAWrapperPass(std::function< void(Pass &, Function &, AAResults &)> Callback)
A wrapper pass around a callback which can be used to populate the AAResults in the AAResultsWrapperP...
bool onlyReadsMemory(const Function *F)
Checks if the specified function is known to only read from non-volatile memory (or not access memory...
AAResultBase(const AAResultBase &Arg)
A set of analyses that are preserved following a run of a transformation pass.
LLVM Basic Block Representation.
bool canInstructionRangeModRef(const Instruction &I1, const Instruction &I2, const MemoryLocation &Loc, const ModRefInfo Mode)
Check if it is possible for the execution of the specified instructions to mod(according to the mode)...
A manager for alias analyses.
ModRefInfo getModRefInfo(const CallInst *C, const Value *P, uint64_t Size)
getModRefInfo (for calls) - A convenience wrapper.
A CRTP mix-in that provides informational APIs needed for analysis passes.
ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx)
Result run(Function &F, FunctionAnalysisManager &AM)
AliasResult
The possible results of an alias query.
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS)
Return the behavior of the given call site.
Represent the analysis usage information of a pass.
void addAADependencyID(AnalysisKey *ID)
Register a function analysis ID that the results aggregation depends on.
static bool doesAccessArgPointees(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to potentially read or write from objects p...
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
The only memory references in this function (if it has any) are non-volatile loads and stores from ob...
FunctionPass class - This class is used to implement most global optimizations.
ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2)
ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx)
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
void getAAResultsAnalysisUsage(AnalysisUsage &AU)
A helper for the legacy pass manager to populate AU to add uses to make sure the analyses required by...
This function does not perform any non-local loads or stores to memory.
bool isIdentifiedFunctionLocal(const Value *V)
Return true if V is umabigously identified at the function-level.
FunctionModRefLocation
The locations at which a function might access memory.
Representation for a specific memory location.
bool doesNotAccessMemory(ImmutableCallSite CS)
Checks if the specified call is known to never read or write memory.
print lazy value Lazy Value Info Printer Pass
Memory that is inaccessible via LLVM IR.
ModRefInfo getModRefInfo(ImmutableCallSite CS, const Value *P, uint64_t Size)
getModRefInfo (for call sites) - A convenience wrapper.
ModRefInfo getModRefInfo(const InvokeInst *I, const MemoryLocation &Loc)
getModRefInfo (for invokes) - Return information about whether a particular invoke modifies or reads ...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Provides information about what library functions are available for the current target.
This function does not perform any non-local stores or volatile loads, but may read from any memory l...
bool isMustAlias(const Value *V1, const Value *V2)
A convenience wrapper around the isMustAlias helper interface.
This proxy class models a common pattern where we delegate to either the top-level AAResults aggregat...
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 ...
virtual ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx)=0
Get the ModRef info associated with a pointer argument of a callsite.
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are must-alias.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
AAResults(const TargetLibraryInfo &TLI)
static bool onlyAccessesArgPointees(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from objects poin...
ModRefInfo getModRefInfo(const CallInst *C, const MemoryLocation &Loc)
getModRefInfo (for calls) - Return information about whether a particular call modifies or reads the ...
Base case is no access to memory.
This file provides utility analysis objects describing memory locations.
static bool doesAccessInaccessibleMem(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to potentially read or write from memory th...
Establish a view to a call site for examination.
The access both references and modifies the value stored in memory.
AAResultsProxy getBestAAResults()
Get a proxy for the best AA result set to query at this time.
virtual AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)=0
The main low level interface to the alias analysis implementation.
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS)
ModRefInfo getModRefInfo(const StoreInst *S, const Value *P, uint64_t Size)
getModRefInfo (for stores) - A convenience wrapper.
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc)
API to communicate dependencies between analyses during invalidation.
Analysis pass providing the TargetLibraryInfo.
ModRefInfo callCapturesBefore(const Instruction *I, const Value *P, uint64_t Size, DominatorTree *DT, OrderedBasicBlock *OBB=nullptr)
A convenience wrapper to synthesize a memory location.
LLVM Value Representation.
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc)
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
print Print MemDeps of function
FunctionModRefBehavior getModRefBehavior(const Function *F)
A container for analyses that lazily runs them and caches their results.
bool isNoAliasArgument(const Value *V)
Return true if this is an argument with the noalias attribute.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
This header defines various interfaces for pass management in LLVM.
bool canBasicBlockModify(const BasicBlock &BB, const Value *P, uint64_t Size)
A convenience wrapper synthesizing a memory location.
bool canBasicBlockModify(const BasicBlock &BB, const MemoryLocation &Loc)
Check if it is possible for execution of the specified basic block to modify the location Loc...
ModRefInfo getModRefInfo(const Instruction *I)
Check whether or not an instruction may read or write memory (without regard to a specific location)...
A special type used by analysis passes to provide an address that identifies that particular analysis...
ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx)
Get the ModRef info associated with a pointer argument of a callsite.
ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2)
virtual FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS)=0
Return the behavior of the given call site.
FunctionModRefBehavior getModRefBehavior(const Function *F)