forked from OSchip/llvm-project
Add two options to allow -count-aa to print queries either (1) all queries,
or (2) only queries that are not successful (e.g. return may alias) llvm-svn: 20790
This commit is contained in:
parent
9c64d9c2b5
commit
ccb6faad7e
|
@ -13,16 +13,24 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Analysis/Passes.h"
|
||||
#include "llvm/Analysis/AliasAnalysis.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Analysis/AliasAnalysis.h"
|
||||
#include "llvm/Assembly/Writer.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include <iostream>
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
cl::opt<bool>
|
||||
PrintAll("count-aa-print-all-queries", cl::ReallyHidden);
|
||||
cl::opt<bool>
|
||||
PrintAllFailures("count-aa-print-all-failed-queries", cl::ReallyHidden);
|
||||
|
||||
class AliasAnalysisCounter : public ModulePass, public AliasAnalysis {
|
||||
unsigned No, May, Must;
|
||||
unsigned NoMR, JustRef, JustMod, MR;
|
||||
const char *Name;
|
||||
Module *M;
|
||||
public:
|
||||
AliasAnalysisCounter() {
|
||||
No = May = Must = 0;
|
||||
|
@ -66,6 +74,7 @@ namespace {
|
|||
}
|
||||
|
||||
bool runOnModule(Module &M) {
|
||||
this->M = &M;
|
||||
InitializeAliasAnalysis(this);
|
||||
Name = dynamic_cast<Pass*>(&getAnalysis<AliasAnalysis>())->getPassName();
|
||||
return false;
|
||||
|
@ -77,24 +86,6 @@ namespace {
|
|||
AU.setPreservesAll();
|
||||
}
|
||||
|
||||
AliasResult count(AliasResult R) {
|
||||
switch (R) {
|
||||
default: assert(0 && "Unknown alias type!");
|
||||
case NoAlias: No++; return NoAlias;
|
||||
case MayAlias: May++; return MayAlias;
|
||||
case MustAlias: Must++; return MustAlias;
|
||||
}
|
||||
}
|
||||
ModRefResult count(ModRefResult R) {
|
||||
switch (R) {
|
||||
default: assert(0 && "Unknown mod/ref type!");
|
||||
case NoModRef: NoMR++; return NoModRef;
|
||||
case Ref: JustRef++; return Ref;
|
||||
case Mod: JustMod++; return Mod;
|
||||
case ModRef: MR++; return ModRef;
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: We could count these too...
|
||||
bool pointsToConstantMemory(const Value *P) {
|
||||
return getAnalysis<AliasAnalysis>().pointsToConstantMemory(P);
|
||||
|
@ -110,12 +101,9 @@ namespace {
|
|||
// Forwarding functions: just delegate to a real AA implementation, counting
|
||||
// the number of responses...
|
||||
AliasResult alias(const Value *V1, unsigned V1Size,
|
||||
const Value *V2, unsigned V2Size) {
|
||||
return count(getAnalysis<AliasAnalysis>().alias(V1, V1Size, V2, V2Size));
|
||||
}
|
||||
ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size) {
|
||||
return count(getAnalysis<AliasAnalysis>().getModRefInfo(CS, P, Size));
|
||||
}
|
||||
const Value *V2, unsigned V2Size);
|
||||
|
||||
ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size);
|
||||
ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) {
|
||||
return AliasAnalysis::getModRefInfo(CS1,CS2);
|
||||
}
|
||||
|
@ -129,3 +117,49 @@ namespace {
|
|||
ModulePass *llvm::createAliasAnalysisCounterPass() {
|
||||
return new AliasAnalysisCounter();
|
||||
}
|
||||
|
||||
AliasAnalysis::AliasResult
|
||||
AliasAnalysisCounter::alias(const Value *V1, unsigned V1Size,
|
||||
const Value *V2, unsigned V2Size) {
|
||||
AliasResult R = getAnalysis<AliasAnalysis>().alias(V1, V1Size, V2, V2Size);
|
||||
|
||||
const char *AliasString;
|
||||
switch (R) {
|
||||
default: assert(0 && "Unknown alias type!");
|
||||
case NoAlias: No++; AliasString = "No alias"; break;
|
||||
case MayAlias: May++; AliasString = "May alias"; break;
|
||||
case MustAlias: Must++; AliasString = "Must alias"; break;
|
||||
}
|
||||
|
||||
if (PrintAll || (PrintAllFailures && R == MayAlias)) {
|
||||
std::cerr << AliasString << ":\t";
|
||||
std::cerr << "[" << V1Size << "B] ";
|
||||
WriteAsOperand(std::cerr, V1, true, true, M) << ", ";
|
||||
std::cerr << "[" << V2Size << "B] ";
|
||||
WriteAsOperand(std::cerr, V2, true, true, M) << "\n";
|
||||
}
|
||||
|
||||
return R;
|
||||
}
|
||||
|
||||
AliasAnalysis::ModRefResult
|
||||
AliasAnalysisCounter::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
|
||||
ModRefResult R = getAnalysis<AliasAnalysis>().getModRefInfo(CS, P, Size);
|
||||
|
||||
const char *MRString;
|
||||
switch (R) {
|
||||
default: assert(0 && "Unknown mod/ref type!");
|
||||
case NoModRef: NoMR++; MRString = "NoModRef"; break;
|
||||
case Ref: JustRef++; MRString = "JustRef"; break;
|
||||
case Mod: JustMod++; MRString = "JustMod"; break;
|
||||
case ModRef: MR++; MRString = "ModRef"; break;
|
||||
}
|
||||
|
||||
if (PrintAll || (PrintAllFailures && R == ModRef)) {
|
||||
std::cerr << MRString << ": Ptr: ";
|
||||
std::cerr << "[" << Size << "B] ";
|
||||
WriteAsOperand(std::cerr, P, true, true, M);
|
||||
std::cerr << "\t<->" << *CS.getInstruction();
|
||||
}
|
||||
return R;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue