18#include "llvm/Config/llvm-config.h"
40 cl::desc(
"The maximum number of pointers may-alias "
41 "sets may contain before degradation"));
46 assert(!AS.Forward &&
"Alias set is already forwarding!");
47 assert(!Forward &&
"This set is a forwarding set!!");
49 bool WasMustAlias = (Alias == SetMustAlias);
54 if (Alias == SetMustAlias) {
58 PointerRec *L = getSomePointer();
59 PointerRec *R = AS.getSomePointer();
68 if (Alias == SetMayAlias) {
70 AST.TotalMayAliasSetSize +=
size();
71 if (AS.Alias == SetMustAlias)
72 AST.TotalMayAliasSetSize += AS.
size();
75 bool ASHadUnknownInsts = !AS.UnknownInsts.empty();
76 if (UnknownInsts.empty()) {
77 if (ASHadUnknownInsts) {
81 }
else if (ASHadUnknownInsts) {
83 AS.UnknownInsts.clear();
93 *PtrListEnd = AS.PtrList;
94 AS.PtrList->setPrevInList(PtrListEnd);
95 PtrListEnd = AS.PtrListEnd;
98 AS.PtrListEnd = &AS.PtrList;
99 assert(*AS.PtrListEnd ==
nullptr &&
"End of list is not null?");
101 if (ASHadUnknownInsts)
105void AliasSetTracker::removeAliasSet(
AliasSet *AS) {
108 AS->Forward =
nullptr;
110 if (AS->Alias == AliasSet::SetMayAlias)
111 TotalMayAliasSetSize -= AS->
size();
116 if (AS == AliasAnyAS) {
117 AliasAnyAS =
nullptr;
118 assert(AliasSets.empty() &&
"Tracker not empty");
123 assert(RefCount == 0 &&
"Cannot remove non-dead alias set from tracker!");
124 AST.removeAliasSet(
this);
129 bool KnownMustAlias,
bool SkipSizeUpdate) {
130 assert(!Entry.hasAliasSet() &&
"Entry already in set!");
134 if (PointerRec *
P = getSomePointer()) {
135 if (!KnownMustAlias) {
142 AST.TotalMayAliasSetSize +=
size();
145 }
else if (!SkipSizeUpdate)
146 P->updateSizeAndAAInfo(
Size, AAInfo);
149 Entry.setAliasSet(
this);
150 Entry.updateSizeAndAAInfo(
Size, AAInfo);
154 assert(*PtrListEnd ==
nullptr &&
"End of list is not null?");
155 *PtrListEnd = &Entry;
156 PtrListEnd = Entry.setPrevInList(PtrListEnd);
157 assert(*PtrListEnd ==
nullptr &&
"End of list is not null?");
161 if (Alias == SetMayAlias)
162 AST.TotalMayAliasSetSize++;
166 if (UnknownInsts.empty())
168 UnknownInsts.emplace_back(
I);
172 using namespace PatternMatch;
173 bool MayWriteMemory =
I->mayWriteToMemory() && !
isGuard(
I) &&
174 !(
I->use_empty() &&
match(
I, m_Intrinsic<Intrinsic::invariant_start>()));
175 if (!MayWriteMemory) {
183 Access = ModRefAccess;
196 if (Alias == SetMustAlias) {
197 assert(UnknownInsts.empty() &&
"Illegal must alias set!");
201 PointerRec *SomePtr = getSomePointer();
202 assert(SomePtr &&
"Empty must-alias set??");
204 SomePtr->getAAInfo()),
219 if (!UnknownInsts.empty()) {
239 const auto *C1 = dyn_cast<CallBase>(UnknownInst);
240 const auto *C2 = dyn_cast<CallBase>(Inst);
261 for (
auto &
I : PointerMap)
262 I.second->eraseFromList();
277 bool &MustAliasAll) {
289 MustAliasAll =
false;
325 AliasSet::PointerRec &Entry = getEntryFor(Pointer);
333 if (Entry.hasAliasSet()) {
334 Entry.updateSizeAndAAInfo(
Size, AAInfo);
335 assert(Entry.getAliasSet(*
this) == AliasAnyAS &&
336 "Entry in saturated AST must belong to only alias set");
338 AliasAnyAS->addPointer(*
this, Entry,
Size, AAInfo);
343 bool MustAliasAll =
false;
345 if (Entry.hasAliasSet()) {
351 if (Entry.updateSizeAndAAInfo(
Size, AAInfo))
352 mergeAliasSetsForPointer(Pointer,
Size, AAInfo, MustAliasAll);
354 return *Entry.getAliasSet(*this)->getForwardedTarget(*
this);
358 mergeAliasSetsForPointer(Pointer,
Size, AAInfo, MustAliasAll)) {
360 AS->addPointer(*
this, Entry,
Size, AAInfo, MustAliasAll);
365 AliasSets.push_back(
new AliasSet());
366 AliasSets.back().addPointer(*
this, Entry,
Size, AAInfo,
true);
367 return AliasSets.back();
401 if (isa<DbgInfoIntrinsic>(Inst))
404 if (
auto *II = dyn_cast<IntrinsicInst>(Inst)) {
407 switch (II->getIntrinsicID()) {
411 case Intrinsic::assume:
412 case Intrinsic::experimental_noalias_scope_decl:
413 case Intrinsic::sideeffect:
414 case Intrinsic::pseudoprobe:
421 if (
AliasSet *AS = findAliasSetForUnknownInst(Inst)) {
422 AS->addUnknownInst(Inst, AA);
425 AliasSets.push_back(
new AliasSet());
426 AliasSets.back().addUnknownInst(Inst, AA);
431 if (
LoadInst *LI = dyn_cast<LoadInst>(
I))
443 if (
auto *Call = dyn_cast<CallBase>(
I))
444 if (Call->onlyAccessesArgMemory()) {
447 return AliasSet::ModRefAccess;
449 return AliasSet::ModAccess;
451 return AliasSet::RefAccess;
453 return AliasSet::NoAccess;
461 using namespace PatternMatch;
462 if (Call->use_empty() &&
463 match(Call, m_Intrinsic<Intrinsic::invariant_start>()))
466 for (
auto IdxArgPair :
enumerate(Call->args())) {
467 int ArgIdx = IdxArgPair.index();
468 const Value *Arg = IdxArgPair.value();
476 addPointer(ArgLoc, getAccessFromModRef(ArgMask));
491 "Merging AliasSetTracker objects with different Alias Analyses!");
508 (AliasSet::AccessLattice)AS.Access);
512AliasSet &AliasSetTracker::mergeAllAliasSets() {
514 "Full merge should happen once, when the saturation threshold is "
519 std::vector<AliasSet *> ASVector;
522 ASVector.push_back(&AS);
526 AliasSets.push_back(
new AliasSet());
527 AliasAnyAS = &AliasSets.back();
528 AliasAnyAS->Alias = AliasSet::SetMayAlias;
529 AliasAnyAS->Access = AliasSet::ModRefAccess;
530 AliasAnyAS->AliasAny =
true;
532 for (
auto *Cur : ASVector) {
536 Cur->Forward = AliasAnyAS;
537 AliasAnyAS->addRef();
538 FwdTo->dropRef(*
this);
550 AliasSet::AccessLattice
E) {
557 return mergeAllAliasSets();
568 OS <<
" AliasSet[" << (
const void*)
this <<
", " << RefCount <<
"] ";
569 OS << (Alias == SetMustAlias ?
"must" :
"may") <<
" alias, ";
571 case NoAccess:
OS <<
"No access ";
break;
572 case RefAccess:
OS <<
"Ref ";
break;
573 case ModAccess:
OS <<
"Mod ";
break;
574 case ModRefAccess:
OS <<
"Mod/Ref ";
break;
578 OS <<
" forwarding to " << (
void*)Forward;
584 I.getPointer()->printAsOperand(
OS <<
"(");
586 OS <<
", unknown after)";
588 OS <<
", unknown before-or-after)";
590 OS <<
", " <<
I.getSize() <<
")";
593 if (!UnknownInsts.empty()) {
595 OS <<
"\n " << UnknownInsts.size() <<
" Unknown instructions: ";
599 I->printAsOperand(
OS);
608 OS <<
"Alias Set Tracker: " << AliasSets.size();
610 OS <<
" (Saturated)";
611 OS <<
" alias sets for " << PointerMap.
size() <<
" pointer values.\n";
617#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
633 OS <<
"Alias sets for function '" <<
F.getName() <<
"':\n";
unsigned const MachineRegisterInfo * MRI
static cl::opt< unsigned > SaturationThreshold("alias-set-saturation-threshold", cl::Hidden, cl::init(250), cl::desc("The maximum number of pointers may-alias " "sets may contain before degradation"))
Atomic ordering constants.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Select target instructions out of generic instructions
This file provides utility analysis objects describing memory locations.
This header defines various interfaces for pass management in LLVM.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A manager for alias analyses.
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.
@ MustAlias
The two locations precisely alias each other.
BatchAAResults & getAliasAnalysis() const
Return the underlying alias analysis object used by this tracker.
AliasSet & getAliasSetFor(const MemoryLocation &MemLoc)
Return the alias set which contains the specified memory location.
void addUnknown(Instruction *I)
void print(raw_ostream &OS) const
void add(Value *Ptr, LocationSize Size, const AAMDNodes &AAInfo)
These methods are used to add different types of instructions to the alias sets.
Define an iterator for alias sets... this is just a forward iterator.
void mergeSetIn(AliasSet &AS, AliasSetTracker &AST, BatchAAResults &BatchAA)
Merge the specified alias set into this alias set.
void print(raw_ostream &OS) const
ModRefInfo aliasesUnknownInst(const Instruction *Inst, BatchAAResults &AA) const
AliasResult aliasesPointer(const Value *Ptr, LocationSize Size, const AAMDNodes &AAInfo, BatchAAResults &AA) const
If the specified pointer "may" (or must) alias one of the members in the set return the appropriate A...
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
AliasSetsPrinterPass(raw_ostream &OS)
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.
This class represents any memset intrinsic.
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)
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
MemoryEffects getMemoryEffects(const CallBase *Call)
ModRefInfo getModRefInfo(const Instruction *I, const std::optional< MemoryLocation > &OptLoc)
bool mayReadOrWriteMemory() const
Return true if this instruction may read or write memory.
An instruction for reading from memory.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
static constexpr LocationSize beforeOrAfterPointer()
Any location before or after the base pointer (but still within the underlying object).
static constexpr LocationSize afterPointer()
Any location after the base pointer (but still within the underlying object).
ModRefInfo getModRef(Location Loc) const
Get ModRefInfo for the given Location.
Representation for a specific memory location.
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
static MemoryLocation getForSource(const MemTransferInst *MTI)
Return a location representing the source of a memory transfer.
LocationSize Size
The maximum size of the location, in address-units, or UnknownSize if the size is not known.
AAMDNodes AATags
The metadata nodes which describes the aliasing of the location (each member is null if that kind of ...
const Value * Ptr
The address of the start of the location.
static MemoryLocation getForDest(const MemIntrinsic *MI)
Return a location representing the destination of a memory set or transfer.
static 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.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
An instruction for storing to memory.
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.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool match(Val *V, const Pattern &P)
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
bool isStrongerThanMonotonic(AtomicOrdering AO)
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
bool isGuard(const User *U)
Returns true iff U has semantics of a guard expressed in a form of call of llvm.experimental....
bool isModSet(const ModRefInfo MRI)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isModOrRefSet(const ModRefInfo MRI)
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.
@ NoModRef
The access neither references nor modifies the value stored in memory.
bool isModAndRefSet(const ModRefInfo MRI)
bool isNoModRef(const ModRefInfo MRI)
bool isRefSet(const ModRefInfo MRI)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...