Go to the documentation of this file.
57 #define DEBUG_TYPE "aa"
61 STATISTIC(NumNoAlias,
"Number of NoAlias results");
62 STATISTIC(NumMayAlias,
"Number of MayAlias results");
63 STATISTIC(NumMustAlias,
"Number of MustAlias results");
81 AA->setAAResults(
this);
91 AA->setAAResults(
nullptr);
102 if (!PAC.preservedWhenStateless())
122 return alias(LocA, LocB, AAQIP);
130 for (
unsigned I = 0;
I < AAQI.
Depth; ++
I)
132 dbgs() <<
"Start " << *LocA.
Ptr <<
" @ " << LocA.
Size <<
", "
133 << *LocB.
Ptr <<
" @ " << LocB.
Size <<
"\n";
137 for (
const auto &
AA : AAs) {
138 Result =
AA->alias(LocA, LocB, AAQI);
145 for (
unsigned I = 0;
I < AAQI.
Depth; ++
I)
147 dbgs() <<
"End " << *LocA.
Ptr <<
" @ " << LocA.
Size <<
", "
148 << *LocB.
Ptr <<
" @ " << LocB.
Size <<
" = " <<
Result <<
"\n";
151 if (AAQI.
Depth == 0) {
170 for (
const auto &
AA : AAs)
171 if (
AA->pointsToConstantMemory(Loc, AAQI, OrLocal))
180 for (
const auto &
AA : AAs) {
199 if (
const auto *Call1 = dyn_cast<CallBase>(
I)) {
204 if (
I->isFenceLike())
228 for (
const auto &
AA : AAs) {
248 bool IsMustAlias =
true;
253 if (!
Arg->getType()->isPointerTy())
255 unsigned ArgIdx =
I.index();
294 for (
const auto &
AA : AAs) {
332 bool IsMustAlias =
true;
335 if (!
Arg->getType()->isPointerTy())
337 unsigned Call2ArgIdx = std::distance(Call2->
arg_begin(),
I);
383 bool IsMustAlias =
true;
386 if (!
Arg->getType()->isPointerTy())
388 unsigned Call1ArgIdx = std::distance(Call1->
arg_begin(),
I);
425 for (
const auto &
AA : AAs) {
439 for (
const auto &
AA : AAs) {
462 OS <<
"PartialAlias";
676 if (OptLoc ==
None) {
677 if (
const auto *Call = dyn_cast<CallBase>(
I)) {
684 switch (
I->getOpcode()) {
685 case Instruction::VAArg:
691 case Instruction::Fence:
693 case Instruction::AtomicCmpXchg:
695 case Instruction::AtomicRMW:
698 case Instruction::CallBr:
699 case Instruction::Invoke:
701 case Instruction::CatchPad:
703 case Instruction::CatchRet:
706 assert(!
I->mayReadOrWriteMemory() &&
707 "Unhandled memory access instruction!");
730 const auto *
Call = dyn_cast<CallBase>(
I);
731 if (!Call || Call == Object)
741 bool IsMustAlias =
true;
743 for (
auto CI =
Call->data_operands_begin(), CE =
Call->data_operands_end();
744 CI != CE; ++CI, ++ArgNo) {
748 if (!(*CI)->getType()->isPointerTy() ||
749 (!
Call->doesNotCapture(ArgNo) && ArgNo < Call->arg_size() &&
750 !
Call->isByValArgument(ArgNo)))
764 if (
Call->doesNotAccessMemory(ArgNo))
766 if (
Call->onlyReadsMemory(ArgNo)) {
794 "Instructions not in same basic block!");
837 "Function Alias Analysis Results",
false,
true)
870 new AAResults(getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F)));
877 AAR->addAAResult(getAnalysis<BasicAAWrapperPass>().getResult());
880 if (
auto *WrapperPass = getAnalysisIfAvailable<ScopedNoAliasAAWrapperPass>())
881 AAR->addAAResult(WrapperPass->getResult());
882 if (
auto *WrapperPass = getAnalysisIfAvailable<TypeBasedAAWrapperPass>())
883 AAR->addAAResult(WrapperPass->getResult());
884 if (
auto *WrapperPass =
885 getAnalysisIfAvailable<objcarc::ObjCARCAAWrapperPass>())
886 AAR->addAAResult(WrapperPass->getResult());
887 if (
auto *WrapperPass = getAnalysisIfAvailable<GlobalsAAWrapperPass>())
888 AAR->addAAResult(WrapperPass->getResult());
889 if (
auto *WrapperPass = getAnalysisIfAvailable<SCEVAAWrapperPass>())
890 AAR->addAAResult(WrapperPass->getResult());
891 if (
auto *WrapperPass = getAnalysisIfAvailable<CFLAndersAAWrapperPass>())
892 AAR->addAAResult(WrapperPass->getResult());
893 if (
auto *WrapperPass = getAnalysisIfAvailable<CFLSteensAAWrapperPass>())
894 AAR->addAAResult(WrapperPass->getResult());
898 if (
auto *WrapperPass = getAnalysisIfAvailable<ExternalAAWrapperPass>())
900 WrapperPass->CB(*
this,
F, *AAR);
927 for (
auto &Getter : ResultGetters)
941 if (
auto *WrapperPass =
946 if (
auto *WrapperPass =
957 WrapperPass->CB(
P,
F, AAR);
963 if (
const auto *Call = dyn_cast<CallBase>(V))
964 return Call->hasRetAttr(Attribute::NoAlias);
969 if (
const Argument *A = dyn_cast<Argument>(V))
970 return A->hasNoAliasAttr() || A->hasByValAttr();
975 if (isa<AllocaInst>(V))
977 if (isa<GlobalValue>(V) && !isa<GlobalAlias>(V))
991 if (
auto *CB = dyn_cast<CallBase>(V))
998 if (isa<LoadInst>(V))
1006 if (isa<IntToPtrInst>(V))
1013 bool &RequiresNoCaptureBeforeUnwind) {
1014 RequiresNoCaptureBeforeUnwind =
false;
1017 if (isa<AllocaInst>(
Object))
1021 if (
auto *A = dyn_cast<Argument>(
Object))
1022 return A->hasByValAttr();
1028 RequiresNoCaptureBeforeUnwind =
true;
void addAAResult(AAResultT &AAResult)
Register a specific AA result.
A set of analyses that are preserved following a run of a transformation pass.
@ NoModRef
The access neither references nor modifies the value stored in memory.
This class represents an incoming formal argument to a Function.
A manager for alias analyses.
@ MayAlias
The two locations may or may not alias.
@ PartialAlias
The two locations alias, but only due to a partial overlap.
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
This is an optimization pass for GlobalISel generic memory operations.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM_NODISCARD bool isModOrRefSet(const ModRefInfo MRI)
ImmutablePass class - This class is used to provide information that does not need to be run.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
const Value * Ptr
The address of the start of the location.
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Trigger the invalidation of some other analysis pass if not already handled and return whether it was...
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
FunctionPass * createAAResultsWrapperPass()
detail::enumerator< R > enumerate(R &&TheRange)
Given an input range, returns a new range whose values are are pair (A,B) such that A is the 0-based ...
AtomicOrdering getSuccessOrdering() const
Returns the success ordering constraint of this cmpxchg instruction.
LLVM_NODISCARD ModRefInfo createModRefInfo(const FunctionModRefBehavior FMRB)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
static bool isNoAliasOrByValArgument(const Value *V)
static bool onlyAccessesArgPointees(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from objects poin...
AAQueryInfo that uses SimpleCaptureInfo.
LocationSize Size
The maximum size of the location, in address-units, or UnknownSize if the size is not known.
An instruction for ordering other memory operations.
The possible results of an alias query.
Function Alias Analysis Results
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
@ FMRB_UnknownModRefBehavior
This indicates that the function could not be classified into one of the behaviors above.
void getAAResultsAnalysisUsage(AnalysisUsage &AU)
A helper for the legacy pass manager to populate AU to add uses to make sure the analyses required by...
LLVM Basic Block Representation.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isIdentifiedFunctionLocal(const Value *V)
Return true if V is umabigously identified at the function-level.
AAResults(const TargetLibraryInfo &TLI)
Legacy wrapper pass to provide the ObjCARCAAResult object.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
This class stores info we want to provide to or retain within an alias query.
@ MustRef
The access may reference the value stored in memory, a mustAlias relation was found,...
bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool onlyReadsMemory(const CallBase *Call)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
@ Ref
The access may reference the value stored in memory.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
@ MustModRef
The access may reference, modify or both the value stored in memory, a mustAlias relation was found,...
@ MustMod
The access may modify the value stored in memory, a mustAlias relation was found, and no mayAlias or ...
Represent the analysis usage information of a pass.
constexpr bool hasOffset() const
INITIALIZE_PASS_BEGIN(AAResultsWrapperPass, "aa", "Function Alias Analysis Results", false, true) INITIALIZE_PASS_END(AAResultsWrapperPass
INITIALIZE_PASS(ExternalAAWrapperPass, "external-aa", "External Alias Analysis", false, true) ImmutablePass *llvm
static bool onlyWritesMemory(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to only write memory (or not access memory ...
std::function< void(Pass &, Function &, AAResults &)> CallbackT
STATISTIC(NumFunctions, "Total number of functions")
This class implements an extremely fast bulk output stream that can only output to a stream.
Result run(Function &F, FunctionAnalysisManager &AM)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
LLVM_NODISCARD ModRefInfo clearRef(const ModRefInfo MRI)
const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value,...
API to communicate dependencies between analyses during invalidation.
LLVM_NODISCARD bool isModSet(const ModRefInfo MRI)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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...
constexpr int32_t getOffset() const
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
LLVM_NODISCARD ModRefInfo clearMod(const ModRefInfo MRI)
LLVM_NODISCARD ModRefInfo clearMust(const ModRefInfo MRI)
Legacy wrapper pass to provide the TypeBasedAAResult object.
An instruction for storing to memory.
LLVM_NODISCARD bool isNoModRef(const ModRefInfo MRI)
Legacy wrapper pass to provide the SCEVAAResult object.
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
Legacy wrapper pass to provide the BasicAAResult object.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
AtomicOrdering getOrdering() const
Returns the ordering constraint of this rmw instruction.
Legacy wrapper pass to provide the CFLAndersAAResult object.
A special type used by analysis passes to provide an address that identifies that particular analysis...
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)...
initializer< Ty > init(const Ty &Val)
LLVM_NODISCARD ModRefInfo unionModRef(const ModRefInfo MRI1, const ModRefInfo MRI2)
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...
Legacy wrapper pass to provide the CFLSteensAAResult object.
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
static MemoryLocation getForArgument(const CallBase *Call, unsigned ArgIdx, const TargetLibraryInfo *TLI)
Return a location representing a particular argument of a call.
static bool doesAccessArgPointees(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to potentially read or write from objects p...
@ FMRB_DoesNotAccessMemory
This function does not perform any non-local loads or stores to memory.
bool isEscapeSource(const Value *V)
Returns true if the pointer is one which would have been considered an escape by isNonEscapingLocalOb...
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
void initializeAAResultsWrapperPassPass(PassRegistry &)
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...
@ NoAlias
The two locations do not alias at all.
@ Mod
The access may modify the value stored in memory.
self_iterator getIterator()
LLVM_NODISCARD ModRefInfo setModAndRef(const ModRefInfo MRI)
@ MustAlias
The two locations precisely alias each other.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
TargetLibraryInfo & getTLI(const Function &F)
FunctionModRefBehavior
Summary of how a function affects memory in the program.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
This is the AA result object for the basic, local, and stateless alias analysis.
An instruction for reading from memory.
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
Return the behavior of the given call site.
static bool onlyAccessesInaccessibleOrArgMem(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from memory that ...
an instruction that atomically reads a memory location, combines it with another value,...
bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM_NODISCARD bool isMustSet(const ModRefInfo MRI)
static bool onlyAccessesInaccessibleMem(FunctionModRefBehavior MRB)
Checks if functions with the specified behavior are known to read and write at most from memory that ...
bool runOnFunction(Function &F) override
Run the wrapper pass to rebuild an aggregation over known AA passes.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
static cl::opt< bool > EnableAATrace("aa-trace", cl::Hidden, cl::init(false))
Print a trace of alias analysis queries and their results.
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 ...
Legacy wrapper pass to provide the ScopedNoAliasAAResult object.
bool isStrongerThan(AtomicOrdering AO, AtomicOrdering Other)
Returns true if ao is stronger than other as defined by the AtomicOrdering lattice,...
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
Get the ModRef info associated with a pointer argument of a call.
Pass interface - Implemented by all 'passes'.
LLVM_NODISCARD bool isRefSet(const ModRefInfo MRI)
cl::opt< bool > DisableBasicAA("disable-basic-aa", cl::Hidden, cl::init(false))
Allow disabling BasicAA from the AA results.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
const BasicBlock * getParent() const
A wrapper pass for external alias analyses.
Legacy wrapper pass to provide the GlobalsAAResult object.
bool isStrongerThanMonotonic(AtomicOrdering AO)
LLVM_NODISCARD ModRefInfo setMust(const ModRefInfo MRI)
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 callCapturesBefore(const Instruction *I, const MemoryLocation &MemLoc, DominatorTree *DT)
Return information about whether a particular call site modifies or reads the specified memory locati...
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...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
AnalysisUsage & addRequiredTransitive()
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
A container for analyses that lazily runs them and caches their results.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
FunctionPass class - This class is used to implement most global optimizations.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
AnalysisUsage & addRequired()
LLVM_NODISCARD ModRefInfo intersectModRef(const ModRefInfo MRI1, const ModRefInfo MRI2)
void initializeExternalAAWrapperPassPass(PassRegistry &)
constexpr T value_or(U &&alt) const &
bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures, bool StoreCaptures, const Instruction *I, const DominatorTree *DT, bool IncludeI=false, unsigned MaxUsesToExplore=0, const LoopInfo *LI=nullptr)
PointerMayBeCapturedBefore - Return true if this pointer value may be captured by the enclosing funct...
LLVM Value Representation.
An instruction that atomically checks whether a specified value is in a memory location,...
Analysis pass providing the TargetLibraryInfo.
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
bool isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(const CallBase *Call, bool MustPreserveNullness)
{launder,strip}.invariant.group returns pointer that aliases its argument, and it only captures point...
@ ModRef
The access may reference and may modify the value stored in memory.
Representation for a specific memory location.
InstListType::const_iterator const_iterator
unsigned Depth
Query depth used to distinguish recursive queries.