19#include "llvm/Config/llvm-config.h"
39 cl::desc(
"The maximum total number of memory locations alias "
40 "sets may contain before degradation"));
45 assert(!AS.Forward &&
"Alias set is already forwarding!");
46 assert(!Forward &&
"This set is a forwarding set!!");
52 if (Alias == SetMustAlias) {
57 return BatchAA.isMustAlias(MemLoc, ASMemLoc);
64 if (MemoryLocs.empty()) {
68 AS.MemoryLocs.clear();
71 bool ASHadUnknownInsts = !AS.UnknownInsts.empty();
72 if (UnknownInsts.empty()) {
73 if (ASHadUnknownInsts) {
77 }
else if (ASHadUnknownInsts) {
79 AS.UnknownInsts.clear();
85 if (ASHadUnknownInsts)
89void AliasSetTracker::removeAliasSet(
AliasSet *AS) {
92 AS->Forward =
nullptr;
94 TotalAliasSetSize -= AS->
size();
99 if (AS == AliasAnyAS) {
100 AliasAnyAS =
nullptr;
101 assert(AliasSets.empty() &&
"Tracker not empty");
106 assert(RefCount == 0 &&
"Cannot remove non-dead alias set from tracker!");
107 AST.removeAliasSet(
this);
112 bool KnownMustAlias) {
123 MemoryLocs.push_back(MemLoc);
125 AST.TotalAliasSetSize++;
129 if (UnknownInsts.empty())
131 UnknownInsts.emplace_back(
I);
135 using namespace PatternMatch;
136 bool MayWriteMemory =
I->mayWriteToMemory() && !
isGuard(
I) &&
137 !(
I->use_empty() &&
match(
I, m_Intrinsic<Intrinsic::invariant_start>()));
138 if (!MayWriteMemory) {
146 Access = ModRefAccess;
159 for (
const auto &ASMemLoc : MemoryLocs) {
183 const auto *C1 = dyn_cast<CallBase>(UnknownInst);
184 const auto *C2 = dyn_cast<CallBase>(Inst);
193 for (
const auto &ASMemLoc : MemoryLocs) {
220AliasSet *AliasSetTracker::mergeAliasSetsForMemoryLocation(
240 MustAliasAll =
false;
277 collapseForwardingIn(MapEntry);
283 bool MustAliasAll =
false;
291 }
else if (
AliasSet *AliasAS = mergeAliasSetsForMemoryLocation(
292 MemLoc, MapEntry, MustAliasAll)) {
297 AliasSets.push_back(AS =
new AliasSet());
302 AS->addMemoryLocation(*
this, MemLoc, MustAliasAll);
306 collapseForwardingIn(MapEntry);
307 assert(MapEntry == AS &&
"Memory locations with same pointer value cannot "
308 "be in different alias sets");
317 addMemoryLocation(Loc, AliasSet::NoAccess);
346 if (isa<DbgInfoIntrinsic>(Inst))
349 if (
auto *
II = dyn_cast<IntrinsicInst>(Inst)) {
352 switch (
II->getIntrinsicID()) {
356 case Intrinsic::allow_runtime_check:
357 case Intrinsic::allow_ubsan_check:
358 case Intrinsic::assume:
359 case Intrinsic::experimental_noalias_scope_decl:
360 case Intrinsic::sideeffect:
361 case Intrinsic::pseudoprobe:
368 if (
AliasSet *AS = findAliasSetForUnknownInst(Inst)) {
369 AS->addUnknownInst(Inst, AA);
372 AliasSets.push_back(
new AliasSet());
373 AliasSets.back().addUnknownInst(Inst, AA);
378 if (
LoadInst *LI = dyn_cast<LoadInst>(
I))
390 if (
auto *Call = dyn_cast<CallBase>(
I))
391 if (Call->onlyAccessesArgMemory()) {
394 return AliasSet::ModRefAccess;
396 return AliasSet::ModAccess;
398 return AliasSet::RefAccess;
400 return AliasSet::NoAccess;
408 using namespace PatternMatch;
409 if (Call->use_empty() &&
410 match(Call, m_Intrinsic<Intrinsic::invariant_start>()))
413 for (
auto IdxArgPair :
enumerate(Call->args())) {
414 int ArgIdx = IdxArgPair.index();
415 const Value *Arg = IdxArgPair.value();
423 addMemoryLocation(ArgLoc, getAccessFromModRef(ArgMask));
438 "Merging AliasSetTracker objects with different Alias Analyses!");
453 addMemoryLocation(ASMemLoc, (AliasSet::AccessLattice)AS.Access);
457AliasSet &AliasSetTracker::mergeAllAliasSets() {
459 "Full merge should happen once, when the saturation threshold is "
464 std::vector<AliasSet *> ASVector;
467 ASVector.push_back(&AS);
471 AliasSets.push_back(
new AliasSet());
472 AliasAnyAS = &AliasSets.back();
473 AliasAnyAS->Alias = AliasSet::SetMayAlias;
474 AliasAnyAS->Access = AliasSet::ModRefAccess;
475 AliasAnyAS->AliasAny =
true;
477 for (
auto *Cur : ASVector) {
481 Cur->Forward = AliasAnyAS;
482 AliasAnyAS->addRef();
483 FwdTo->dropRef(*
this);
495 AliasSet::AccessLattice E) {
502 return mergeAllAliasSets();
513 OS <<
" AliasSet[" << (
const void*)
this <<
", " << RefCount <<
"] ";
514 OS << (Alias == SetMustAlias ?
"must" :
"may") <<
" alias, ";
516 case NoAccess:
OS <<
"No access ";
break;
517 case RefAccess:
OS <<
"Ref ";
break;
518 case ModAccess:
OS <<
"Mod ";
break;
519 case ModRefAccess:
OS <<
"Mod/Ref ";
break;
523 OS <<
" forwarding to " << (
void*)Forward;
525 if (!MemoryLocs.empty()) {
527 OS <<
"Memory locations: ";
532 OS <<
", unknown after)";
534 OS <<
", unknown before-or-after)";
536 OS <<
", " << MemLoc.
Size <<
")";
539 if (!UnknownInsts.empty()) {
541 OS <<
"\n " << UnknownInsts.size() <<
" Unknown instructions: ";
545 I->printAsOperand(
OS);
554 OS <<
"Alias Set Tracker: " << AliasSets.size();
556 OS <<
" (Saturated)";
557 OS <<
" alias sets for " << PointerMap.
size() <<
" pointer values.\n";
563#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
579 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 total number of memory locations alias " "sets may contain before degradation"))
Expand Atomic instructions
Atomic ordering constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This header defines various interfaces for pass management in LLVM.
This file provides utility analysis objects describing memory locations.
uint64_t IntrinsicInst * II
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
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(const MemoryLocation &Loc)
These methods are used to add different types of instructions to the alias sets.
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 aliasesMemoryLocation(const MemoryLocation &MemLoc, BatchAAResults &AA) const
If the specified memory location "may" (or must) alias one of the members in the set return the appro...
PointerVector getPointers() const
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)
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.
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.
Vector takeVector()
Clear the SetVector and return the underlying vector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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.
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
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 tuples (A, B,...
bool isStrongerThanMonotonic(AtomicOrdering AO)
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
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 any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
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 is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
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.