37#ifndef LLVM_ANALYSIS_ALIASANALYSIS_H
38#define LLVM_ANALYSIS_ALIASANALYSIS_H
56class AtomicCmpXchgInst;
63class TargetLibraryInfo;
80 static const int OffsetBits = 23;
81 static const int AliasBits = 8;
82 static_assert(AliasBits + 1 + OffsetBits <= 32,
83 "AliasResult size is intended to be 4 bytes!");
85 unsigned int Alias : AliasBits;
86 unsigned int HasOffset : 1;
87 signed int Offset : OffsetBits;
105 static_assert(
MustAlias < (1 << AliasBits),
106 "Not enough bit field size for the enum!");
110 : Alias(Alias), HasOffset(
false), Offset(0) {}
112 operator Kind()
const {
return static_cast<Kind>(Alias); }
115 return Alias ==
Other.Alias && HasOffset ==
Other.HasOffset &&
116 Offset ==
Other.Offset;
125 assert(HasOffset &&
"No offset!");
129 if (isInt<OffsetBits>(NewOffset)) {
136 void swap(
bool DoSwap =
true) {
142static_assert(
sizeof(AliasResult) == 4,
143 "AliasResult size is intended to be 4 bytes!");
244 using LocPair = std::pair<AACacheLoc, AACacheLoc>;
327 template <
typename AAResultT>
void addAAResult(AAResultT &AAResult) {
331 AAs.emplace_back(
new Model<AAResultT>(AAResult, *
this));
426 bool IgnoreLocals =
false);
514 const std::optional<MemoryLocation> &OptLoc) {
591 bool IgnoreLocals =
false);
624 const std::optional<MemoryLocation> &OptLoc,
637 template <
typename T>
class Model;
643 std::vector<std::unique_ptr<Concept>> AAs;
645 std::vector<AnalysisKey *> AADeps;
664 : AA(AAR), AAQI(AAR, CA) {}
667 return AA.
alias(LocA, LocB, AAQI);
676 bool IgnoreLocals =
false) {
680 const std::optional<MemoryLocation> &OptLoc) {
758 bool IgnoreLocals) = 0;
766 unsigned ArgIdx) = 0;
796template <
typename AAResultT>
class AAResults::Model final :
public Concept {
800 explicit Model(AAResultT &Result,
AAResults &AAR) : Result(Result) {}
801 ~Model()
override =
default;
803 AliasResult alias(
const MemoryLocation &LocA,
const MemoryLocation &LocB,
804 AAQueryInfo &AAQI,
const Instruction *CtxI)
override {
805 return Result.alias(LocA, LocB, AAQI, CtxI);
808 ModRefInfo getModRefInfoMask(
const MemoryLocation &Loc, AAQueryInfo &AAQI,
809 bool IgnoreLocals)
override {
810 return Result.getModRefInfoMask(Loc, AAQI, IgnoreLocals);
813 ModRefInfo getArgModRefInfo(
const CallBase *Call,
unsigned ArgIdx)
override {
814 return Result.getArgModRefInfo(Call, ArgIdx);
818 AAQueryInfo &AAQI)
override {
819 return Result.getMemoryEffects(Call, AAQI);
823 return Result.getMemoryEffects(
F);
826 ModRefInfo getModRefInfo(
const CallBase *Call,
const MemoryLocation &Loc,
827 AAQueryInfo &AAQI)
override {
828 return Result.getModRefInfo(Call, Loc, AAQI);
831 ModRefInfo getModRefInfo(
const CallBase *Call1,
const CallBase *Call2,
832 AAQueryInfo &AAQI)
override {
833 return Result.getModRefInfo(Call1, Call2, AAQI);
927 bool &RequiresNoCaptureBeforeUnwind);
941 bool &ExplicitlyDereferenceableOnly);
966 ResultGetters.push_back(&getFunctionAAResultImpl<AnalysisT>);
971 ResultGetters.push_back(&getModuleAAResultImpl<AnalysisT>);
985 template <
typename AnalysisT>
986 static void getFunctionAAResultImpl(
Function &
F,
993 template <
typename AnalysisT>
995 AAResults &AAResults) {
998 MAMProxy.template getCachedResult<AnalysisT>(*
F.getParent())) {
999 AAResults.addAAResult(*R);
1001 .template registerOuterAnalysisInvalidation<AnalysisT, AAManager>();
1009 std::unique_ptr<AAResults> AAR;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
static bool runOnFunction(Function &F, bool PostInlining)
This header defines various interfaces for pass management in LLVM.
This file provides utility analysis objects describing memory locations.
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallVector class.
A manager for alias analyses.
void registerFunctionAnalysis()
Register a specific AA result.
LLVM_ABI Result run(Function &F, FunctionAnalysisManager &AM)
void registerModuleAnalysis()
Register a specific AA result.
This class stores info we want to provide to or retain within an alias query.
AAQueryInfo(AAResults &AAR, CaptureAnalysis *CA)
SmallVector< AAQueryInfo::LocPair, 4 > AssumptionBasedResults
Location pairs for which an assumption based result is currently stored.
unsigned Depth
Query depth used to distinguish recursive queries.
bool UseDominatorTree
Whether alias analysis is allowed to use the dominator tree, for use by passes that lazily update the...
int NumAssumptionUses
How many active NoAlias assumption uses there are.
std::pair< AACacheLoc, AACacheLoc > LocPair
bool MayBeCrossIteration
Tracks whether the accesses may be on different cycle iterations.
A base class to help implement the function alias analysis results concept.
ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2, AAQueryInfo &AAQI)
MemoryEffects getMemoryEffects(const CallBase *Call, AAQueryInfo &AAQI)
ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool IgnoreLocals)
MemoryEffects getMemoryEffects(const Function *F)
AAResultBase(const AAResultBase &Arg)
AAResultBase(AAResultBase &&Arg)
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI, const Instruction *I)
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
const AAResults & getAAResults() const
AAResults & getAAResults()
A private abstract base class describing the concept of an individual alias analysis implementation.
virtual ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2, AAQueryInfo &AAQI)=0
Return information about whether two call sites may refer to the same set of memory locations.
bool canInstructionRangeModRef(const Instruction &I1, const Instruction &I2, const Value *Ptr, LocationSize Size, const ModRefInfo Mode)
A convenience wrapper synthesizing a memory location.
bool pointsToConstantMemory(const Value *P, bool OrLocal=false)
A convenience wrapper around the primary pointsToConstantMemory interface.
virtual ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool IgnoreLocals)=0
Returns a bitmask that should be unconditionally applied to the ModRef info of a memory location.
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 ...
ModRefInfo getModRefInfo(const Instruction *I, const std::optional< MemoryLocation > &OptLoc)
Check whether or not an instruction may read or write the optionally specified memory location.
virtual MemoryEffects getMemoryEffects(const CallBase *Call, AAQueryInfo &AAQI)=0
Return the behavior of the given call site.
bool doesNotAccessMemory(const Function *F)
Checks if the specified function is known to never read or write memory.
AliasResult alias(const Value *V1, const Value *V2)
A convenience wrapper around the primary alias interface.
AliasResult alias(const Value *V1, LocationSize V1Size, const Value *V2, LocationSize V2Size)
A convenience wrapper around the primary alias interface.
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are must-alias.
virtual ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)=0
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
bool doesNotAccessMemory(const CallBase *Call)
Checks if the specified call is known to never read or write memory.
bool isNoAlias(const Value *V1, LocationSize V1Size, const Value *V2, LocationSize V2Size)
A convenience wrapper around the isNoAlias helper interface.
virtual ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)=0
Get the ModRef info associated with a pointer argument of a callsite.
LLVM_ABI AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
virtual AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI, const Instruction *CtxI)=0
The main low level interface to the alias analysis implementation.
ModRefInfo getModRefInfo(const Instruction *I, const Value *P, LocationSize Size)
A convenience wrapper for constructing the memory location.
bool canBasicBlockModify(const BasicBlock &BB, const Value *P, LocationSize Size)
A convenience wrapper synthesizing a memory location.
LLVM_ABI ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, bool IgnoreLocals=false)
Returns a bitmask that should be unconditionally applied to the ModRef info of a memory location.
bool isNoAlias(const Value *V1, const Value *V2)
A convenience wrapper around the isNoAlias helper interface.
bool onlyReadsMemory(const Function *F)
Checks if the specified function is known to only read from non-volatile memory (or not access memory...
ModRefInfo callCapturesBefore(const Instruction *I, const MemoryLocation &MemLoc, DominatorTree *DT)
Return information about whether a particular call site modifies or reads the specified memory locati...
LLVM_ABI MemoryEffects getMemoryEffects(const CallBase *Call)
Return the behavior of the given call site.
bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are no-alias.
ModRefInfo getModRefInfoMask(const Value *P, bool IgnoreLocals=false)
A convenience wrapper around the primary getModRefInfoMask interface.
LLVM_ABI bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
LLVM_ABI ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
Get the ModRef info associated with a pointer argument of a call.
bool onlyReadsMemory(const CallBase *Call)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
LLVM_ABI 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)...
bool isMustAlias(const Value *V1, const Value *V2)
A convenience wrapper around the isMustAlias helper interface.
void addAAResult(AAResultT &AAResult)
Register a specific AA result.
void addAADependencyID(AnalysisKey *ID)
Register a function analysis ID that the results aggregation depends on.
virtual MemoryEffects getMemoryEffects(const Function *F)=0
Return the behavior when calling the given function.
ModRefInfo callCapturesBefore(const Instruction *I, const Value *P, LocationSize Size, DominatorTree *DT)
A convenience wrapper to synthesize a memory location.
LLVM_ABI 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.
The possible results of an alias query.
constexpr AliasResult(const Kind &Alias)
bool operator==(const AliasResult &Other) const
bool operator!=(Kind K) const
void swap(bool DoSwap=true)
Helper for processing AliasResult for swapped memory location pairs.
bool operator==(Kind K) const
@ MayAlias
The two locations may or may not alias.
@ 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.
void setOffset(int32_t NewOffset)
bool operator!=(const AliasResult &Other) const
constexpr int32_t getOffset() const
constexpr bool hasOffset() const
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
LLVM Basic Block Representation.
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)
BatchAAResults(AAResults &AAR)
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
void disableDominatorTree()
Disable the use of the dominator tree during alias analysis queries.
BatchAAResults(AAResults &AAR, CaptureAnalysis *CA)
void enableCrossIterationMode()
Assume that values may come from different cycle iterations.
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
ModRefInfo getModRefInfo(const Instruction *I, const CallBase *Call2)
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal=false)
bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
MemoryEffects getMemoryEffects(const CallBase *Call)
bool isMustAlias(const Value *V1, const Value *V2)
ModRefInfo getModRefInfo(const Instruction *I, const std::optional< MemoryLocation > &OptLoc)
bool pointsToConstantMemory(const Value *P, bool OrLocal=false)
ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, bool IgnoreLocals=false)
ModRefInfo callCapturesBefore(const Instruction *I, const MemoryLocation &MemLoc, DominatorTree *DT)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Context-sensitive CaptureAnalysis provider, which computes and caches the earliest common dominator c...
EarliestEscapeAnalysis(DominatorTree &DT, const LoopInfo *LI=nullptr)
An instruction for ordering other memory operations.
FunctionPass class - This class is used to implement most global optimizations.
ImmutablePass class - This class is used to provide information that does not need to be run.
An instruction for reading from memory.
static LocationSize precise(uint64_t Value)
bool doesNotAccessMemory() const
Whether this function accesses no memory.
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
static MemoryEffectsBase unknown()
Create MemoryEffectsBase that can read and write any memory.
Representation for a specific memory location.
static MemoryLocation getBeforeOrAfter(const Value *Ptr, const AAMDNodes &AATags=AAMDNodes())
Return a location that may access any location before or after Ptr, while remaining within the underl...
Pass interface - Implemented by all 'passes'.
A set of analyses that are preserved following a run of a transformation pass.
AAQueryInfo that uses SimpleCaptureAnalysis.
SimpleAAQueryInfo(AAResults &AAR)
Context-free CaptureAnalysis provider, which computes and caches whether an object is captured in the...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Provides information about what library functions are available for the current target.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM Value Representation.
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool isBaseOfObject(const Value *V)
Return true if we know V to the base address of the corresponding memory object.
LLVM_ABI bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
LLVM_ABI bool isNotVisibleOnUnwind(const Value *Object, bool &RequiresNoCaptureBeforeUnwind)
Return true if Object memory is not visible after an unwind, in the sense that program semantics cann...
CaptureComponents
Components of the pointer that may be captured.
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
@ ModRef
The access may reference and may modify the value stored in memory.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
LLVM_ABI bool isIdentifiedFunctionLocal(const Value *V)
Return true if V is umabigously identified at the function-level.
LLVM_ABI bool isEscapeSource(const Value *V)
Returns true if the pointer is one which would have been considered an escape by isNotCapturedBefore.
bool isNoModRef(const ModRefInfo MRI)
LLVM_ABI bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
LLVM_ABI bool isWritableObject(const Value *Object, bool &ExplicitlyDereferenceableOnly)
Return true if the Object is writable, in the sense that any location based on this pointer that can ...
LLVM_ABI 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...
Cache key for BasicAA results.
AACacheLoc(const Value *Ptr, LocationSize Size, bool MayBeCrossIteration)
AACacheLoc(PtrTy Ptr, LocationSize Size)
bool isAssumption() const
Whether this is an assumption that has not been proven yet.
bool isDefinitive() const
Whether this is a definitive (non-assumption) result.
static constexpr int Definitive
Cache entry is neither an assumption nor does it use a (non-definitive) assumption.
static constexpr int AssumptionBased
Cache entry is not an assumption itself, but may be using an assumption from higher up the stack.
int NumAssumptionUses
Number of times a NoAlias assumption has been used, 0 for assumptions that have not been used.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Virtual base class for providers of capture analysis.
virtual CaptureComponents getCapturesBefore(const Value *Object, const Instruction *I, bool OrAt)=0
Return how Object may be captured before instruction I, considering only provenance captures.
virtual ~CaptureAnalysis()=0
static AACacheLoc getEmptyKey()
static bool isEqual(const AACacheLoc &LHS, const AACacheLoc &RHS)
static unsigned getHashValue(const AACacheLoc &Val)
static AACacheLoc getTombstoneKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...
A wrapper pass for external alias analyses.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
std::function< void(Pass &, Function &, AAResults &)> CallbackT
LLVM_ABI ExternalAAWrapperPass()
bool RunEarly
Flag indicating whether this external AA should run before Basic AA.