38 #ifndef LLVM_ANALYSIS_ALIASANALYSIS_H 39 #define LLVM_ANALYSIS_ALIASANALYSIS_H 62 class OrderedBasicBlock;
188 return ModRefInfo(static_cast<int>(MRI1) | static_cast<int>(MRI2));
192 return ModRefInfo(static_cast<int>(MRI1) & static_cast<int>(MRI2));
298 template <
typename AAResultT>
void addAAResult(AAResultT &AAResult) {
302 AAs.emplace_back(
new Model<AAResultT>(AAResult, *
this));
343 return alias(LocA, LocB) ==
NoAlias;
371 bool pointsToConstantMemory(
const MemoryLocation &Loc,
bool OrLocal =
false);
437 return onlyReadsMemory(getModRefBehavior(Call));
450 return onlyReadsMemory(getModRefBehavior(F));
603 if (OptLoc ==
None) {
604 if (
const auto *Call = dyn_cast<CallBase>(I)) {
612 case Instruction::VAArg:
return getModRefInfo((
const VAArgInst*)I, Loc);
615 case Instruction::Fence:
return getModRefInfo((
const FenceInst*)I, Loc);
616 case Instruction::AtomicCmpXchg:
618 case Instruction::AtomicRMW:
621 case Instruction::Invoke:
return getModRefInfo((
const InvokeInst*)I,Loc);
622 case Instruction::CatchPad:
624 case Instruction::CatchRet:
691 return canInstructionRangeModRef(I1, I2,
MemoryLocation(Ptr, Size), Mode);
703 std::vector<std::unique_ptr<Concept>> AAs;
705 std::vector<AnalysisKey *> AADeps;
727 virtual void setAAResults(
AAResults *NewAAR) = 0;
756 unsigned ArgIdx) = 0;
788 explicit Model(AAResultT &Result,
AAResults &AAR) : Result(Result) {
789 Result.setAAResults(&AAR);
791 ~
Model()
override =
default;
793 void setAAResults(
AAResults *NewAAR)
override { Result.setAAResults(NewAAR); }
797 return Result.alias(LocA, LocB);
801 bool OrLocal)
override {
802 return Result.pointsToConstantMemory(Loc, OrLocal);
806 return Result.getArgModRefInfo(Call, ArgIdx);
810 return Result.getModRefBehavior(Call);
814 return Result.getModRefBehavior(F);
819 return Result.getModRefInfo(Call, Loc);
824 return Result.getModRefInfo(Call1, Call2);
852 DerivedT &derived() {
return static_cast<DerivedT &
>(*this); }
856 void setAAResults(
AAResults *NewAAR) { AAR = NewAAR; }
864 DerivedT &CurrentResult;
868 : AAR(AAR), CurrentResult(CurrentResult) {}
871 return AAR ? AAR->
alias(LocA, LocB) : CurrentResult.alias(LocA, LocB);
876 : CurrentResult.pointsToConstantMemory(Loc, OrLocal);
881 : CurrentResult.getArgModRefInfo(Call, ArgIdx);
886 : CurrentResult.getModRefBehavior(Call);
895 : CurrentResult.getModRefInfo(Call, Loc);
900 : CurrentResult.getModRefInfo(Call1, Call2);
993 ResultGetters.push_back(&getFunctionAAResultImpl<AnalysisT>);
998 ResultGetters.push_back(&getModuleAAResultImpl<AnalysisT>);
1003 for (
auto &Getter : ResultGetters)
1004 (*Getter)(
F, AM, R);
1017 template <
typename AnalysisT>
1018 static void getFunctionAAResultImpl(
Function &F,
1021 AAResults.
addAAResult(AM.template getResult<AnalysisT>(F));
1025 template <
typename AnalysisT>
1027 AAResults &AAResults) {
1029 auto &MAM = MAMProxy.getManager();
1030 if (
auto *R = MAM.template getCachedResult<AnalysisT>(*F.
getParent())) {
1033 .template registerOuterAnalysisInvalidation<AnalysisT, AAManager>();
1041 std::unique_ptr<AAResults> AAR;
1059 using CallbackT = std::function<void(Pass &, Function &, AAResults &)>;
1106 #endif // LLVM_ANALYSIS_ALIASANALYSIS_H The access may reference and may modify the value stored in memory.
Pass interface - Implemented by all 'passes'.
LLVM_NODISCARD ModRefInfo unionModRef(const ModRefInfo MRI1, const ModRefInfo MRI2)
ModRefInfo getModRefInfo(const CatchReturnInst *I, const Value *P, LocationSize Size)
getModRefInfo (for catchrets) - A convenience wrapper.
ModRefInfo getModRefInfo(const AtomicRMWInst *RMW, const Value *P, LocationSize Size)
getModRefInfo (for atomicrmws) - A convenience wrapper.
static bool onlyAccessesInaccessibleMem(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from memory that ...
void addAAResult(AAResultT &AAResult)
Register a specific AA result.
The access neither references nor modifies the value stored in memory.
LLVM_NODISCARD ModRefInfo clearMust(const ModRefInfo MRI)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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.
ModRefInfo getModRefInfo(const CatchPadInst *I, const Value *P, LocationSize Size)
getModRefInfo (for catchpads) - A convenience wrapper.
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
AAResultsProxy(AAResults *AAR, DerivedT &CurrentResult)
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.
ModRefInfo callCapturesBefore(const Instruction *I, const Value *P, LocationSize Size, DominatorTree *DT, OrderedBasicBlock *OBB=nullptr)
A convenience wrapper to synthesize a memory location.
ModRefInfo getModRefInfo(const FenceInst *S, const Value *P, LocationSize Size)
getModRefInfo (for fences) - A convenience wrapper.
static constexpr LocationSize unknown()
ModRefInfo getModRefInfo(const StoreInst *S, const Value *P, LocationSize Size)
getModRefInfo (for stores) - A convenience wrapper.
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)
std::function< void(Pass &, Function &, AAResults &)> CallbackT
bool canInstructionRangeModRef(const Instruction &I1, const Instruction &I2, const Value *Ptr, LocationSize Size, const ModRefInfo Mode)
A convenience wrapper synthesizing a memory location.
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
This class represents a function call, abstracting a target machine's calling convention.
The two locations do not alias at all.
bool doesNotAccessMemory(const Function *F)
Checks if the specified function is known to never read or write memory.
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
void registerModuleAnalysis()
Register a specific AA result.
const AAResults & getAAResults() const
This is the AA result object for the basic, local, and stateless alias analysis.
static LocationSize precise(uint64_t Value)
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.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
An instruction for reading from memory.
bool canBasicBlockModify(const BasicBlock &BB, const Value *P, LocationSize Size)
A convenience wrapper synthesizing a memory location.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
void initializeExternalAAWrapperPassPass(PassRegistry &)
LLVM_NODISCARD bool isModAndRefSet(const ModRefInfo MRI)
ModRefInfo getModRefInfo(const Instruction *I, const Optional< MemoryLocation > &OptLoc)
Check whether or not an instruction may read or write the optionally specified memory location...
This indicates that the function could not be classified into one of the behaviors above...
LLVM_NODISCARD ModRefInfo clearMod(const ModRefInfo MRI)
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
ModRefInfo getModRefInfo(const CallBase *Call, const Value *P, LocationSize Size)
getModRefInfo (for call sites) - A convenience wrapper.
The only memory references in this function (if it has any) are references of memory that is otherwis...
FunctionPass * createAAResultsWrapperPass()
ModRefInfo getModRefInfo(const AtomicCmpXchgInst *CX, const Value *P, LocationSize Size)
getModRefInfo (for cmpxchges) - A convenience wrapper.
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.
LLVM_NODISCARD ModRefInfo clearRef(const ModRefInfo MRI)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Must is provided for completeness, but no routines will return only Must today.
The access may reference the value stored in memory, a mustAlias relation was found, and no mayAlias or partialAlias found.
The access may reference the value stored in memory.
The only memory references in this function (if it has any) are non-volatile loads from objects point...
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...
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...
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
Return the behavior of the given call site.
AliasResult alias(const Value *V1, const Value *V2)
A convenience wrapper around the primary alias interface.
LLVM_NODISCARD ModRefInfo setRef(const ModRefInfo MRI)
LLVM_NODISCARD bool isMustSet(const ModRefInfo MRI)
ModRefInfo getModRefInfo(const LoadInst *L, const Value *P, LocationSize Size)
getModRefInfo (for loads) - A convenience wrapper.
Access to memory via argument pointers.
The access may reference, modify or both the value stored in memory, a mustAlias relation was found...
FunctionModRefBehavior
Summary of how a function affects memory in the program.
The access may modify the value stored in memory, a mustAlias relation was found, and no mayAlias or ...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
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...
AliasResult
The possible results of an alias query.
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 ...
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...
static bool runOnFunction(Function &F, bool PostInlining)
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)
LLVM_NODISCARD ModRefInfo setMust(const ModRefInfo MRI)
A set of analyses that are preserved following a run of a transformation pass.
unsigned const MachineRegisterInfo * MRI
LLVM Basic Block Representation.
AliasResult alias(const Value *V1, LocationSize V1Size, const Value *V2, LocationSize V2Size)
A convenience wrapper around the primary alias interface.
A manager for alias analyses.
A CRTP mix-in that provides informational APIs needed for analysis passes.
ModRefInfo getModRefInfo(const VAArgInst *I, const Value *P, LocationSize Size)
getModRefInfo (for va_args) - A convenience wrapper.
Result run(Function &F, FunctionAnalysisManager &AM)
Represent the analysis usage information of a pass.
void addAADependencyID(AnalysisKey *ID)
Register a function analysis ID that the results aggregation depends on.
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2)
static bool doesAccessArgPointees(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to potentially read or write from objects p...
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.
bool onlyReadsMemory(const CallBase *Call)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
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.
The two locations may or may not alias. This is the least precise result.
FunctionModRefLocation
The locations at which a function might access memory.
Representation for a specific memory location.
The two locations precisely alias each other.
ImmutablePass class - This class is used to provide information that does not need to be run...
Memory that is inaccessible via LLVM IR.
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
LLVM_NODISCARD ModRefInfo setMod(const ModRefInfo MRI)
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...
The access may modify the value stored in memory.
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...
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM_NODISCARD bool isNoModRef(const ModRefInfo MRI)
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are must-alias.
amdgpu Simplify well known AMD library false Value Value * Arg
AAResults(const TargetLibraryInfo &TLI)
LLVM_NODISCARD bool isModSet(const ModRefInfo MRI)
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 CallBase *Call, const MemoryLocation &Loc)
Base case is no access to memory.
bool doesNotAccessMemory(const CallBase *Call)
Checks if the specified call is known to never read or write 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...
LLVM_NODISCARD ModRefInfo intersectModRef(const ModRefInfo MRI1, const ModRefInfo MRI2)
AAResultsProxy getBestAAResults()
Get a proxy for the best AA result set to query at this time.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
API to communicate dependencies between analyses during invalidation.
Analysis pass providing the TargetLibraryInfo.
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
Get the ModRef info associated with a pointer argument of a call.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
LLVM_NODISCARD ModRefInfo createModRefInfo(const FunctionModRefBehavior FMRB)
This class implements an extremely fast bulk output stream that can only output to a stream...
A wrapper pass for external alias analyses.
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
LLVM_NODISCARD ModRefInfo setModAndRef(const ModRefInfo MRI)
print Print MemDeps of function
FunctionModRefBehavior getModRefBehavior(const Function *F)
bool isNoAlias(const Value *V1, LocationSize V1Size, const Value *V2, LocationSize V2Size)
A convenience wrapper around the isNoAlias helper interface.
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.
LLVM_NODISCARD bool isModOrRefSet(const ModRefInfo MRI)
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.
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.
ExternalAAWrapperPass(CallbackT CB)
A special type used by analysis passes to provide an address that identifies that particular analysis...
ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2)
FunctionModRefBehavior getModRefBehavior(const Function *F)
ModRefInfo getModRefInfo(const Instruction *I, const Value *P, LocationSize Size)
A convenience wrapper for constructing the memory location.
LLVM_NODISCARD bool isRefSet(const ModRefInfo MRI)