53#define DEBUG_TYPE "aa"
58STATISTIC(NumMayAlias,
"Number of MayAlias results");
59STATISTIC(NumMustAlias,
"Number of MustAlias results");
76 : TLI(Arg.TLI), AAs(
std::
move(Arg.AAs)), AADeps(
std::
move(Arg.AADeps)) {}
87 if (!PAC.preservedWhenStateless())
107 return alias(LocA, LocB, AAQIP,
nullptr);
115 "Can only call alias() on pointers");
119 for (
unsigned I = 0;
I < AAQI.
Depth; ++
I)
121 dbgs() <<
"Start " << *LocA.
Ptr <<
" @ " << LocA.
Size <<
", "
122 << *LocB.
Ptr <<
" @ " << LocB.
Size <<
"\n";
126 for (
const auto &AA : AAs) {
127 Result = AA->alias(LocA, LocB, AAQI, CtxI);
134 for (
unsigned I = 0;
I < AAQI.
Depth; ++
I)
136 dbgs() <<
"End " << *LocA.
Ptr <<
" @ " << LocA.
Size <<
", "
137 << *LocB.
Ptr <<
" @ " << LocB.
Size <<
" = " << Result <<
"\n";
140 if (AAQI.
Depth == 0) {
161 for (
const auto &AA : AAs) {
162 Result &= AA->getModRefInfoMask(Loc, AAQI, IgnoreLocals);
175 for (
const auto &AA : AAs) {
176 Result &= AA->getArgModRefInfo(Call, ArgIdx);
195 if (
const auto *Call1 = dyn_cast<CallBase>(
I)) {
200 if (
I->isFenceLike())
218 for (
const auto &AA : AAs) {
219 Result &= AA->getModRefInfo(Call, Loc, AAQI);
239 for (
const auto &AA : AAs) {
240 Result &= AA->getModRefInfo(Call1, Call2, AAQI);
252 if (Call1B.doesNotAccessMemory())
256 if (Call2B.doesNotAccessMemory())
260 if (Call1B.onlyReadsMemory() && Call2B.onlyReadsMemory())
265 if (Call1B.onlyReadsMemory())
267 else if (Call1B.onlyWritesMemory())
273 if (Call2B.onlyAccessesArgPointees()) {
274 if (!Call2B.doesAccessArgPointees())
281 unsigned Call2ArgIdx = std::distance(Call2->
arg_begin(),
I);
301 R = (R | ArgMask) & Result;
311 if (Call1B.onlyAccessesArgPointees()) {
312 if (!Call1B.doesAccessArgPointees())
319 unsigned Call1ArgIdx = std::distance(Call1->
arg_begin(),
I);
330 R = (R | ArgModRefC1) & Result;
354 if (
const auto *Call2 = dyn_cast<CallBase>(I2))
366 for (
const auto &AA : AAs) {
367 Result &= AA->getMemoryEffects(Call, AAQI);
370 if (Result.doesNotAccessMemory())
385 for (
const auto &AA : AAs) {
386 Result &= AA->getMemoryEffects(
F);
389 if (Result.doesNotAccessMemory())
408 OS <<
"PartialAlias";
557 const std::optional<MemoryLocation> &OptLoc,
559 if (OptLoc == std::nullopt) {
560 if (
const auto *Call = dyn_cast<CallBase>(
I))
566 switch (
I->getOpcode()) {
567 case Instruction::VAArg:
569 case Instruction::Load:
571 case Instruction::Store:
573 case Instruction::Fence:
575 case Instruction::AtomicCmpXchg:
577 case Instruction::AtomicRMW:
579 case Instruction::Call:
580 case Instruction::CallBr:
581 case Instruction::Invoke:
583 case Instruction::CatchPad:
585 case Instruction::CatchRet:
588 assert(!
I->mayReadOrWriteMemory() &&
589 "Unhandled memory access instruction!");
612 const auto *Call = dyn_cast<CallBase>(
I);
613 if (!Call || Call == Object)
624 for (
auto CI = Call->data_operands_begin(), CE = Call->data_operands_end();
625 CI != CE; ++CI, ++ArgNo) {
629 if (!(*CI)->getType()->isPointerTy())
635 CaptureInfo Captures = Call->getCaptureInfo(ArgNo);
648 if (Call->doesNotAccessMemory(ArgNo))
650 if (Call->onlyReadsMemory(ArgNo)) {
677 "Instructions not in same basic block!");
689AAResults::Concept::~Concept() =
default;
714 "Function Alias Analysis Results",
false,
true)
740 new AAResults(getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F)));
743 auto *ExtWrapperPass = getAnalysisIfAvailable<ExternalAAWrapperPass>();
744 if (ExtWrapperPass && ExtWrapperPass->RunEarly && ExtWrapperPass->CB) {
746 << ExtWrapperPass->getPassName() <<
"\n");
747 ExtWrapperPass->CB(*
this,
F, *AAR);
756 AAR->addAAResult(getAnalysis<BasicAAWrapperPass>().getResult());
760 if (
auto *WrapperPass =
761 getAnalysisIfAvailable<ScopedNoAliasAAWrapperPass>()) {
763 AAR->addAAResult(WrapperPass->getResult());
765 if (
auto *WrapperPass = getAnalysisIfAvailable<TypeBasedAAWrapperPass>()) {
767 AAR->addAAResult(WrapperPass->getResult());
769 if (
auto *WrapperPass = getAnalysisIfAvailable<GlobalsAAWrapperPass>()) {
771 AAR->addAAResult(WrapperPass->getResult());
773 if (
auto *WrapperPass = getAnalysisIfAvailable<SCEVAAWrapperPass>()) {
775 AAR->addAAResult(WrapperPass->getResult());
780 if (ExtWrapperPass && !ExtWrapperPass->RunEarly && ExtWrapperPass->CB) {
782 << ExtWrapperPass->getPassName() <<
"\n");
783 ExtWrapperPass->CB(*
this,
F, *AAR);
808 for (
auto &Getter : ResultGetters)
814 if (
const auto *Call = dyn_cast<CallBase>(V))
815 return Call->hasRetAttr(Attribute::NoAlias);
820 if (
const Argument *
A = dyn_cast<Argument>(V))
821 return A->hasNoAliasAttr() ||
A->hasByValAttr();
826 if (isa<AllocaInst>(V))
828 if (isa<GlobalValue>(V) && !isa<GlobalAlias>(V))
846 return (isa<AllocaInst>(V) || isa<GlobalVariable>(V));
850 if (
auto *CB = dyn_cast<CallBase>(V)) {
857 return !CB->hasArgumentWithAdditionalReturnCaptureComponents();
863 if (isa<LoadInst>(V))
871 if (isa<IntToPtrInst>(V))
877 if (isa<ExtractValueInst, ExtractElementInst>(V))
881 if (
auto *CE = dyn_cast<ConstantExpr>(V))
882 if (CE->getOpcode() == Instruction::IntToPtr)
889 bool &RequiresNoCaptureBeforeUnwind) {
890 RequiresNoCaptureBeforeUnwind =
false;
893 if (isa<AllocaInst>(Object))
897 if (
auto *
A = dyn_cast<Argument>(Object))
898 return A->hasByValAttr() ||
A->hasAttribute(Attribute::DeadOnUnwind);
904 RequiresNoCaptureBeforeUnwind =
true;
914 bool &ExplicitlyDereferenceableOnly) {
915 ExplicitlyDereferenceableOnly =
false;
919 if (isa<AllocaInst>(Object))
922 if (
auto *
A = dyn_cast<Argument>(Object)) {
926 if (
A->hasAttribute(Attribute::Writable) &&
A->hasNoAliasAttr()) {
927 ExplicitlyDereferenceableOnly =
true;
931 return A->hasByValAttr();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< bool > EnableAATrace("aa-trace", cl::Hidden, cl::init(false))
Print a trace of alias analysis queries and their results.
static bool isNoAliasOrByValArgument(const Value *V)
Function Alias Analysis Results
static cl::opt< bool > DisableBasicAA("disable-basic-aa", cl::Hidden, cl::init(false))
Allow disabling BasicAA from the AA results.
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
This is the interface for LLVM's primary stateless and local alias analysis.
block Block Frequency Analysis
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static bool runOnFunction(Function &F, bool PostInlining)
This is the interface for a simple mod/ref and alias analysis over globals.
This file provides utility analysis objects describing memory locations.
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This is the interface for a SCEV-based alias analysis.
This is the interface for a metadata-based scoped no-alias analysis.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
This is the interface for a metadata-based TBAA.
A manager for alias analyses.
LLVM_ABI Result run(Function &F, FunctionAnalysisManager &AM)
This class stores info we want to provide to or retain within an alias query.
unsigned Depth
Query depth used to distinguish recursive queries.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
A private abstract base class describing the concept of an individual alias analysis implementation.
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.
LLVM_ABI AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
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.
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 AAResults(const TargetLibraryInfo &TLI)
LLVM_ABI MemoryEffects getMemoryEffects(const CallBase *Call)
Return the behavior of the given call site.
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.
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)...
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.
@ 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.
constexpr int32_t getOffset() const
constexpr bool hasOffset() const
API to communicate dependencies between analyses during invalidation.
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Trigger the invalidation of some other analysis pass if not already handled and return whether it was...
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
AnalysisUsage & addRequiredTransitive()
This class represents an incoming formal argument to a Function.
An instruction that atomically checks whether a specified value is in a memory location,...
AtomicOrdering getSuccessOrdering() const
Returns the success ordering constraint of this cmpxchg instruction.
an instruction that atomically reads a memory location, combines it with another value,...
AtomicOrdering getOrdering() const
Returns the ordering constraint of this rmw instruction.
Legacy wrapper pass to provide the BasicAAResult object.
LLVM Basic Block Representation.
InstListType::const_iterator const_iterator
const Instruction & front() const
const Instruction & back() const
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
Represents which components of the pointer may be captured in which location.
CaptureComponents getOtherComponents() const
Get components potentially captured through locations other than the return value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
An instruction for ordering other memory operations.
FunctionPass class - This class is used to implement most global optimizations.
Legacy wrapper pass to provide the GlobalsAAResult object.
ImmutablePass class - This class is used to provide information that does not need to be run.
bool mayReadOrWriteMemory() const
Return true if this instruction may read or write memory.
An instruction for reading from memory.
ModRefInfo getModRef(Location Loc) const
Get ModRefInfo for the given Location.
static MemoryEffectsBase unknown()
Create MemoryEffectsBase that can read and write any memory.
Representation for a specific memory location.
static LLVM_ABI MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
LocationSize Size
The maximum size of the location, in address-units, or UnknownSize if the size is not known.
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...
const Value * Ptr
The address of the start of the location.
static LLVM_ABI std::optional< MemoryLocation > getOrNone(const Instruction *Inst)
static LLVM_ABI MemoryLocation getForArgument(const CallBase *Call, unsigned ArgIdx, const TargetLibraryInfo *TLI)
Return a location representing a particular argument of a call.
A set of analyses that are preserved following a run of a transformation pass.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Legacy wrapper pass to provide the SCEVAAResult object.
Legacy wrapper pass to provide the ScopedNoAliasAAResult object.
AAQueryInfo that uses SimpleCaptureAnalysis.
An instruction for storing to memory.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this store instruction.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
Legacy wrapper pass to provide the TypeBasedAAResult object.
bool isPointerTy() const
True if this is an instance of PointerType.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
const ParentTy * getParent() const
self_iterator getIterator()
This class implements an extremely fast bulk output stream that can only output to a stream.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
bool isStrongerThanMonotonic(AtomicOrdering AO)
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.
LLVM_ABI bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures, 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_ABI bool isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(const CallBase *Call, bool MustPreserveNullness)
{launder,strip}.invariant.group returns pointer that aliases its argument, and it only captures point...
bool isModSet(const ModRefInfo MRI)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isModOrRefSet(const ModRefInfo MRI)
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...
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
@ Ref
The access may reference the value stored in memory.
@ ModRef
The access may reference and may modify the value stored in memory.
@ Mod
The access may modify the value stored in memory.
@ NoModRef
The access neither references nor modifies 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.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool isEscapeSource(const Value *V)
Returns true if the pointer is one which would have been considered an escape by isNotCapturedBefore.
bool capturesAnything(CaptureComponents CC)
LLVM_ABI const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=MaxLookupSearchDepth)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
bool isNoModRef(const ModRefInfo MRI)
LLVM_ABI bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
bool capturesAnyProvenance(CaptureComponents CC)
bool isStrongerThan(AtomicOrdering AO, AtomicOrdering Other)
Returns true if ao is stronger than other as defined by the AtomicOrdering lattice,...
bool isRefSet(const ModRefInfo MRI)
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...
Implement std::hash so that hash_code can be used in STL containers.
A special type used by analysis passes to provide an address that identifies that particular analysis...
A wrapper pass for external alias analyses.
std::function< void(Pass &, Function &, AAResults &)> CallbackT
LLVM_ABI ExternalAAWrapperPass()