123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775 |
- #include "llvm/Analysis/AliasSetTracker.h"
- #include "llvm/Analysis/AliasAnalysis.h"
- #include "llvm/Analysis/GuardUtils.h"
- #include "llvm/Analysis/LoopInfo.h"
- #include "llvm/Analysis/MemoryLocation.h"
- #include "llvm/Config/llvm-config.h"
- #include "llvm/IR/Constants.h"
- #include "llvm/IR/DataLayout.h"
- #include "llvm/IR/Function.h"
- #include "llvm/IR/InstIterator.h"
- #include "llvm/IR/Instructions.h"
- #include "llvm/IR/IntrinsicInst.h"
- #include "llvm/IR/Module.h"
- #include "llvm/IR/PassManager.h"
- #include "llvm/IR/PatternMatch.h"
- #include "llvm/IR/Value.h"
- #include "llvm/InitializePasses.h"
- #include "llvm/Pass.h"
- #include "llvm/Support/AtomicOrdering.h"
- #include "llvm/Support/CommandLine.h"
- #include "llvm/Support/Compiler.h"
- #include "llvm/Support/Debug.h"
- #include "llvm/Support/ErrorHandling.h"
- #include "llvm/Support/raw_ostream.h"
- using namespace llvm;
- 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"));
- void AliasSet::mergeSetIn(AliasSet &AS, AliasSetTracker &AST) {
- assert(!AS.Forward && "Alias set is already forwarding!");
- assert(!Forward && "This set is a forwarding set!!");
- bool WasMustAlias = (Alias == SetMustAlias);
-
- Access |= AS.Access;
- Alias |= AS.Alias;
- if (Alias == SetMustAlias) {
-
-
-
- AliasAnalysis &AA = AST.getAliasAnalysis();
- PointerRec *L = getSomePointer();
- PointerRec *R = AS.getSomePointer();
-
- if (!AA.isMustAlias(
- MemoryLocation(L->getValue(), L->getSize(), L->getAAInfo()),
- MemoryLocation(R->getValue(), R->getSize(), R->getAAInfo())))
- Alias = SetMayAlias;
- }
- if (Alias == SetMayAlias) {
- if (WasMustAlias)
- AST.TotalMayAliasSetSize += size();
- if (AS.Alias == SetMustAlias)
- AST.TotalMayAliasSetSize += AS.size();
- }
- bool ASHadUnknownInsts = !AS.UnknownInsts.empty();
- if (UnknownInsts.empty()) {
- if (ASHadUnknownInsts) {
- std::swap(UnknownInsts, AS.UnknownInsts);
- addRef();
- }
- } else if (ASHadUnknownInsts) {
- llvm::append_range(UnknownInsts, AS.UnknownInsts);
- AS.UnknownInsts.clear();
- }
- AS.Forward = this;
- addRef();
-
- if (AS.PtrList) {
- SetSize += AS.size();
- AS.SetSize = 0;
- *PtrListEnd = AS.PtrList;
- AS.PtrList->setPrevInList(PtrListEnd);
- PtrListEnd = AS.PtrListEnd;
- AS.PtrList = nullptr;
- AS.PtrListEnd = &AS.PtrList;
- assert(*AS.PtrListEnd == nullptr && "End of list is not null?");
- }
- if (ASHadUnknownInsts)
- AS.dropRef(AST);
- }
- void AliasSetTracker::removeAliasSet(AliasSet *AS) {
- if (AliasSet *Fwd = AS->Forward) {
- Fwd->dropRef(*this);
- AS->Forward = nullptr;
- } else
- if (AS->Alias == AliasSet::SetMayAlias)
- TotalMayAliasSetSize -= AS->size();
- AliasSets.erase(AS);
-
-
- if (AS == AliasAnyAS) {
- AliasAnyAS = nullptr;
- assert(AliasSets.empty() && "Tracker not empty");
- }
- }
- void AliasSet::removeFromTracker(AliasSetTracker &AST) {
- assert(RefCount == 0 && "Cannot remove non-dead alias set from tracker!");
- AST.removeAliasSet(this);
- }
- void AliasSet::addPointer(AliasSetTracker &AST, PointerRec &Entry,
- LocationSize Size, const AAMDNodes &AAInfo,
- bool KnownMustAlias, bool SkipSizeUpdate) {
- assert(!Entry.hasAliasSet() && "Entry already in set!");
-
- if (isMustAlias())
- if (PointerRec *P = getSomePointer()) {
- if (!KnownMustAlias) {
- AliasAnalysis &AA = AST.getAliasAnalysis();
- AliasResult Result = AA.alias(
- MemoryLocation(P->getValue(), P->getSize(), P->getAAInfo()),
- MemoryLocation(Entry.getValue(), Size, AAInfo));
- if (Result != AliasResult::MustAlias) {
- Alias = SetMayAlias;
- AST.TotalMayAliasSetSize += size();
- }
- assert(Result != AliasResult::NoAlias && "Cannot be part of must set!");
- } else if (!SkipSizeUpdate)
- P->updateSizeAndAAInfo(Size, AAInfo);
- }
- Entry.setAliasSet(this);
- Entry.updateSizeAndAAInfo(Size, AAInfo);
-
- ++SetSize;
- assert(*PtrListEnd == nullptr && "End of list is not null?");
- *PtrListEnd = &Entry;
- PtrListEnd = Entry.setPrevInList(PtrListEnd);
- assert(*PtrListEnd == nullptr && "End of list is not null?");
-
- addRef();
- if (Alias == SetMayAlias)
- AST.TotalMayAliasSetSize++;
- }
- void AliasSet::addUnknownInst(Instruction *I, AliasAnalysis &AA) {
- if (UnknownInsts.empty())
- addRef();
- UnknownInsts.emplace_back(I);
-
-
- using namespace PatternMatch;
- bool MayWriteMemory = I->mayWriteToMemory() && !isGuard(I) &&
- !(I->use_empty() && match(I, m_Intrinsic<Intrinsic::invariant_start>()));
- if (!MayWriteMemory) {
- Alias = SetMayAlias;
- Access |= RefAccess;
- return;
- }
-
- Alias = SetMayAlias;
- Access = ModRefAccess;
- }
- AliasResult AliasSet::aliasesPointer(const Value *Ptr, LocationSize Size,
- const AAMDNodes &AAInfo,
- AliasAnalysis &AA) const {
- if (AliasAny)
- return AliasResult::MayAlias;
- if (Alias == SetMustAlias) {
- assert(UnknownInsts.empty() && "Illegal must alias set!");
-
-
- PointerRec *SomePtr = getSomePointer();
- assert(SomePtr && "Empty must-alias set??");
- return AA.alias(MemoryLocation(SomePtr->getValue(), SomePtr->getSize(),
- SomePtr->getAAInfo()),
- MemoryLocation(Ptr, Size, AAInfo));
- }
-
-
- for (iterator I = begin(), E = end(); I != E; ++I) {
- AliasResult AR =
- AA.alias(MemoryLocation(Ptr, Size, AAInfo),
- MemoryLocation(I.getPointer(), I.getSize(), I.getAAInfo()));
- if (AR != AliasResult::NoAlias)
- return AR;
- }
-
- if (!UnknownInsts.empty()) {
- for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i)
- if (auto *Inst = getUnknownInst(i))
- if (isModOrRefSet(
- AA.getModRefInfo(Inst, MemoryLocation(Ptr, Size, AAInfo))))
- return AliasResult::MayAlias;
- }
- return AliasResult::NoAlias;
- }
- bool AliasSet::aliasesUnknownInst(const Instruction *Inst,
- AliasAnalysis &AA) const {
- if (AliasAny)
- return true;
- assert(Inst->mayReadOrWriteMemory() &&
- "Instruction must either read or write memory.");
- for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
- if (auto *UnknownInst = getUnknownInst(i)) {
- const auto *C1 = dyn_cast<CallBase>(UnknownInst);
- const auto *C2 = dyn_cast<CallBase>(Inst);
- if (!C1 || !C2 || isModOrRefSet(AA.getModRefInfo(C1, C2)) ||
- isModOrRefSet(AA.getModRefInfo(C2, C1)))
- return true;
- }
- }
- for (iterator I = begin(), E = end(); I != E; ++I)
- if (isModOrRefSet(AA.getModRefInfo(
- Inst, MemoryLocation(I.getPointer(), I.getSize(), I.getAAInfo()))))
- return true;
- return false;
- }
- Instruction* AliasSet::getUniqueInstruction() {
- if (AliasAny)
-
- return nullptr;
- if (begin() != end()) {
- if (!UnknownInsts.empty())
-
- return nullptr;
- if (std::next(begin()) != end())
-
- return nullptr;
- Value *Addr = begin()->getValue();
- assert(!Addr->user_empty() &&
- "where's the instruction which added this pointer?");
- if (std::next(Addr->user_begin()) != Addr->user_end())
-
-
- return nullptr;
- return cast<Instruction>(*(Addr->user_begin()));
- }
- if (1 != UnknownInsts.size())
- return nullptr;
- return cast<Instruction>(UnknownInsts[0]);
- }
- void AliasSetTracker::clear() {
-
- for (auto &I : PointerMap)
- I.second->eraseFromList();
- PointerMap.clear();
-
- AliasSets.clear();
- }
- AliasSet *AliasSetTracker::mergeAliasSetsForPointer(const Value *Ptr,
- LocationSize Size,
- const AAMDNodes &AAInfo,
- bool &MustAliasAll) {
- AliasSet *FoundSet = nullptr;
- MustAliasAll = true;
- for (AliasSet &AS : llvm::make_early_inc_range(*this)) {
- if (AS.Forward)
- continue;
- AliasResult AR = AS.aliasesPointer(Ptr, Size, AAInfo, AA);
- if (AR == AliasResult::NoAlias)
- continue;
- if (AR != AliasResult::MustAlias)
- MustAliasAll = false;
- if (!FoundSet) {
-
- FoundSet = &AS;
- } else {
-
- FoundSet->mergeSetIn(AS, *this);
- }
- }
- return FoundSet;
- }
- AliasSet *AliasSetTracker::findAliasSetForUnknownInst(Instruction *Inst) {
- AliasSet *FoundSet = nullptr;
- for (AliasSet &AS : llvm::make_early_inc_range(*this)) {
- if (AS.Forward || !AS.aliasesUnknownInst(Inst, AA))
- continue;
- if (!FoundSet) {
-
- FoundSet = &AS;
- } else {
-
- FoundSet->mergeSetIn(AS, *this);
- }
- }
- return FoundSet;
- }
- AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
- Value * const Pointer = const_cast<Value*>(MemLoc.Ptr);
- const LocationSize Size = MemLoc.Size;
- const AAMDNodes &AAInfo = MemLoc.AATags;
- AliasSet::PointerRec &Entry = getEntryFor(Pointer);
- if (AliasAnyAS) {
-
-
-
-
-
- if (Entry.hasAliasSet()) {
- Entry.updateSizeAndAAInfo(Size, AAInfo);
- assert(Entry.getAliasSet(*this) == AliasAnyAS &&
- "Entry in saturated AST must belong to only alias set");
- } else {
- AliasAnyAS->addPointer(*this, Entry, Size, AAInfo);
- }
- return *AliasAnyAS;
- }
- bool MustAliasAll = false;
-
- if (Entry.hasAliasSet()) {
-
-
-
-
-
- if (Entry.updateSizeAndAAInfo(Size, AAInfo))
- mergeAliasSetsForPointer(Pointer, Size, AAInfo, MustAliasAll);
-
- return *Entry.getAliasSet(*this)->getForwardedTarget(*this);
- }
- if (AliasSet *AS =
- mergeAliasSetsForPointer(Pointer, Size, AAInfo, MustAliasAll)) {
-
- AS->addPointer(*this, Entry, Size, AAInfo, MustAliasAll);
- return *AS;
- }
-
- AliasSets.push_back(new AliasSet());
- AliasSets.back().addPointer(*this, Entry, Size, AAInfo, true);
- return AliasSets.back();
- }
- void AliasSetTracker::add(Value *Ptr, LocationSize Size,
- const AAMDNodes &AAInfo) {
- addPointer(MemoryLocation(Ptr, Size, AAInfo), AliasSet::NoAccess);
- }
- void AliasSetTracker::add(LoadInst *LI) {
- if (isStrongerThanMonotonic(LI->getOrdering()))
- return addUnknown(LI);
- addPointer(MemoryLocation::get(LI), AliasSet::RefAccess);
- }
- void AliasSetTracker::add(StoreInst *SI) {
- if (isStrongerThanMonotonic(SI->getOrdering()))
- return addUnknown(SI);
- addPointer(MemoryLocation::get(SI), AliasSet::ModAccess);
- }
- void AliasSetTracker::add(VAArgInst *VAAI) {
- addPointer(MemoryLocation::get(VAAI), AliasSet::ModRefAccess);
- }
- void AliasSetTracker::add(AnyMemSetInst *MSI) {
- addPointer(MemoryLocation::getForDest(MSI), AliasSet::ModAccess);
- }
- void AliasSetTracker::add(AnyMemTransferInst *MTI) {
- addPointer(MemoryLocation::getForDest(MTI), AliasSet::ModAccess);
- addPointer(MemoryLocation::getForSource(MTI), AliasSet::RefAccess);
- }
- void AliasSetTracker::addUnknown(Instruction *Inst) {
- if (isa<DbgInfoIntrinsic>(Inst))
- return;
- if (auto *II = dyn_cast<IntrinsicInst>(Inst)) {
-
-
- switch (II->getIntrinsicID()) {
- default:
- break;
-
- case Intrinsic::assume:
- case Intrinsic::experimental_noalias_scope_decl:
- case Intrinsic::sideeffect:
- case Intrinsic::pseudoprobe:
- return;
- }
- }
- if (!Inst->mayReadOrWriteMemory())
- return;
- if (AliasSet *AS = findAliasSetForUnknownInst(Inst)) {
- AS->addUnknownInst(Inst, AA);
- return;
- }
- AliasSets.push_back(new AliasSet());
- AliasSets.back().addUnknownInst(Inst, AA);
- }
- void AliasSetTracker::add(Instruction *I) {
-
- if (LoadInst *LI = dyn_cast<LoadInst>(I))
- return add(LI);
- if (StoreInst *SI = dyn_cast<StoreInst>(I))
- return add(SI);
- if (VAArgInst *VAAI = dyn_cast<VAArgInst>(I))
- return add(VAAI);
- if (AnyMemSetInst *MSI = dyn_cast<AnyMemSetInst>(I))
- return add(MSI);
- if (AnyMemTransferInst *MTI = dyn_cast<AnyMemTransferInst>(I))
- return add(MTI);
-
- if (auto *Call = dyn_cast<CallBase>(I))
- if (Call->onlyAccessesArgMemory()) {
- auto getAccessFromModRef = [](ModRefInfo MRI) {
- if (isRefSet(MRI) && isModSet(MRI))
- return AliasSet::ModRefAccess;
- else if (isModSet(MRI))
- return AliasSet::ModAccess;
- else if (isRefSet(MRI))
- return AliasSet::RefAccess;
- else
- return AliasSet::NoAccess;
- };
- ModRefInfo CallMask = createModRefInfo(AA.getModRefBehavior(Call));
-
-
-
- using namespace PatternMatch;
- if (Call->use_empty() &&
- match(Call, m_Intrinsic<Intrinsic::invariant_start>()))
- CallMask = clearMod(CallMask);
- for (auto IdxArgPair : enumerate(Call->args())) {
- int ArgIdx = IdxArgPair.index();
- const Value *Arg = IdxArgPair.value();
- if (!Arg->getType()->isPointerTy())
- continue;
- MemoryLocation ArgLoc =
- MemoryLocation::getForArgument(Call, ArgIdx, nullptr);
- ModRefInfo ArgMask = AA.getArgModRefInfo(Call, ArgIdx);
- ArgMask = intersectModRef(CallMask, ArgMask);
- if (!isNoModRef(ArgMask))
- addPointer(ArgLoc, getAccessFromModRef(ArgMask));
- }
- return;
- }
- return addUnknown(I);
- }
- void AliasSetTracker::add(BasicBlock &BB) {
- for (auto &I : BB)
- add(&I);
- }
- void AliasSetTracker::add(const AliasSetTracker &AST) {
- assert(&AA == &AST.AA &&
- "Merging AliasSetTracker objects with different Alias Analyses!");
-
-
-
- for (const AliasSet &AS : AST) {
- if (AS.Forward)
- continue;
-
- for (unsigned i = 0, e = AS.UnknownInsts.size(); i != e; ++i)
- if (auto *Inst = AS.getUnknownInst(i))
- add(Inst);
-
- for (AliasSet::iterator ASI = AS.begin(), E = AS.end(); ASI != E; ++ASI)
- addPointer(
- MemoryLocation(ASI.getPointer(), ASI.getSize(), ASI.getAAInfo()),
- (AliasSet::AccessLattice)AS.Access);
- }
- }
- void AliasSetTracker::deleteValue(Value *PtrVal) {
-
- PointerMapType::iterator I = PointerMap.find_as(PtrVal);
- if (I == PointerMap.end()) return;
-
- AliasSet::PointerRec *PtrValEnt = I->second;
- AliasSet *AS = PtrValEnt->getAliasSet(*this);
-
- PtrValEnt->eraseFromList();
- if (AS->Alias == AliasSet::SetMayAlias) {
- AS->SetSize--;
- TotalMayAliasSetSize--;
- }
-
- AS->dropRef(*this);
- PointerMap.erase(I);
- }
- void AliasSetTracker::copyValue(Value *From, Value *To) {
-
- PointerMapType::iterator I = PointerMap.find_as(From);
- if (I == PointerMap.end())
- return;
- assert(I->second->hasAliasSet() && "Dead entry?");
- AliasSet::PointerRec &Entry = getEntryFor(To);
- if (Entry.hasAliasSet()) return;
-
- I = PointerMap.find_as(From);
-
- AliasSet *AS = I->second->getAliasSet(*this);
- AS->addPointer(*this, Entry, I->second->getSize(), I->second->getAAInfo(),
- true, true);
- }
- AliasSet &AliasSetTracker::mergeAllAliasSets() {
- assert(!AliasAnyAS && (TotalMayAliasSetSize > SaturationThreshold) &&
- "Full merge should happen once, when the saturation threshold is "
- "reached");
-
-
- std::vector<AliasSet *> ASVector;
- ASVector.reserve(SaturationThreshold);
- for (AliasSet &AS : *this)
- ASVector.push_back(&AS);
-
-
- AliasSets.push_back(new AliasSet());
- AliasAnyAS = &AliasSets.back();
- AliasAnyAS->Alias = AliasSet::SetMayAlias;
- AliasAnyAS->Access = AliasSet::ModRefAccess;
- AliasAnyAS->AliasAny = true;
- for (auto Cur : ASVector) {
-
- AliasSet *FwdTo = Cur->Forward;
- if (FwdTo) {
- Cur->Forward = AliasAnyAS;
- AliasAnyAS->addRef();
- FwdTo->dropRef(*this);
- continue;
- }
-
- AliasAnyAS->mergeSetIn(*Cur, *this);
- }
- return *AliasAnyAS;
- }
- AliasSet &AliasSetTracker::addPointer(MemoryLocation Loc,
- AliasSet::AccessLattice E) {
- AliasSet &AS = getAliasSetFor(Loc);
- AS.Access |= E;
- if (!AliasAnyAS && (TotalMayAliasSetSize > SaturationThreshold)) {
-
-
- return mergeAllAliasSets();
- }
- return AS;
- }
- void AliasSet::print(raw_ostream &OS) const {
- OS << " AliasSet[" << (const void*)this << ", " << RefCount << "] ";
- OS << (Alias == SetMustAlias ? "must" : "may") << " alias, ";
- switch (Access) {
- case NoAccess: OS << "No access "; break;
- case RefAccess: OS << "Ref "; break;
- case ModAccess: OS << "Mod "; break;
- case ModRefAccess: OS << "Mod/Ref "; break;
- default: llvm_unreachable("Bad value for Access!");
- }
- if (Forward)
- OS << " forwarding to " << (void*)Forward;
- if (!empty()) {
- OS << "Pointers: ";
- for (iterator I = begin(), E = end(); I != E; ++I) {
- if (I != begin()) OS << ", ";
- I.getPointer()->printAsOperand(OS << "(");
- if (I.getSize() == LocationSize::afterPointer())
- OS << ", unknown after)";
- else if (I.getSize() == LocationSize::beforeOrAfterPointer())
- OS << ", unknown before-or-after)";
- else
- OS << ", " << I.getSize() << ")";
- }
- }
- if (!UnknownInsts.empty()) {
- OS << "\n " << UnknownInsts.size() << " Unknown instructions: ";
- for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
- if (i) OS << ", ";
- if (auto *I = getUnknownInst(i)) {
- if (I->hasName())
- I->printAsOperand(OS);
- else
- I->print(OS);
- }
- }
- }
- OS << "\n";
- }
- void AliasSetTracker::print(raw_ostream &OS) const {
- OS << "Alias Set Tracker: " << AliasSets.size();
- if (AliasAnyAS)
- OS << " (Saturated)";
- OS << " alias sets for " << PointerMap.size() << " pointer values.\n";
- for (const AliasSet &AS : *this)
- AS.print(OS);
- OS << "\n";
- }
- #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
- LLVM_DUMP_METHOD void AliasSet::dump() const { print(dbgs()); }
- LLVM_DUMP_METHOD void AliasSetTracker::dump() const { print(dbgs()); }
- #endif
- void AliasSetTracker::ASTCallbackVH::deleted() {
- assert(AST && "ASTCallbackVH called with a null AliasSetTracker!");
- AST->deleteValue(getValPtr());
-
- }
- void AliasSetTracker::ASTCallbackVH::allUsesReplacedWith(Value *V) {
- AST->copyValue(getValPtr(), V);
- }
- AliasSetTracker::ASTCallbackVH::ASTCallbackVH(Value *V, AliasSetTracker *ast)
- : CallbackVH(V), AST(ast) {}
- AliasSetTracker::ASTCallbackVH &
- AliasSetTracker::ASTCallbackVH::operator=(Value *V) {
- return *this = ASTCallbackVH(V, AST);
- }
- namespace {
- class AliasSetPrinter : public FunctionPass {
- public:
- static char ID;
- AliasSetPrinter() : FunctionPass(ID) {
- initializeAliasSetPrinterPass(*PassRegistry::getPassRegistry());
- }
- void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.setPreservesAll();
- AU.addRequired<AAResultsWrapperPass>();
- }
- bool runOnFunction(Function &F) override {
- auto &AAWP = getAnalysis<AAResultsWrapperPass>();
- AliasSetTracker Tracker(AAWP.getAAResults());
- errs() << "Alias sets for function '" << F.getName() << "':\n";
- for (Instruction &I : instructions(F))
- Tracker.add(&I);
- Tracker.print(errs());
- return false;
- }
- };
- }
- char AliasSetPrinter::ID = 0;
- INITIALIZE_PASS_BEGIN(AliasSetPrinter, "print-alias-sets",
- "Alias Set Printer", false, true)
- INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
- INITIALIZE_PASS_END(AliasSetPrinter, "print-alias-sets",
- "Alias Set Printer", false, true)
- AliasSetsPrinterPass::AliasSetsPrinterPass(raw_ostream &OS) : OS(OS) {}
- PreservedAnalyses AliasSetsPrinterPass::run(Function &F,
- FunctionAnalysisManager &AM) {
- auto &AA = AM.getResult<AAManager>(F);
- AliasSetTracker Tracker(AA);
- OS << "Alias sets for function '" << F.getName() << "':\n";
- for (Instruction &I : instructions(F))
- Tracker.add(&I);
- Tracker.print(OS);
- return PreservedAnalyses::all();
- }
|