2003-02-08 03:46:03 +08:00
|
|
|
//===- AliasAnalysisCounter.cpp - Alias Analysis Query Counter ------------===//
|
2005-04-22 05:13:18 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 05:13:18 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-02-08 03:46:03 +08:00
|
|
|
//
|
|
|
|
// This file implements a pass which can be used to count how many alias queries
|
|
|
|
// are being made and how the alias analysis implementation being used responds.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-01-09 06:01:16 +08:00
|
|
|
#include "llvm/Analysis/Passes.h"
|
2003-02-08 03:46:03 +08:00
|
|
|
#include "llvm/Pass.h"
|
2005-03-24 05:59:07 +08:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
|
|
|
#include "llvm/Assembly/Writer.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-12-24 03:15:13 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-12 04:10:48 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-23 12:37:46 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2003-12-10 23:34:03 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2008-05-13 08:00:25 +08:00
|
|
|
static cl::opt<bool>
|
2009-08-30 12:25:40 +08:00
|
|
|
PrintAll("count-aa-print-all-queries", cl::ReallyHidden, cl::init(true));
|
2008-05-13 08:00:25 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
PrintAllFailures("count-aa-print-all-failed-queries", cl::ReallyHidden);
|
2005-03-24 05:59:07 +08:00
|
|
|
|
2008-05-13 08:00:25 +08:00
|
|
|
namespace {
|
2009-10-25 14:33:48 +08:00
|
|
|
class AliasAnalysisCounter : public ModulePass, public AliasAnalysis {
|
2003-02-08 04:39:17 +08:00
|
|
|
unsigned No, May, Must;
|
2003-02-27 03:27:05 +08:00
|
|
|
unsigned NoMR, JustRef, JustMod, MR;
|
2005-03-24 05:59:07 +08:00
|
|
|
Module *M;
|
2003-02-08 04:39:17 +08:00
|
|
|
public:
|
2007-05-03 09:11:54 +08:00
|
|
|
static char ID; // Class identification, replacement for typeinfo
|
2008-09-05 01:05:41 +08:00
|
|
|
AliasAnalysisCounter() : ModulePass(&ID) {
|
2003-02-27 03:27:05 +08:00
|
|
|
No = May = Must = 0;
|
|
|
|
NoMR = JustRef = JustMod = MR = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void printLine(const char *Desc, unsigned Val, unsigned Sum) {
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " " << Val << " " << Desc << " responses ("
|
2009-08-23 13:17:37 +08:00
|
|
|
<< Val*100/Sum << "%)\n";
|
2003-02-27 03:27:05 +08:00
|
|
|
}
|
2003-02-08 04:39:17 +08:00
|
|
|
~AliasAnalysisCounter() {
|
2003-02-27 03:27:05 +08:00
|
|
|
unsigned AASum = No+May+Must;
|
|
|
|
unsigned MRSum = NoMR+JustRef+JustMod+MR;
|
|
|
|
if (AASum + MRSum) { // Print a report if any counted queries occurred...
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << "\n===== Alias Analysis Counter Report =====\n"
|
2010-01-22 13:52:51 +08:00
|
|
|
<< " Analysis counted:\n"
|
2009-08-23 13:17:37 +08:00
|
|
|
<< " " << AASum << " Total Alias Queries Performed\n";
|
2003-06-17 23:07:20 +08:00
|
|
|
if (AASum) {
|
|
|
|
printLine("no alias", No, AASum);
|
|
|
|
printLine("may alias", May, AASum);
|
|
|
|
printLine("must alias", Must, AASum);
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " Alias Analysis Counter Summary: " << No*100/AASum << "%/"
|
2009-08-23 13:17:37 +08:00
|
|
|
<< May*100/AASum << "%/" << Must*100/AASum<<"%\n\n";
|
2003-06-17 23:07:20 +08:00
|
|
|
}
|
2003-02-27 03:27:05 +08:00
|
|
|
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " " << MRSum << " Total Mod/Ref Queries Performed\n";
|
2003-06-17 23:07:20 +08:00
|
|
|
if (MRSum) {
|
|
|
|
printLine("no mod/ref", NoMR, MRSum);
|
|
|
|
printLine("ref", JustRef, MRSum);
|
|
|
|
printLine("mod", JustMod, MRSum);
|
|
|
|
printLine("mod/ref", MR, MRSum);
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " Mod/Ref Analysis Counter Summary: " <<NoMR*100/MRSum
|
2009-08-23 13:17:37 +08:00
|
|
|
<< "%/" << JustRef*100/MRSum << "%/" << JustMod*100/MRSum
|
|
|
|
<< "%/" << MR*100/MRSum <<"%\n\n";
|
2003-06-17 23:07:20 +08:00
|
|
|
}
|
2003-02-08 04:39:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-20 12:48:05 +08:00
|
|
|
bool runOnModule(Module &M) {
|
2005-03-24 05:59:07 +08:00
|
|
|
this->M = &M;
|
2003-02-27 03:27:05 +08:00
|
|
|
InitializeAliasAnalysis(this);
|
2003-02-08 04:39:17 +08:00
|
|
|
return false;
|
|
|
|
}
|
2003-02-08 03:46:03 +08:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
2003-02-27 03:27:05 +08:00
|
|
|
AliasAnalysis::getAnalysisUsage(AU);
|
2003-02-08 03:46:03 +08:00
|
|
|
AU.addRequired<AliasAnalysis>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2010-01-21 04:09:02 +08:00
|
|
|
/// 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.
|
2010-07-20 14:52:42 +08:00
|
|
|
virtual void *getAdjustedAnalysisPointer(const StaticPassInfo *PI) {
|
2010-01-21 04:09:02 +08:00
|
|
|
if (PI->isPassID(&AliasAnalysis::ID))
|
|
|
|
return (AliasAnalysis*)this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2004-03-15 12:06:46 +08:00
|
|
|
// FIXME: We could count these too...
|
|
|
|
bool pointsToConstantMemory(const Value *P) {
|
|
|
|
return getAnalysis<AliasAnalysis>().pointsToConstantMemory(P);
|
|
|
|
}
|
2005-04-22 05:13:18 +08:00
|
|
|
|
2003-02-08 03:46:03 +08:00
|
|
|
// Forwarding functions: just delegate to a real AA implementation, counting
|
|
|
|
// the number of responses...
|
2003-02-27 03:27:05 +08:00
|
|
|
AliasResult alias(const Value *V1, unsigned V1Size,
|
2005-03-24 05:59:07 +08:00
|
|
|
const Value *V2, unsigned V2Size);
|
|
|
|
|
|
|
|
ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size);
|
2004-12-07 16:11:24 +08:00
|
|
|
ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) {
|
|
|
|
return AliasAnalysis::getModRefInfo(CS1,CS2);
|
|
|
|
}
|
2003-02-08 03:46:03 +08:00
|
|
|
};
|
|
|
|
}
|
2005-01-09 06:01:16 +08:00
|
|
|
|
2008-05-13 08:00:25 +08:00
|
|
|
char AliasAnalysisCounter::ID = 0;
|
|
|
|
static RegisterPass<AliasAnalysisCounter>
|
|
|
|
X("count-aa", "Count Alias Analysis Query Responses", false, true);
|
|
|
|
static RegisterAnalysisGroup<AliasAnalysis> Y(X);
|
|
|
|
|
2005-01-09 06:01:16 +08:00
|
|
|
ModulePass *llvm::createAliasAnalysisCounterPass() {
|
|
|
|
return new AliasAnalysisCounter();
|
|
|
|
}
|
2005-03-24 05:59:07 +08:00
|
|
|
|
2005-04-22 05:13:18 +08:00
|
|
|
AliasAnalysis::AliasResult
|
2005-03-24 05:59:07 +08:00
|
|
|
AliasAnalysisCounter::alias(const Value *V1, unsigned V1Size,
|
|
|
|
const Value *V2, unsigned V2Size) {
|
|
|
|
AliasResult R = getAnalysis<AliasAnalysis>().alias(V1, V1Size, V2, V2Size);
|
2005-04-22 05:13:18 +08:00
|
|
|
|
2005-03-24 05:59:07 +08:00
|
|
|
const char *AliasString;
|
|
|
|
switch (R) {
|
2009-07-15 00:55:14 +08:00
|
|
|
default: llvm_unreachable("Unknown alias type!");
|
2005-03-24 05:59:07 +08:00
|
|
|
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)) {
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << AliasString << ":\t";
|
|
|
|
errs() << "[" << V1Size << "B] ";
|
|
|
|
WriteAsOperand(errs(), V1, true, M);
|
|
|
|
errs() << ", ";
|
|
|
|
errs() << "[" << V2Size << "B] ";
|
|
|
|
WriteAsOperand(errs(), V2, true, M);
|
|
|
|
errs() << "\n";
|
2005-03-24 05:59:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
2005-04-22 05:13:18 +08:00
|
|
|
AliasAnalysis::ModRefResult
|
2005-03-24 05:59:07 +08:00
|
|
|
AliasAnalysisCounter::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
|
|
|
|
ModRefResult R = getAnalysis<AliasAnalysis>().getModRefInfo(CS, P, Size);
|
|
|
|
|
|
|
|
const char *MRString;
|
|
|
|
switch (R) {
|
2009-07-15 00:55:14 +08:00
|
|
|
default: llvm_unreachable("Unknown mod/ref type!");
|
2005-03-24 05:59:07 +08:00
|
|
|
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)) {
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << MRString << ": Ptr: ";
|
|
|
|
errs() << "[" << Size << "B] ";
|
|
|
|
WriteAsOperand(errs(), P, true, M);
|
2010-03-02 01:42:55 +08:00
|
|
|
errs() << "\t<->" << *CS.getInstruction() << '\n';
|
2005-03-24 05:59:07 +08:00
|
|
|
}
|
|
|
|
return R;
|
|
|
|
}
|