17 #include "llvm/Config/llvm-config.h" 45 cl::desc(
"The maximum number of pointers may-alias " 46 "sets may contain before degradation"));
51 assert(!AS.Forward &&
"Alias set is already forwarding!");
52 assert(!Forward &&
"This set is a forwarding set!!");
54 bool WasMustAlias = (Alias == SetMustAlias);
58 Volatile |= AS.Volatile;
60 if (Alias == SetMustAlias) {
65 PointerRec *L = getSomePointer();
66 PointerRec *R = AS.getSomePointer();
75 if (Alias == SetMayAlias) {
77 AST.TotalMayAliasSetSize +=
size();
78 if (AS.Alias == SetMustAlias)
79 AST.TotalMayAliasSetSize += AS.
size();
82 bool ASHadUnknownInsts = !AS.UnknownInsts.empty();
83 if (UnknownInsts.empty()) {
84 if (ASHadUnknownInsts) {
88 }
else if (ASHadUnknownInsts) {
89 UnknownInsts.insert(UnknownInsts.end(), AS.UnknownInsts.begin(), AS.UnknownInsts.end());
90 AS.UnknownInsts.clear();
100 *PtrListEnd = AS.PtrList;
101 AS.PtrList->setPrevInList(PtrListEnd);
102 PtrListEnd = AS.PtrListEnd;
104 AS.PtrList =
nullptr;
105 AS.PtrListEnd = &AS.PtrList;
106 assert(*AS.PtrListEnd ==
nullptr &&
"End of list is not null?");
108 if (ASHadUnknownInsts)
112 void AliasSetTracker::removeAliasSet(
AliasSet *
AS) {
115 AS->Forward =
nullptr;
118 if (AS->Alias == AliasSet::SetMayAlias)
119 TotalMayAliasSetSize -= AS->
size();
125 assert(RefCount == 0 &&
"Cannot remove non-dead alias set from tracker!");
126 AST.removeAliasSet(
this);
131 bool KnownMustAlias) {
132 assert(!Entry.hasAliasSet() &&
"Entry already in set!");
136 if (PointerRec *
P = getSomePointer()) {
143 AST.TotalMayAliasSetSize +=
size();
146 P->updateSizeAndAAInfo(Size, AAInfo);
151 Entry.setAliasSet(
this);
152 Entry.updateSizeAndAAInfo(Size, AAInfo);
156 assert(*PtrListEnd ==
nullptr &&
"End of list is not null?");
157 *PtrListEnd = &Entry;
158 PtrListEnd = Entry.setPrevInList(PtrListEnd);
159 assert(*PtrListEnd ==
nullptr &&
"End of list is not null?");
163 if (Alias == SetMayAlias)
164 AST.TotalMayAliasSetSize++;
168 if (UnknownInsts.empty())
170 UnknownInsts.emplace_back(I);
180 Access = ModRefAccess;
192 if (Alias == SetMustAlias) {
193 assert(UnknownInsts.empty() &&
"Illegal must alias set!");
197 PointerRec *SomePtr = getSomePointer();
198 assert(SomePtr &&
"Empty must-alias set??");
200 SomePtr->getAAInfo()),
212 if (!UnknownInsts.empty()) {
213 for (
unsigned i = 0, e = UnknownInsts.size(); i != e; ++i)
214 if (
auto *Inst = getUnknownInst(i))
232 for (
unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
233 if (
auto *UnknownInst = getUnknownInst(i)) {
243 Inst,
MemoryLocation(I.getPointer(), I.getSize(), I.getAAInfo()))))
253 I->second->eraseFromList();
271 if (Cur->Forward || !Cur->aliasesPointer(Ptr, Size, AAInfo, AA))
continue;
294 if (Cur->Forward || !Cur->aliasesUnknownInst(Inst, AA))
298 else if (!Cur->Forward)
309 AliasSet::PointerRec &Entry = getEntryFor(Pointer);
317 if (Entry.hasAliasSet()) {
318 Entry.updateSizeAndAAInfo(Size, AAInfo);
319 assert(Entry.getAliasSet(*
this) == AliasAnyAS &&
320 "Entry in saturated AST must belong to only alias set");
322 AliasAnyAS->addPointer(*
this, Entry, Size, AAInfo);
328 if (Entry.hasAliasSet()) {
334 if (Entry.updateSizeAndAAInfo(Size, AAInfo))
335 mergeAliasSetsForPointer(Pointer, Size, AAInfo);
337 return *Entry.getAliasSet(*this)->getForwardedTarget(*
this);
340 if (
AliasSet *AS = mergeAliasSetsForPointer(Pointer, Size, AAInfo)) {
342 AS->addPointer(*
this, Entry, Size, AAInfo);
347 AliasSets.push_back(
new AliasSet());
348 AliasSets.back().addPointer(*
this, Entry, Size, AAInfo);
349 return AliasSets.back();
354 addPointer(Ptr, Size, AAInfo, AliasSet::NoAccess);
363 AliasSet::AccessLattice Access = AliasSet::RefAccess;
376 AliasSet::AccessLattice Access = AliasSet::ModAccess;
389 AliasSet::ModRefAccess);
399 Len =
C->getZExtValue();
404 addPointer(MSI->
getRawDest(), Len, AAInfo, AliasSet::ModAccess);
406 if (MS && MS->isVolatile())
416 Len =
C->getZExtValue();
421 addPointer(MTI->
getRawSource(), Len, AAInfo, AliasSet::RefAccess);
424 addPointer(MTI->
getRawDest(), Len, AAInfo, AliasSet::ModAccess);
427 if (MT && MT->isVolatile()) {
434 if (isa<DbgInfoIntrinsic>(Inst))
437 if (
auto *II = dyn_cast<IntrinsicInst>(Inst)) {
440 switch (II->getIntrinsicID()) {
444 case Intrinsic::assume:
445 case Intrinsic::sideeffect:
452 AliasSet *AS = findAliasSetForUnknownInst(Inst);
454 AS->addUnknownInst(Inst, AA);
457 AliasSets.push_back(
new AliasSet());
458 AS = &AliasSets.back();
459 AS->addUnknownInst(Inst, AA);
464 if (
LoadInst *LI = dyn_cast<LoadInst>(I))
468 if (
VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
474 return addUnknown(I);
484 "Merging AliasSetTracker objects with different Alias Analyses!");
494 for (
unsigned i = 0, e = AS.UnknownInsts.size(); i != e; ++i)
495 if (
auto *Inst = AS.getUnknownInst(i))
501 addPointer(ASI.getPointer(), ASI.getSize(), ASI.getAAInfo(),
502 (AliasSet::AccessLattice)AS.Access);
516 if (I == PointerMap.end())
return;
519 AliasSet::PointerRec *PtrValEnt = I->second;
520 AliasSet *AS = PtrValEnt->getAliasSet(*
this);
523 PtrValEnt->eraseFromList();
525 if (AS->Alias == AliasSet::SetMayAlias) {
527 TotalMayAliasSetSize--;
544 if (I == PointerMap.end())
546 assert(I->second->hasAliasSet() &&
"Dead entry?");
548 AliasSet::PointerRec &Entry = getEntryFor(To);
549 if (Entry.hasAliasSet())
return;
552 I = PointerMap.find_as(From);
554 AliasSet *AS = I->second->getAliasSet(*
this);
555 AS->addPointer(*
this, Entry, I->second->getSize(),
556 I->second->getAAInfo(),
560 AliasSet &AliasSetTracker::mergeAllAliasSets() {
562 "Full merge should happen once, when the saturation threshold is " 567 std::vector<AliasSet *> ASVector;
570 ASVector.push_back(&*I);
574 AliasSets.push_back(
new AliasSet());
575 AliasAnyAS = &AliasSets.back();
576 AliasAnyAS->Alias = AliasSet::SetMayAlias;
577 AliasAnyAS->Access = AliasSet::ModRefAccess;
578 AliasAnyAS->AliasAny =
true;
580 for (
auto Cur : ASVector) {
584 Cur->Forward = AliasAnyAS;
585 AliasAnyAS->addRef();
586 FwdTo->dropRef(*
this);
591 AliasAnyAS->mergeSetIn(*Cur, *
this);
599 AliasSet::AccessLattice
E) {
600 AliasSet &AS = getAliasSetForPointer(P, Size, AAInfo);
606 return mergeAllAliasSets();
617 OS <<
" AliasSet[" << (
const void*)
this <<
", " << RefCount <<
"] ";
618 OS << (Alias == SetMustAlias ?
"must" :
"may") <<
" alias, ";
620 case NoAccess: OS <<
"No access ";
break;
621 case RefAccess: OS <<
"Ref ";
break;
622 case ModAccess: OS <<
"Mod ";
break;
623 case ModRefAccess: OS <<
"Mod/Ref ";
break;
628 OS <<
" forwarding to " << (
void*)Forward;
633 if (I !=
begin()) OS <<
", ";
635 OS <<
", " << I.getSize() <<
")";
638 if (!UnknownInsts.empty()) {
639 OS <<
"\n " << UnknownInsts.size() <<
" Unknown instructions: ";
640 for (
unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
642 if (
auto *I = getUnknownInst(i)) {
654 OS <<
"Alias Set Tracker: " << AliasSets.size() <<
" alias sets for " 655 << PointerMap.size() <<
" pointer values.\n";
661 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 670 void AliasSetTracker::ASTCallbackVH::deleted() {
671 assert(AST &&
"ASTCallbackVH called with a null AliasSetTracker!");
676 void AliasSetTracker::ASTCallbackVH::allUsesReplacedWith(
Value *V) {
683 AliasSetTracker::ASTCallbackVH &
684 AliasSetTracker::ASTCallbackVH::operator=(
Value *V) {
685 return *
this = ASTCallbackVH(V, AST);
710 auto &AAWP = getAnalysis<AAResultsWrapperPass>();
712 errs() <<
"Alias sets for function '" << F.
getName() <<
"':\n";
715 Tracker->print(
errs());
726 "Alias Set Printer",
false,
true)
void mergeSetIn(AliasSet &AS, AliasSetTracker &AST)
Merge the specified alias set into this alias set.
A parsed version of the target data layout string in and methods for querying it. ...
INITIALIZE_PASS_BEGIN(AliasSetPrinter, "print-alias-sets", "Alias Set Printer", false, true) INITIALIZE_PASS_END(AliasSetPrinter
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Atomic ordering constants.
Compute iterated dominance frontiers using a linear time algorithm.
Define an iterator for alias sets... this is just a forward iterator.
void add(Value *Ptr, LocationSize Size, const AAMDNodes &AAInfo)
These methods are used to add different types of instructions to the alias sets.
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"))
bool containsUnknown(const Instruction *I) const
Return true if the specified instruction "may" (or must) alias one of the members in any of the sets...
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
The two locations do not alias at all.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
This class wraps the llvm.memset intrinsic.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
block Block Frequency true
An instruction for reading from memory.
Value * getLength() const
print alias Alias Set Printer
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool isVolatile() const
Return true if this is a load from a volatile memory location.
inst_iterator inst_begin(Function *F)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void initializeAliasSetPrinterPass(PassRegistry &)
AliasSet & getAliasSetForPointer(Value *P, LocationSize Size, const AAMDNodes &AAInfo)
Return the alias set that the specified pointer lives in.
Type * getType() const
All values are typed, get the type of this value.
friend class AliasSetTracker
bool aliasesUnknownInst(const Instruction *Inst, AliasAnalysis &AA) const
An instruction for storing to memory.
bool isStrongerThanMonotonic(AtomicOrdering ao)
Value * getOperand(unsigned i) const
AliasResult
The possible results of an alias query.
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
Fills the AAMDNodes structure with AA metadata from this instruction.
static bool runOnFunction(Function &F, bool PostInlining)
initializer< Ty > init(const Ty &Val)
void print(raw_ostream &OS) const
LLVM Basic Block Representation.
AliasAnalysis & getAliasAnalysis() const
Return the underlying alias analysis object used by this tracker.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Represent the analysis usage information of a pass.
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
FunctionPass class - This class is used to implement most global optimizations.
This class represents any memset intrinsic.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
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.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Representation for a specific memory location.
The two locations precisely alias each other.
Iterator for intrusive lists based on ilist_node.
This is the shared class of boolean and integer constants.
void print(raw_ostream &OS) const
void copyValue(Value *From, Value *To)
This method should be used whenever a preexisting value in the program is copied or cloned...
Module.h This file contains the declarations for the Module class.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Value * getRawSource() const
Return the arguments to the instruction.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
void setPreservesAll()
Set by analyses that do not transform their input at all.
This class wraps the llvm.memcpy/memmove intrinsics.
bool isVolatile() const
Return true if this is a store to a volatile memory location.
AtomicOrdering getOrdering() const
Returns the ordering constraint of this store instruction.
This file provides utility analysis objects describing memory locations.
StringRef getName() const
Return a constant reference to the value's name.
Establish a view to a call site for examination.
bool isVolatile() const
Return true if this alias set contains volatile loads or stores.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
This class implements an extremely fast bulk output stream that can only output to a stream...
Value handle with callbacks on RAUW and destruction.
inst_iterator inst_end(Function *F)
bool aliasesPointer(const Value *Ptr, LocationSize Size, const AAMDNodes &AAInfo, AliasAnalysis &AA) const
Return true if the specified pointer "may" (or must) alias one of the members in the set...
LLVM_NODISCARD bool isModOrRefSet(const ModRefInfo MRI)
void addUnknown(Instruction *I)
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
Value * getRawDest() const
void deleteValue(Value *PtrVal)
This method is used to remove a pointer value from the AliasSetTracker entirely.
bool mayReadOrWriteMemory() const
Return true if this instruction may read or write memory.