[PM/AA] Sink all the actual code from AliasAnalysisCounter back into the

.cpp file to make the header much less noisy.

Also makes it easy to use a static helper rather than a public method
for printing lines of stats.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245006 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chandler Carruth 2015-08-14 02:12:12 +00:00
parent 20c9ab5fe6
commit 0dc1606c51
2 changed files with 64 additions and 54 deletions

View File

@ -19,7 +19,6 @@
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
@ -30,67 +29,19 @@ class AliasAnalysisCounter : public ModulePass, public AliasAnalysis {
public:
static char ID; // Class identification, replacement for typeinfo
AliasAnalysisCounter() : ModulePass(ID) {
initializeAliasAnalysisCounterPass(*PassRegistry::getPassRegistry());
No = May = Partial = Must = 0;
NoMR = JustRef = JustMod = MR = 0;
}
void printLine(const char *Desc, unsigned Val, unsigned Sum) {
errs() << " " << Val << " " << Desc << " responses (" << Val * 100 / Sum
<< "%)\n";
}
~AliasAnalysisCounter() override {
unsigned AASum = No + May + Partial + Must;
unsigned MRSum = NoMR + JustRef + JustMod + MR;
if (AASum + MRSum) { // Print a report if any counted queries occurred...
errs() << "\n===== Alias Analysis Counter Report =====\n"
<< " Analysis counted:\n"
<< " " << AASum << " Total Alias Queries Performed\n";
if (AASum) {
printLine("no alias", No, AASum);
printLine("may alias", May, AASum);
printLine("partial alias", Partial, AASum);
printLine("must alias", Must, AASum);
errs() << " Alias Analysis Counter Summary: " << No * 100 / AASum
<< "%/" << May * 100 / AASum << "%/" << Partial * 100 / AASum
<< "%/" << Must * 100 / AASum << "%\n\n";
}
AliasAnalysisCounter();
~AliasAnalysisCounter() override;
errs() << " " << MRSum << " Total MRI_Mod/MRI_Ref Queries Performed\n";
if (MRSum) {
printLine("no mod/ref", NoMR, MRSum);
printLine("ref", JustRef, MRSum);
printLine("mod", JustMod, MRSum);
printLine("mod/ref", MR, MRSum);
errs() << " MRI_Mod/MRI_Ref Analysis Counter Summary: "
<< NoMR * 100 / MRSum << "%/" << JustRef * 100 / MRSum << "%/"
<< JustMod * 100 / MRSum << "%/" << MR * 100 / MRSum << "%\n\n";
}
}
}
bool runOnModule(Module &M) override;
bool runOnModule(Module &M) override {
this->M = &M;
InitializeAliasAnalysis(this, &M.getDataLayout());
return false;
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
AliasAnalysis::getAnalysisUsage(AU);
AU.addRequired<AliasAnalysis>();
AU.setPreservesAll();
}
void getAnalysisUsage(AnalysisUsage &AU) const override;
/// getAdjustedAnalysisPointer - This method is used when a pass implements
/// an analysis interface through multiple inheritance. If needed, it
/// should override this to adjust the this pointer as needed for the
/// specified pass info.
void *getAdjustedAnalysisPointer(AnalysisID PI) override {
if (PI == &AliasAnalysis::ID)
return (AliasAnalysis *)this;
return this;
}
void *getAdjustedAnalysisPointer(AnalysisID PI) override;
// FIXME: We could count these too...
bool pointsToConstantMemory(const MemoryLocation &Loc,

View File

@ -35,6 +35,65 @@ ModulePass *llvm::createAliasAnalysisCounterPass() {
return new AliasAnalysisCounter();
}
AliasAnalysisCounter::AliasAnalysisCounter() : ModulePass(ID) {
initializeAliasAnalysisCounterPass(*PassRegistry::getPassRegistry());
No = May = Partial = Must = 0;
NoMR = JustRef = JustMod = MR = 0;
}
static void printLine(const char *Desc, unsigned Val, unsigned Sum) {
errs() << " " << Val << " " << Desc << " responses (" << Val * 100 / Sum
<< "%)\n";
}
AliasAnalysisCounter::~AliasAnalysisCounter() {
unsigned AASum = No + May + Partial + Must;
unsigned MRSum = NoMR + JustRef + JustMod + MR;
if (AASum + MRSum) { // Print a report if any counted queries occurred...
errs() << "\n===== Alias Analysis Counter Report =====\n"
<< " Analysis counted:\n"
<< " " << AASum << " Total Alias Queries Performed\n";
if (AASum) {
printLine("no alias", No, AASum);
printLine("may alias", May, AASum);
printLine("partial alias", Partial, AASum);
printLine("must alias", Must, AASum);
errs() << " Alias Analysis Counter Summary: " << No * 100 / AASum << "%/"
<< May * 100 / AASum << "%/" << Partial * 100 / AASum << "%/"
<< Must * 100 / AASum << "%\n\n";
}
errs() << " " << MRSum << " Total MRI_Mod/MRI_Ref Queries Performed\n";
if (MRSum) {
printLine("no mod/ref", NoMR, MRSum);
printLine("ref", JustRef, MRSum);
printLine("mod", JustMod, MRSum);
printLine("mod/ref", MR, MRSum);
errs() << " MRI_Mod/MRI_Ref Analysis Counter Summary: "
<< NoMR * 100 / MRSum << "%/" << JustRef * 100 / MRSum << "%/"
<< JustMod * 100 / MRSum << "%/" << MR * 100 / MRSum << "%\n\n";
}
}
}
bool AliasAnalysisCounter::runOnModule(Module &M) {
this->M = &M;
InitializeAliasAnalysis(this, &M.getDataLayout());
return false;
}
void AliasAnalysisCounter::getAnalysisUsage(AnalysisUsage &AU) const {
AliasAnalysis::getAnalysisUsage(AU);
AU.addRequired<AliasAnalysis>();
AU.setPreservesAll();
}
void *AliasAnalysisCounter::getAdjustedAnalysisPointer(AnalysisID PI) {
if (PI == &AliasAnalysis::ID)
return (AliasAnalysis *)this;
return this;
}
AliasResult AliasAnalysisCounter::alias(const MemoryLocation &LocA,
const MemoryLocation &LocB) {
AliasResult R = getAnalysis<AliasAnalysis>().alias(LocA, LocB);