--- /dev/null
+//===- AliasAnalysisEvaluator.h - Alias Analysis Accuracy Evaluator -------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ANALYSIS_ALIASANALYSISEVALUATOR_H
+#define LLVM_ANALYSIS_ALIASANALYSISEVALUATOR_H
+
+#include "llvm/IR/Function.h"
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+class AAResults;
+
+class AAEvaluator {
+ int64_t FunctionCount;
+ int64_t NoAliasCount, MayAliasCount, PartialAliasCount, MustAliasCount;
+ int64_t NoModRefCount, ModCount, RefCount, ModRefCount;
+
+public:
+ AAEvaluator()
+ : FunctionCount(), NoAliasCount(), MayAliasCount(), PartialAliasCount(),
+ MustAliasCount(), NoModRefCount(), ModCount(), RefCount(),
+ ModRefCount() {}
+ AAEvaluator(AAEvaluator &&Arg)
+ : FunctionCount(Arg.FunctionCount), NoAliasCount(Arg.NoAliasCount),
+ MayAliasCount(Arg.MayAliasCount),
+ PartialAliasCount(Arg.PartialAliasCount),
+ MustAliasCount(Arg.MustAliasCount), NoModRefCount(Arg.NoModRefCount),
+ ModCount(Arg.ModCount), RefCount(Arg.RefCount),
+ ModRefCount(Arg.ModRefCount) {
+ Arg.FunctionCount = 0;
+ }
+ ~AAEvaluator();
+
+ static StringRef name() { return "AAEvaluator"; }
+
+ /// \brief Run the pass over the function.
+ PreservedAnalyses run(Function &F, AnalysisManager<Function> *AM);
+
+private:
+ // Allow the legacy pass to run this using an internal API.
+ friend class AAEvalLegacyPass;
+
+ void runInternal(Function &F, AAResults &AA);
+};
+
+/// Create a wrapper of the above for the legacy pass manager.
+FunctionPass *createAAEvalPass();
+
+}
+
+#endif
// 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"
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);
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';
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';
}
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';
}
&& !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;
}
}
- 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";
}
}
}
-
- 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) {
}
// 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";
<< 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(); }