diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2016-02-20 03:46:03 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2016-02-20 03:46:03 +0000 |
commit | 4f846a5f15d579ceeb1fb5f7f2ca75107ae25978 (patch) | |
tree | 93d9cb8d837b89771e42a0ee004f132bc008191f /llvm/lib/Analysis/AliasAnalysisEvaluator.cpp | |
parent | 2ac7ee7139a0a06526126d18e549c724b96e3ee8 (diff) | |
download | bcm5719-llvm-4f846a5f15d579ceeb1fb5f7f2ca75107ae25978.tar.gz bcm5719-llvm-4f846a5f15d579ceeb1fb5f7f2ca75107ae25978.zip |
[PM/AA] Port alias analysis evaluator to the new pass manager, and use
it to actually test the new pass manager AA wiring.
This patch was extracted from the (somewhat too large) D12357 and
rebosed on top of the slightly different design of the new pass manager
AA wiring that I just landed. With this we can start testing the AA in
a thorough way with the new pass manager.
Some minor cleanups to the code in the pass was necessitated here, but
otherwise it is a very minimal change.
Differential Revision: http://reviews.llvm.org/D17372
llvm-svn: 261403
Diffstat (limited to 'llvm/lib/Analysis/AliasAnalysisEvaluator.cpp')
-rw-r--r-- | llvm/lib/Analysis/AliasAnalysisEvaluator.cpp | 135 |
1 files changed, 65 insertions, 70 deletions
diff --git a/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp b/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp index 12917b650e5..3a40afcaa84 100644 --- a/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp +++ b/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp @@ -6,18 +6,8 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -// -// This file implements a simple N^2 alias analysis accuracy evaluator. -// Basically, for each function in the program, it simply queries to see how the -// alias analysis implementation answers alias queries between each pair of -// pointers in the function. -// -// This is inspired and adapted from code by: Naveen Neelakantam, Francesco -// Spadini, and Wojciech Stryjewski. -// -//===----------------------------------------------------------------------===// -#include "llvm/Analysis/Passes.h" +#include "llvm/Analysis/AliasAnalysisEvaluator.h" #include "llvm/ADT/SetVector.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/IR/Constants.h" @@ -47,51 +37,9 @@ static cl::opt<bool> PrintModRef("print-modref", cl::ReallyHidden); static cl::opt<bool> EvalAAMD("evaluate-aa-metadata", cl::ReallyHidden); -namespace { - class AAEval : public FunctionPass { - unsigned NoAliasCount, MayAliasCount, PartialAliasCount, MustAliasCount; - unsigned NoModRefCount, ModCount, RefCount, ModRefCount; - - public: - static char ID; // Pass identification, replacement for typeid - AAEval() : FunctionPass(ID) { - initializeAAEvalPass(*PassRegistry::getPassRegistry()); - } - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addRequired<AAResultsWrapperPass>(); - AU.setPreservesAll(); - } - - bool doInitialization(Module &M) override { - NoAliasCount = MayAliasCount = PartialAliasCount = MustAliasCount = 0; - NoModRefCount = ModCount = RefCount = ModRefCount = 0; - - if (PrintAll) { - PrintNoAlias = PrintMayAlias = true; - PrintPartialAlias = PrintMustAlias = true; - PrintNoModRef = PrintMod = PrintRef = PrintModRef = true; - } - return false; - } - - bool runOnFunction(Function &F) override; - bool doFinalization(Module &M) override; - }; -} - -char AAEval::ID = 0; -INITIALIZE_PASS_BEGIN(AAEval, "aa-eval", - "Exhaustive Alias Analysis Precision Evaluator", false, true) -INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass) -INITIALIZE_PASS_END(AAEval, "aa-eval", - "Exhaustive Alias Analysis Precision Evaluator", false, true) - -FunctionPass *llvm::createAAEvalPass() { return new AAEval(); } - static void PrintResults(const char *Msg, bool P, const Value *V1, const Value *V2, const Module *M) { - if (P) { + if (PrintAll || P) { std::string o1, o2; { raw_string_ostream os1(o1), os2(o2); @@ -110,7 +58,7 @@ static void PrintResults(const char *Msg, bool P, const Value *V1, static inline void PrintModRefResults(const char *Msg, bool P, Instruction *I, Value *Ptr, Module *M) { - if (P) { + if (PrintAll || P) { errs() << " " << Msg << ": Ptr: "; Ptr->printAsOperand(errs(), true, M); errs() << "\t<->" << *I << '\n'; @@ -120,7 +68,7 @@ PrintModRefResults(const char *Msg, bool P, Instruction *I, Value *Ptr, static inline void PrintModRefResults(const char *Msg, bool P, CallSite CSA, CallSite CSB, Module *M) { - if (P) { + if (PrintAll || P) { errs() << " " << Msg << ": " << *CSA.getInstruction() << " <-> " << *CSB.getInstruction() << '\n'; } @@ -129,7 +77,7 @@ PrintModRefResults(const char *Msg, bool P, CallSite CSA, CallSite CSB, static inline void PrintLoadStoreResults(const char *Msg, bool P, const Value *V1, const Value *V2, const Module *M) { - if (P) { + if (PrintAll || P) { errs() << " " << Msg << ": " << *V1 << " <-> " << *V2 << '\n'; } @@ -140,9 +88,15 @@ static inline bool isInterestingPointer(Value *V) { && !isa<ConstantPointerNull>(V); } -bool AAEval::runOnFunction(Function &F) { +PreservedAnalyses AAEvaluator::run(Function &F, AnalysisManager<Function> *AM) { + runInternal(F, AM->getResult<AAManager>(F)); + return PreservedAnalyses::all(); +} + +void AAEvaluator::runInternal(Function &F, AAResults &AA) { const DataLayout &DL = F.getParent()->getDataLayout(); - AliasAnalysis &AA = getAnalysis<AAResultsWrapperPass>().getAAResults(); + + ++FunctionCount; SetVector<Value *> Pointers; SmallSetVector<CallSite, 16> CallSites; @@ -180,8 +134,8 @@ bool AAEval::runOnFunction(Function &F) { } } - if (PrintNoAlias || PrintMayAlias || PrintPartialAlias || PrintMustAlias || - PrintNoModRef || PrintMod || PrintRef || PrintModRef) + if (PrintAll || PrintNoAlias || PrintMayAlias || PrintPartialAlias || + PrintMustAlias || PrintNoModRef || PrintMod || PrintRef || PrintModRef) errs() << "Function: " << F.getName() << ": " << Pointers.size() << " pointers, " << CallSites.size() << " call sites\n"; @@ -338,17 +292,18 @@ bool AAEval::runOnFunction(Function &F) { } } } - - return false; } -static void PrintPercent(unsigned Num, unsigned Sum) { - errs() << "(" << Num*100ULL/Sum << "." - << ((Num*1000ULL/Sum) % 10) << "%)\n"; +static void PrintPercent(int64_t Num, int64_t Sum) { + errs() << "(" << Num * 100LL / Sum << "." << ((Num * 1000LL / Sum) % 10) + << "%)\n"; } -bool AAEval::doFinalization(Module &M) { - unsigned AliasSum = +AAEvaluator::~AAEvaluator() { + if (FunctionCount == 0) + return; + + int64_t AliasSum = NoAliasCount + MayAliasCount + PartialAliasCount + MustAliasCount; errs() << "===== Alias Analysis Evaluator Report =====\n"; if (AliasSum == 0) { @@ -371,7 +326,7 @@ bool AAEval::doFinalization(Module &M) { } // Display the summary for mod/ref analysis - unsigned ModRefSum = NoModRefCount + ModCount + RefCount + ModRefCount; + int64_t ModRefSum = NoModRefCount + ModCount + RefCount + ModRefCount; if (ModRefSum == 0) { errs() << " Alias Analysis Mod/Ref Evaluator Summary: no " "mod/ref!\n"; @@ -390,6 +345,46 @@ bool AAEval::doFinalization(Module &M) { << ModCount * 100 / ModRefSum << "%/" << RefCount * 100 / ModRefSum << "%/" << ModRefCount * 100 / ModRefSum << "%\n"; } +} + +namespace llvm { +class AAEvalLegacyPass : public FunctionPass { + std::unique_ptr<AAEvaluator> P; + +public: + static char ID; // Pass identification, replacement for typeid + AAEvalLegacyPass() : FunctionPass(ID) { + initializeAAEvalLegacyPassPass(*PassRegistry::getPassRegistry()); + } - return false; + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addRequired<AAResultsWrapperPass>(); + AU.setPreservesAll(); + } + + bool doInitialization(Module &M) override { + P.reset(new AAEvaluator()); + return false; + } + + bool runOnFunction(Function &F) override { + P->runInternal(F, getAnalysis<AAResultsWrapperPass>().getAAResults()); + return false; + } + bool doFinalization(Module &M) override { + P.reset(); + return false; + } +}; } + +char AAEvalLegacyPass::ID = 0; +INITIALIZE_PASS_BEGIN(AAEvalLegacyPass, "aa-eval", + "Exhaustive Alias Analysis Precision Evaluator", false, + true) +INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass) +INITIALIZE_PASS_END(AAEvalLegacyPass, "aa-eval", + "Exhaustive Alias Analysis Precision Evaluator", false, + true) + +FunctionPass *llvm::createAAEvalPass() { return new AAEvalLegacyPass(); } |