31 assert(!AS.Forward &&
"Alias set is already forwarding!");
32 assert(!Forward &&
"This set is a forwarding set!!");
37 Volatile |= AS.Volatile;
39 if (Alias == SetMustAlias) {
44 PointerRec *L = getSomePointer();
45 PointerRec *R = AS.getSomePointer();
54 bool ASHadUnknownInsts = !AS.UnknownInsts.empty();
55 if (UnknownInsts.empty()) {
56 if (ASHadUnknownInsts) {
60 }
else if (ASHadUnknownInsts) {
61 UnknownInsts.insert(UnknownInsts.end(), AS.UnknownInsts.begin(), AS.UnknownInsts.end());
62 AS.UnknownInsts.clear();
70 *PtrListEnd = AS.PtrList;
71 AS.PtrList->setPrevInList(PtrListEnd);
72 PtrListEnd = AS.PtrListEnd;
75 AS.PtrListEnd = &AS.PtrList;
76 assert(*AS.PtrListEnd ==
nullptr &&
"End of list is not null?");
78 if (ASHadUnknownInsts)
82 void AliasSetTracker::removeAliasSet(
AliasSet *AS) {
85 AS->Forward =
nullptr;
91 assert(RefCount == 0 &&
"Cannot remove non-dead alias set from tracker!");
92 AST.removeAliasSet(
this);
97 bool KnownMustAlias) {
98 assert(!Entry.hasAliasSet() &&
"Entry already in set!");
102 if (PointerRec *
P = getSomePointer()) {
110 P->updateSizeAndAAInfo(Size, AAInfo);
111 assert(Result !=
NoAlias &&
"Cannot be part of must set!");
114 Entry.setAliasSet(
this);
115 Entry.updateSizeAndAAInfo(Size, AAInfo);
118 assert(*PtrListEnd ==
nullptr &&
"End of list is not null?");
119 *PtrListEnd = &Entry;
120 PtrListEnd = Entry.setPrevInList(PtrListEnd);
121 assert(*PtrListEnd ==
nullptr &&
"End of list is not null?");
126 if (UnknownInsts.empty())
128 UnknownInsts.emplace_back(I);
138 Access = ModRefAccess;
147 if (Alias == SetMustAlias) {
148 assert(UnknownInsts.empty() &&
"Illegal must alias set!");
152 PointerRec *SomePtr = getSomePointer();
153 assert(SomePtr &&
"Empty must-alias set??");
155 SomePtr->getAAInfo()),
167 if (!UnknownInsts.empty()) {
168 for (
unsigned i = 0, e = UnknownInsts.size(); i != e; ++i)
183 for (
unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
193 Inst,
MemoryLocation(I.getPointer(), I.getSize(), I.getAAInfo())) !=
204 I->second->eraseFromList();
217 AliasSet *AliasSetTracker::findAliasSetForPointer(
const Value *Ptr,
223 if (Cur->Forward || !Cur->aliasesPointer(Ptr, Size, AAInfo, AA))
continue;
241 if (!I->Forward && I->aliasesPointer(Ptr, Size, AAInfo, AA))
248 if (!I->Forward && I->aliasesUnknownInst(Inst, AA))
257 if (Cur->Forward || !Cur->aliasesUnknownInst(Inst, AA))
261 else if (!Cur->Forward)
275 AliasSet::PointerRec &Entry = getEntryFor(Pointer);
278 if (Entry.hasAliasSet()) {
279 Entry.updateSizeAndAAInfo(Size, AAInfo);
281 return *Entry.getAliasSet(*this)->getForwardedTarget(*
this);
284 if (
AliasSet *AS = findAliasSetForPointer(Pointer, Size, AAInfo)) {
286 AS->addPointer(*
this, Entry, Size, AAInfo);
290 if (New) *New =
true;
292 AliasSets.push_back(
new AliasSet());
293 AliasSets.back().addPointer(*
this, Entry, Size, AAInfo);
294 return AliasSets.back();
299 addPointer(Ptr, Size, AAInfo, AliasSet::NoAccess, NewPtr);
310 AliasSet::AccessLattice Access = AliasSet::RefAccess;
314 AAInfo, Access, NewPtr);
325 AliasSet::AccessLattice Access = AliasSet::ModAccess;
330 AAInfo, Access, NewPtr);
341 AliasSet::ModRefAccess, NewPtr);
347 if (isa<DbgInfoIntrinsic>(Inst))
352 AliasSet *AS = findAliasSetForUnknownInst(Inst);
354 AS->addUnknownInst(Inst, AA);
357 AliasSets.push_back(
new AliasSet());
358 AS = &AliasSets.back();
359 AS->addUnknownInst(Inst, AA);
365 if (
LoadInst *LI = dyn_cast<LoadInst>(I))
369 if (
VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
380 assert(&AA == &AST.AA &&
381 "Merging AliasSetTracker objects with different Alias Analyses!");
387 if (I->Forward)
continue;
392 for (
unsigned i = 0, e = AS.UnknownInsts.size(); i != e; ++i)
393 add(AS.UnknownInsts[i]);
398 AliasSet &NewAS = addPointer(ASI.getPointer(), ASI.getSize(),
400 (AliasSet::AccessLattice)AS.Access, X);
410 if (!AS.UnknownInsts.empty())
412 AS.UnknownInsts.clear();
415 unsigned NumRefs = 0;
416 while (!AS.
empty()) {
417 AliasSet::PointerRec *
P = AS.PtrList;
419 Value *ValToRemove = P->getValue();
428 PointerMap.
erase(ValToRemove);
432 AS.RefCount -= NumRefs;
433 if (AS.RefCount == 0)
434 AS.removeFromTracker(*
this);
439 AliasSet *AS = findAliasSetForPointer(Ptr, Size, AAInfo);
440 if (!AS)
return false;
452 if (!AS)
return false;
464 if (!AS)
return false;
475 if (!AS)
return false;
484 AliasSet *AS = findAliasSetForUnknownInst(I);
485 if (!AS)
return false;
492 if (
LoadInst *LI = dyn_cast<LoadInst>(I))
496 if (
VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
513 if (
Instruction *Inst = dyn_cast<Instruction>(PtrVal)) {
519 Cur->removeUnknownInst(*
this, Inst);
526 if (I == PointerMap.
end())
return;
529 AliasSet::PointerRec *PtrValEnt = I->second;
530 AliasSet *AS = PtrValEnt->getAliasSet(*
this);
533 PtrValEnt->eraseFromList();
549 if (I == PointerMap.
end())
551 assert(I->second->hasAliasSet() &&
"Dead entry?");
553 AliasSet::PointerRec &Entry = getEntryFor(To);
554 if (Entry.hasAliasSet())
return;
558 AliasSet *AS = I->second->getAliasSet(*
this);
559 AS->addPointer(*
this, Entry, I->second->getSize(),
560 I->second->getAAInfo(),
571 OS <<
" AliasSet[" << (
const void*)
this <<
", " << RefCount <<
"] ";
572 OS << (Alias == SetMustAlias ?
"must" :
"may") <<
" alias, ";
574 case NoAccess: OS <<
"No access ";
break;
575 case RefAccess: OS <<
"Ref ";
break;
576 case ModAccess: OS <<
"Mod ";
break;
577 case ModRefAccess: OS <<
"Mod/Ref ";
break;
582 OS <<
" forwarding to " << (
void*)Forward;
588 if (I !=
begin()) OS <<
", ";
590 OS <<
", " << I.getSize() <<
")";
593 if (!UnknownInsts.empty()) {
594 OS <<
"\n " << UnknownInsts.size() <<
" Unknown instructions: ";
595 for (
unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
597 UnknownInsts[i]->printAsOperand(OS);
604 OS <<
"Alias Set Tracker: " << AliasSets.size() <<
" alias sets for "
605 << PointerMap.
size() <<
" pointer values.\n";
611 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
620 void AliasSetTracker::ASTCallbackVH::deleted() {
621 assert(AST &&
"ASTCallbackVH called with a null AliasSetTracker!");
626 void AliasSetTracker::ASTCallbackVH::allUsesReplacedWith(
Value *V) {
633 AliasSetTracker::ASTCallbackVH &
634 AliasSetTracker::ASTCallbackVH::operator=(
Value *V) {
635 return *
this = ASTCallbackVH(V, AST);
656 bool runOnFunction(
Function &
F)
override {
661 Tracker->print(
errs());
670 "Alias Set Printer",
false,
true)
The two locations precisely alias each other.
void mergeSetIn(AliasSet &AS, AliasSetTracker &AST)
mergeSetIn - Merge the specified alias set into this alias set...
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...
bool isVolatile() const
isVolatile - Return true if this is a store to a volatile memory location.
Define an iterator for alias sets... this is just a forward iterator.
The two locations do not alias at all.
LoadInst - an instruction for reading from memory.
bool add(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo)
add methods - These methods are used to add different types of instructions to the alias sets...
print alias Alias Set Printer
AliasSet & getAliasSetForPointer(Value *P, uint64_t Size, const AAMDNodes &AAInfo, bool *New=nullptr)
getAliasSetForPointer - Return the alias set that the specified pointer lives in. ...
iterator begin()
Instruction iterator methods.
AnalysisUsage & addRequired()
inst_iterator inst_begin(Function *F)
const_iterator end() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
void initializeAliasSetPrinterPass(PassRegistry &)
void print(raw_ostream &O) const
Implement operator<< on Value.
bool aliasesPointer(const Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo, AliasAnalysis &AA) const
aliasesPointer - Return true if the specified pointer "may" (or must) alias one of the members in the...
const_iterator begin() const
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.
uint64_t getTypeStoreSize(Type *Ty)
getTypeStoreSize - Return the DataLayout store size for the given type, if known, or a conservative v...
StoreInst - an instruction for storing to memory.
bool mayReadOrWriteMemory() const
mayReadOrWriteMemory - Return true if this instruction may read or write memory.
bool remove(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo)
remove methods - These methods are used to remove all entries that might be aliased by the specified ...
bool aliasesUnknownInst(const Instruction *Inst, AliasAnalysis &AA) const
bool erase(const KeyT &Val)
LLVM Basic Block Representation.
AliasResult
The possible results of an alias query.
Represent the analysis usage information of a pass.
print alias Alias Set false
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
#define INITIALIZE_AG_DEPENDENCY(depName)
VAArgInst - This class represents the va_arg llvm instruction, which returns an argument of the speci...
virtual void deleteValue(Value *V)
Methods that clients should call when they transform the program to allow alias analyses to update th...
void print(raw_ostream &OS) const
bool mayWriteToMemory() const
mayWriteToMemory - Return true if this instruction may modify memory.
Representation for a specific memory location.
INITIALIZE_PASS_BEGIN(AliasSetPrinter,"print-alias-sets","Alias Set Printer", false, true) INITIALIZE_PASS_END(AliasSetPrinter
AtomicOrdering getOrdering() const
Returns the ordering effect of this store.
bool removeUnknown(Instruction *I)
AliasAnalysis & getAliasAnalysis() const
getAliasAnalysis - Return the underlying alias analysis object used by this tracker.
void copyValue(Value *From, Value *To)
copyValue - This method should be used whenever a preexisting value in the program is copied or clone...
virtual AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
Alias Queries...
Type * getType() const
All values are typed, get the type of this value.
ModRefResult getModRefInfo(const Instruction *I)
getModRefInfo - Return information about whether or not an instruction may read or write memory (with...
bool isVolatile() const
isVolatile - Return true if this is a load from a volatile memory location.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
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...
AtomicOrdering getOrdering() const
Returns the ordering effect of this fence.
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.
void setPreservesAll()
Set by analyses that do not transform their input at all.
void print(raw_ostream &OS) const
ilist< AliasSet >::iterator iterator
bool addUnknown(Instruction *I)
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
getAAMetadata - Fills the AAMDNodes structure with AA metadata from this instruction.
ImmutableCallSite - establish a view to a call site for examination.
iterator find_as(const LookupKeyT &Val)
Alternate version of find() which allows a different, and possibly less expensive, key type.
LLVM Value Representation.
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)
void deleteValue(Value *PtrVal)
deleteValue method - This method is used to remove a pointer value from the AliasSetTracker entirely...
bool containsPointer(const Value *P, uint64_t Size, const AAMDNodes &AAInfo) const
containsPointer - Return true if the specified location is represented by this alias set...