32 assert(!AS.Forward &&
"Alias set is already forwarding!");
33 assert(!Forward &&
"This set is a forwarding set!!");
36 AccessTy |= AS.AccessTy;
37 AliasTy |= AS.AliasTy;
38 Volatile |= AS.Volatile;
40 if (AliasTy == MustAlias) {
45 PointerRec *L = getSomePointer();
46 PointerRec *R = AS.getSomePointer();
59 if (UnknownInsts.empty()) {
60 if (!AS.UnknownInsts.empty())
62 }
else if (!AS.UnknownInsts.empty()) {
63 UnknownInsts.insert(UnknownInsts.end(), AS.UnknownInsts.begin(), AS.UnknownInsts.end());
64 AS.UnknownInsts.clear();
72 *PtrListEnd = AS.PtrList;
73 AS.PtrList->setPrevInList(PtrListEnd);
74 PtrListEnd = AS.PtrListEnd;
77 AS.PtrListEnd = &AS.PtrList;
78 assert(*AS.PtrListEnd == 0 &&
"End of list is not null?");
82 void AliasSetTracker::removeAliasSet(
AliasSet *AS) {
91 assert(RefCount == 0 &&
"Cannot remove non-dead alias set from tracker!");
92 AST.removeAliasSet(
this);
96 uint64_t Size,
const MDNode *TBAAInfo,
97 bool KnownMustAlias) {
98 assert(!Entry.hasAliasSet() &&
"Entry already in set!");
102 if (PointerRec *
P = getSomePointer()) {
111 P->updateSizeAndTBAAInfo(Size, TBAAInfo);
115 Entry.setAliasSet(
this);
116 Entry.updateSizeAndTBAAInfo(Size, TBAAInfo);
119 assert(*PtrListEnd == 0 &&
"End of list is not null?");
120 *PtrListEnd = &Entry;
121 PtrListEnd = Entry.setPrevInList(PtrListEnd);
122 assert(*PtrListEnd == 0 &&
"End of list is not null?");
127 UnknownInsts.push_back(I);
146 if (AliasTy == MustAlias) {
147 assert(UnknownInsts.empty() &&
"Illegal must alias set!");
151 PointerRec *SomePtr = getSomePointer();
152 assert(SomePtr &&
"Empty must-alias set??");
155 SomePtr->getTBAAInfo()),
168 if (!UnknownInsts.empty()) {
169 for (
unsigned i = 0, e = UnknownInsts.size(); i != e; ++i)
183 for (
unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
184 CallSite C1 = getUnknownInst(i), C2 = Inst;
205 I->second->eraseFromList();
218 AliasSet *AliasSetTracker::findAliasSetForPointer(
const Value *Ptr,
223 if (I->Forward || !I->aliasesPointer(Ptr, Size, TBAAInfo, AA))
continue;
239 const MDNode *TBAAInfo)
const {
241 if (!I->Forward && I->aliasesPointer(Ptr, Size, TBAAInfo, AA))
251 if (I->Forward || !I->aliasesUnknownInst(Inst, AA))
256 else if (!I->Forward)
270 AliasSet::PointerRec &Entry = getEntryFor(Pointer);
273 if (Entry.hasAliasSet()) {
274 Entry.updateSizeAndTBAAInfo(Size, TBAAInfo);
276 return *Entry.getAliasSet(*this)->getForwardedTarget(*
this);
279 if (
AliasSet *AS = findAliasSetForPointer(Pointer, Size, TBAAInfo)) {
281 AS->addPointer(*
this, Entry, Size, TBAAInfo);
285 if (New) *New =
true;
287 AliasSets.push_back(
new AliasSet());
288 AliasSets.back().addPointer(*
this, Entry, Size, TBAAInfo);
289 return AliasSets.back();
294 addPointer(Ptr, Size, TBAAInfo, AliasSet::NoModRef, NewPtr);
301 AliasSet::AccessType ATy = AliasSet::Refs;
313 AliasSet::AccessType ATy = AliasSet::Mods;
328 AliasSet::ModRef, NewPtr);
334 if (isa<DbgInfoIntrinsic>(Inst))
339 AliasSet *AS = findAliasSetForUnknownInst(Inst);
341 AS->addUnknownInst(Inst, AA);
344 AliasSets.push_back(
new AliasSet());
345 AS = &AliasSets.back();
346 AS->addUnknownInst(Inst, AA);
354 if (
StoreInst *SI = dyn_cast<StoreInst>(I))
356 if (
VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
367 assert(&AA == &AST.AA &&
368 "Merging AliasSetTracker objects with different Alias Analyses!");
374 if (I->Forward)
continue;
379 for (
unsigned i = 0, e = AS.UnknownInsts.size(); i != e; ++i)
380 add(AS.UnknownInsts[i]);
385 AliasSet &NewAS = addPointer(ASI.getPointer(), ASI.getSize(),
387 (AliasSet::AccessType)AS.AccessTy, X);
397 AS.UnknownInsts.clear();
400 unsigned NumRefs = 0;
401 while (!AS.
empty()) {
402 AliasSet::PointerRec *
P = AS.PtrList;
404 Value *ValToRemove = P->getValue();
413 PointerMap.
erase(ValToRemove);
417 AS.RefCount -= NumRefs;
418 if (AS.RefCount == 0)
419 AS.removeFromTracker(*
this);
424 AliasSet *AS = findAliasSetForPointer(Ptr, Size, TBAAInfo);
425 if (!AS)
return false;
434 if (!AS)
return false;
443 if (!AS)
return false;
452 if (!AS)
return false;
461 AliasSet *AS = findAliasSetForUnknownInst(I);
462 if (!AS)
return false;
471 if (
StoreInst *SI = dyn_cast<StoreInst>(I))
473 if (
VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
490 if (
Instruction *Inst = dyn_cast<Instruction>(PtrVal)) {
494 if (I->Forward)
continue;
496 I->removeUnknownInst(Inst);
503 if (I == PointerMap.
end())
return;
506 AliasSet::PointerRec *PtrValEnt = I->second;
507 AliasSet *AS = PtrValEnt->getAliasSet(*
this);
510 PtrValEnt->eraseFromList();
529 if (I == PointerMap.
end())
531 assert(I->second->hasAliasSet() &&
"Dead entry?");
533 AliasSet::PointerRec &Entry = getEntryFor(To);
534 if (Entry.hasAliasSet())
return;
538 AliasSet *AS = I->second->getAliasSet(*
this);
539 AS->addPointer(*
this, Entry, I->second->getSize(),
540 I->second->getTBAAInfo(),
551 OS <<
" AliasSet[" << (
const void*)
this <<
", " << RefCount <<
"] ";
552 OS << (AliasTy == MustAlias ?
"must" :
"may") <<
" alias, ";
554 case NoModRef: OS <<
"No access ";
break;
555 case Refs : OS <<
"Ref ";
break;
556 case Mods : OS <<
"Mod ";
break;
557 case ModRef : OS <<
"Mod/Ref ";
break;
562 OS <<
" forwarding to " << (
void*)Forward;
568 if (I !=
begin()) OS <<
", ";
570 OS <<
", " << I.getSize() <<
")";
573 if (!UnknownInsts.empty()) {
574 OS <<
"\n " << UnknownInsts.size() <<
" Unknown instructions: ";
575 for (
unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
584 OS <<
"Alias Set Tracker: " << AliasSets.size() <<
" alias sets for "
585 << PointerMap.
size() <<
" pointer values.\n";
591 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
600 void AliasSetTracker::ASTCallbackVH::deleted() {
601 assert(AST &&
"ASTCallbackVH called with a null AliasSetTracker!");
606 void AliasSetTracker::ASTCallbackVH::allUsesReplacedWith(
Value *V) {
613 AliasSetTracker::ASTCallbackVH &
614 AliasSetTracker::ASTCallbackVH::operator=(
Value *V) {
615 return *
this = ASTCallbackVH(V, AST);
636 virtual bool runOnFunction(
Function &
F) {
641 Tracker->print(
errs());
650 "Alias Set Printer",
false,
true)
void mergeSetIn(AliasSet &AS, AliasSetTracker &AST)
static PassRegistry * getPassRegistry()
ModRefResult getModRefInfo(const Instruction *I, const Location &Loc)
Define an iterator for alias sets... this is just a forward iterator.
MDNode - a tuple of other values.
print alias Alias Set Printer
LoopInfoBase< BlockT, LoopT > * LI
void WriteAsOperand(raw_ostream &, const Value *, bool PrintTy=true, const Module *Context=0)
AnalysisUsage & addRequired()
inst_iterator inst_begin(Function *F)
const_iterator end() const
#define llvm_unreachable(msg)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
iterator find_as(const LookupKeyT &Val)
void initializeAliasSetPrinterPass(PassRegistry &)
ID
LLVM Calling Convention Representation.
virtual void copyValue(Value *From, Value *To)
const_iterator begin() const
uint64_t getTypeStoreSize(Type *Ty)
bool mayReadOrWriteMemory() const
bool containsPointer(Value *P, uint64_t Size, const MDNode *TBAAInfo) const
LLVM Basic Block Representation.
virtual AliasResult alias(const Location &LocA, const Location &LocB)
bool aliasesUnknownInst(Instruction *Inst, AliasAnalysis &AA) const
print alias Alias Set false
Value * getOperand(unsigned i) const
Location - A description of a memory location.
#define INITIALIZE_AG_DEPENDENCY(depName)
virtual void deleteValue(Value *V)
void print(raw_ostream &OS) const
bool mayWriteToMemory() const
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 remove(Value *Ptr, uint64_t Size, const MDNode *TBAAInfo)
bool removeUnknown(Instruction *I)
AliasAnalysis & getAliasAnalysis() const
void copyValue(Value *From, Value *To)
MDNode * getMetadata(unsigned KindID) const
bool erase(const KeyT &Val)
AtomicOrdering getOrdering() const
Returns the ordering effect of this fence.
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
AliasSet & getAliasSetForPointer(Value *P, uint64_t Size, const MDNode *TBAAInfo, bool *New=0)
void print(raw_ostream &OS) const
ilist< AliasSet >::iterator iterator
bool addUnknown(Instruction *I)
static uint64_t const UnknownSize
bool add(Value *Ptr, uint64_t Size, const MDNode *TBAAInfo)
LLVM Value Representation.
void print(raw_ostream &O, AssemblyAnnotationWriter *AAW=0) const
inst_iterator inst_end(Function *F)
bool aliasesPointer(const Value *Ptr, uint64_t Size, const MDNode *TBAAInfo, AliasAnalysis &AA) const
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
void deleteValue(Value *PtrVal)