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 (
auto *
II = dyn_cast<IntrinsicInst>(Inst)) {
349 switch (
II->getIntrinsicID()) {
353 case Intrinsic::allow_runtime_check:
354 case Intrinsic::allow_ubsan_check:
355 case Intrinsic::assume:
356 case Intrinsic::experimental_noalias_scope_decl:
357 case Intrinsic::sideeffect:
358 case Intrinsic::pseudoprobe:
365 if (
AliasSet *AS = findAliasSetForUnknownInst(Inst)) {
366 AS->addUnknownInst(Inst, AA);
369 AliasSets.push_back(
new AliasSet());
370 AliasSets.back().addUnknownInst(Inst, AA);
375 if (
LoadInst *LI = dyn_cast<LoadInst>(
I))
387 if (
auto *Call = dyn_cast<CallBase>(
I))
388 if (Call->onlyAccessesArgMemory()) {
391 return AliasSet::ModRefAccess;
393 return AliasSet::ModAccess;
395 return AliasSet::RefAccess;
397 return AliasSet::NoAccess;
405 using namespace PatternMatch;
406 if (Call->use_empty() &&
407 match(Call, m_Intrinsic<Intrinsic::invariant_start>()))
410 for (
auto IdxArgPair :
enumerate(Call->args())) {
411 int ArgIdx = IdxArgPair.index();
412 const Value *Arg = IdxArgPair.value();
420 addMemoryLocation(ArgLoc, getAccessFromModRef(ArgMask));
435 "Merging AliasSetTracker objects with different Alias Analyses!");
450 addMemoryLocation(ASMemLoc, (AliasSet::AccessLattice)AS.Access);
454AliasSet &AliasSetTracker::mergeAllAliasSets() {
456 "Full merge should happen once, when the saturation threshold is "
461 std::vector<AliasSet *> ASVector;
464 ASVector.push_back(&AS);
468 AliasSets.push_back(
new AliasSet());
469 AliasAnyAS = &AliasSets.back();
470 AliasAnyAS->Alias = AliasSet::SetMayAlias;
471 AliasAnyAS->Access = AliasSet::ModRefAccess;
472 AliasAnyAS->AliasAny =
true;
474 for (
auto *Cur : ASVector) {
478 Cur->Forward = AliasAnyAS;
479 AliasAnyAS->addRef();
480 FwdTo->dropRef(*
this);
492 AliasSet::AccessLattice E) {
499 return mergeAllAliasSets();
510 OS <<
" AliasSet[" << (
const void*)
this <<
", " << RefCount <<
"] ";
511 OS << (Alias == SetMustAlias ?
"must" :
"may") <<
" alias, ";
513 case NoAccess:
OS <<
"No access ";
break;
514 case RefAccess:
OS <<
"Ref ";
break;
515 case ModAccess:
OS <<
"Mod ";
break;
516 case ModRefAccess:
OS <<
"Mod/Ref ";
break;
520 OS <<
" forwarding to " << (
void*)Forward;
522 if (!MemoryLocs.empty()) {
524 OS <<
"Memory locations: ";
529 OS <<
", unknown after)";
531 OS <<
", unknown before-or-after)";
533 OS <<
", " << MemLoc.
Size <<
")";
536 if (!UnknownInsts.empty()) {
538 OS <<
"\n " << UnknownInsts.size() <<
" Unknown instructions: ";
542 I->printAsOperand(
OS);
551 OS <<
"Alias Set Tracker: " << AliasSets.size();
553 OS <<
" (Saturated)";
554 OS <<
" alias sets for " << PointerMap.
size() <<
" pointer values.\n";
560#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
576 OS <<
"Alias sets for function '" <<
F.getName() <<
"':\n";
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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
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.
LLVM_ABI void dump() const
BatchAAResults & getAliasAnalysis() const
Return the underlying alias analysis object used by this tracker.
LLVM_ABI AliasSet & getAliasSetFor(const MemoryLocation &MemLoc)
Return the alias set which contains the specified memory location.
LLVM_ABI void addUnknown(Instruction *I)
LLVM_ABI void print(raw_ostream &OS) const
LLVM_ABI void add(const MemoryLocation &Loc)
These methods are used to add different types of instructions to the alias sets.
LLVM_ABI void mergeSetIn(AliasSet &AS, AliasSetTracker &AST, BatchAAResults &BatchAA)
Merge the specified alias set into this alias set.
LLVM_ABI void print(raw_ostream &OS) const
LLVM_ABI ModRefInfo aliasesUnknownInst(const Instruction *Inst, BatchAAResults &AA) const
LLVM_ABI 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...
LLVM_ABI PointerVector getPointers() const
LLVM_ABI void dump() const
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM_ABI 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 LLVM_ABI MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
static LLVM_ABI 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 LLVM_ABI MemoryLocation getForDest(const MemIntrinsic *MI)
Return a location representing the destination of a memory set or transfer.
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.
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.
LLVM_ABI 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)
LLVM_ABI 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.