diff options
author | Misha Brukman <brukman+llvm@gmail.com> | 2004-03-12 06:15:08 +0000 |
---|---|---|
committer | Misha Brukman <brukman+llvm@gmail.com> | 2004-03-12 06:15:08 +0000 |
commit | bf28cf6b7dcd271b7c5635447f950a36d681d5bb (patch) | |
tree | 32e1a6ce99fbaf873300f09aa61d418c2f60a298 | |
parent | 362841dccc5d81ec3fb323fdc4a5fa048eed5177 (diff) | |
download | llvm-bf28cf6b7dcd271b7c5635447f950a36d681d5bb.zip llvm-bf28cf6b7dcd271b7c5635447f950a36d681d5bb.tar.gz llvm-bf28cf6b7dcd271b7c5635447f950a36d681d5bb.tar.bz2 |
Evaluate ModRef information in addition to regular ol' pointer analysis.
llvm-svn: 12331
-rw-r--r-- | llvm/lib/Analysis/AliasAnalysisEvaluator.cpp | 117 |
1 files changed, 93 insertions, 24 deletions
diff --git a/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp b/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp index 073300c..df1a9b8 100644 --- a/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp +++ b/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp @@ -17,23 +17,31 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Analysis/AliasAnalysis.h" -#include "llvm/Pass.h" #include "llvm/Function.h" +#include "llvm/iOther.h" +#include "llvm/iTerminators.h" +#include "llvm/Pass.h" #include "llvm/Type.h" -#include "llvm/Support/InstIterator.h" +#include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Assembly/Writer.h" +#include "llvm/Support/InstIterator.h" #include "Support/CommandLine.h" #include <set> using namespace llvm; namespace { - cl::opt<bool> PrintNo ("print-no-aliases", cl::ReallyHidden); - cl::opt<bool> PrintMay ("print-may-aliases", cl::ReallyHidden); - cl::opt<bool> PrintMust("print-must-aliases", cl::ReallyHidden); + cl::opt<bool> PrintNoAlias("print-no-aliases", cl::ReallyHidden); + cl::opt<bool> PrintMayAlias("print-may-aliases", cl::ReallyHidden); + cl::opt<bool> PrintMustAlias("print-must-aliases", cl::ReallyHidden); + + cl::opt<bool> PrintNoModRef("print-no-modref", cl::ReallyHidden); + cl::opt<bool> PrintMod("print-mod", cl::ReallyHidden); + cl::opt<bool> PrintRef("print-ref", cl::ReallyHidden); + cl::opt<bool> PrintModRef("print-modref", cl::ReallyHidden); class AAEval : public FunctionPass { - unsigned No, May, Must; + unsigned NoAlias, MayAlias, MustAlias; + unsigned NoModRef, Mod, Ref, ModRef; public: virtual void getAnalysisUsage(AnalysisUsage &AU) const { @@ -41,7 +49,12 @@ namespace { AU.setPreservesAll(); } - bool doInitialization(Module &M) { No = May = Must = 0; return false; } + bool doInitialization(Module &M) { + NoAlias = MayAlias = MustAlias = 0; + NoModRef = Mod = Ref = ModRef = 0; + return false; + } + bool runOnFunction(Function &F); bool doFinalization(Module &M); }; @@ -63,6 +76,7 @@ bool AAEval::runOnFunction(Function &F) { AliasAnalysis &AA = getAnalysis<AliasAnalysis>(); std::set<Value *> Pointers; + std::set<CallSite> CallSites; for (Function::aiterator I = F.abegin(), E = F.aend(); I != E; ++I) if (isa<PointerType>(I->getType())) // Add all pointer arguments @@ -76,7 +90,15 @@ bool AAEval::runOnFunction(Function &F) { Pointers.insert(*OI); } - if (PrintNo || PrintMay || PrintMust) + for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) { + if (CallInst *CI = dyn_cast<CallInst>(*I)) + CallSites.insert(CallSite(CI)); + else if (InvokeInst *II = dyn_cast<InvokeInst>(*I)) + CallSites.insert(CallSite(II)); + } + + if (PrintNoAlias || PrintMayAlias || PrintMustAlias || + PrintNoModRef || PrintMod || PrintRef || PrintModRef) std::cerr << "Function: " << F.getName() << "\n"; // iterate over the worklist, and run the full (n^2)/2 disambiguations @@ -85,34 +107,81 @@ bool AAEval::runOnFunction(Function &F) { for (std::set<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2) switch (AA.alias(*I1, 0, *I2, 0)) { case AliasAnalysis::NoAlias: - PrintResults("No", PrintNo, *I1, *I2, F.getParent()); - ++No; break; + PrintResults("NoAlias", PrintNoAlias, *I1, *I2, F.getParent()); + ++NoAlias; break; case AliasAnalysis::MayAlias: - PrintResults("May", PrintMay, *I1, *I2, F.getParent()); - ++May; break; + PrintResults("MayAlias", PrintMayAlias, *I1, *I2, F.getParent()); + ++MayAlias; break; case AliasAnalysis::MustAlias: - PrintResults("Must", PrintMust, *I1, *I2, F.getParent()); - ++Must; break; + PrintResults("MustAlias", PrintMustAlias, *I1, *I2, F.getParent()); + ++MustAlias; break; default: std::cerr << "Unknown alias query result!\n"; } + // Mod/ref alias analysis: compare all pairs of calls and values + for (std::set<Value *>::iterator V = Pointers.begin(), Ve = Pointers.end(); + V != Ve; ++V) + for (std::set<CallSite>::iterator C = CallSites.begin(), + Ce = CallSites.end(); C != Ce; ++C) { + Instruction *I = C->getInstruction(); + switch (AA.getModRefInfo(*C, *V, (*V)->getType()->getPrimitiveSize())) { + case AliasAnalysis::NoModRef: + PrintResults("NoModRef", PrintNoModRef, I, *V, F.getParent()); + ++NoModRef; break; + case AliasAnalysis::Mod: + PrintResults("Mod", PrintMod, I, *V, F.getParent()); + ++Mod; break; + case AliasAnalysis::Ref: + PrintResults("Ref", PrintRef, I, *V, F.getParent()); + ++Ref; break; + case AliasAnalysis::ModRef: + PrintResults("ModRef", PrintModRef, I, *V, F.getParent()); + ++ModRef; break; + default: + std::cerr << "Unknown alias query result!\n"; + } + } + return false; } bool AAEval::doFinalization(Module &M) { - unsigned Sum = No+May+Must; + unsigned AliasSum = NoAlias + MayAlias + MustAlias; std::cerr << "===== Alias Analysis Evaluator Report =====\n"; - if (Sum == 0) { + if (AliasSum == 0) { std::cerr << " Alias Analysis Evaluator Summary: No pointers!\n"; - return false; + } else { + std::cerr << " " << AliasSum << " Total Alias Queries Performed\n"; + std::cerr << " " << NoAlias << " no alias responses (" + << NoAlias*100/AliasSum << "%)\n"; + std::cerr << " " << MayAlias << " may alias responses (" + << MayAlias*100/AliasSum << "%)\n"; + std::cerr << " " << MustAlias << " must alias responses (" + << MustAlias*100/AliasSum <<"%)\n"; + std::cerr << " Alias Analysis Evaluator Pointer Alias Summary: " + << NoAlias*100/AliasSum << "%/" << MayAlias*100/AliasSum << "%/" + << MustAlias*100/AliasSum << "%\n"; + } + + // Display the summary for mod/ref analysis + unsigned ModRefSum = NoModRef + Mod + Ref + ModRef; + if (ModRefSum == 0) { + std::cerr << " Alias Analysis Mod/Ref Evaluator Summary: no mod/ref!\n"; + } else { + std::cerr << " " << ModRefSum << " Total ModRef Queries Performed\n"; + std::cerr << " " << NoModRef << " no mod/ref responses (" + << NoModRef*100/ModRefSum << "%)\n"; + std::cerr << " " << Mod << " mod responses (" + << Mod*100/ModRefSum << "%)\n"; + std::cerr << " " << Ref << " ref responses (" + << Ref*100/ModRefSum <<"%)\n"; + std::cerr << " " << ModRef << " mod & ref responses (" + << ModRef*100/ModRefSum <<"%)\n"; + std::cerr << " Alias Analysis Evaluator Mod/Ref Summary: " + << NoModRef*100/ModRefSum << "%/" << Mod*100/ModRefSum << "%/" + << Ref*100/ModRefSum << "%/" << ModRef*100/ModRefSum << "%\n"; } - std::cerr << " " << Sum << " Total Alias Queries Performed\n"; - std::cerr << " " << No << " no alias responses (" << No*100/Sum << "%)\n"; - std::cerr << " " << May << " may alias responses (" << May*100/Sum << "%)\n"; - std::cerr << " " << Must << " must alias responses (" <<Must*100/Sum<<"%)\n"; - std::cerr << " Alias Analysis Evaluator Summary: " << No*100/Sum << "%/" - << May*100/Sum << "%/" << Must*100/Sum<<"%\n"; return false; } |