2003-02-07 20:46:03 +01:00
|
|
|
//===- AliasAnalysisCounter.cpp - Alias Analysis Query Counter ------------===//
|
2005-04-21 23:13:18 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:13:18 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-02-07 20:46:03 +01: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-08 23:01:16 +01:00
|
|
|
#include "llvm/Analysis/Passes.h"
|
2003-02-07 20:46:03 +01:00
|
|
|
#include "llvm/Pass.h"
|
2005-03-23 22:59:07 +01:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
|
|
|
#include "llvm/Assembly/Writer.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
2007-02-06 00:42:17 +01:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2006-11-28 23:46:12 +01:00
|
|
|
#include "llvm/Support/Streams.h"
|
2003-12-10 16:34:03 +01:00
|
|
|
using namespace llvm;
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2008-05-13 02:00:25 +02:00
|
|
|
static cl::opt<bool>
|
|
|
|
PrintAll("count-aa-print-all-queries", cl::ReallyHidden);
|
|
|
|
static cl::opt<bool>
|
|
|
|
PrintAllFailures("count-aa-print-all-failed-queries", cl::ReallyHidden);
|
2005-03-23 22:59:07 +01:00
|
|
|
|
2008-05-13 02:00:25 +02:00
|
|
|
namespace {
|
2007-02-06 00:42:17 +01:00
|
|
|
class VISIBILITY_HIDDEN AliasAnalysisCounter
|
|
|
|
: public ModulePass, public AliasAnalysis {
|
2003-02-07 21:39:17 +01:00
|
|
|
unsigned No, May, Must;
|
2003-02-26 20:27:05 +01:00
|
|
|
unsigned NoMR, JustRef, JustMod, MR;
|
2003-02-07 21:39:17 +01:00
|
|
|
const char *Name;
|
2005-03-23 22:59:07 +01:00
|
|
|
Module *M;
|
2003-02-07 21:39:17 +01:00
|
|
|
public:
|
2007-05-03 03:11:54 +02:00
|
|
|
static char ID; // Class identification, replacement for typeinfo
|
2008-09-04 19:05:41 +02:00
|
|
|
AliasAnalysisCounter() : ModulePass(&ID) {
|
2003-02-26 20:27:05 +01:00
|
|
|
No = May = Must = 0;
|
|
|
|
NoMR = JustRef = JustMod = MR = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void printLine(const char *Desc, unsigned Val, unsigned Sum) {
|
2006-12-07 02:30:32 +01:00
|
|
|
cerr << " " << Val << " " << Desc << " responses ("
|
|
|
|
<< Val*100/Sum << "%)\n";
|
2003-02-26 20:27:05 +01:00
|
|
|
}
|
2003-02-07 21:39:17 +01:00
|
|
|
~AliasAnalysisCounter() {
|
2003-02-26 20:27:05 +01:00
|
|
|
unsigned AASum = No+May+Must;
|
|
|
|
unsigned MRSum = NoMR+JustRef+JustMod+MR;
|
|
|
|
if (AASum + MRSum) { // Print a report if any counted queries occurred...
|
2006-12-07 02:30:32 +01:00
|
|
|
cerr << "\n===== Alias Analysis Counter Report =====\n"
|
|
|
|
<< " Analysis counted: " << Name << "\n"
|
|
|
|
<< " " << AASum << " Total Alias Queries Performed\n";
|
2003-06-17 17:07:20 +02:00
|
|
|
if (AASum) {
|
|
|
|
printLine("no alias", No, AASum);
|
|
|
|
printLine("may alias", May, AASum);
|
|
|
|
printLine("must alias", Must, AASum);
|
2006-12-07 02:30:32 +01:00
|
|
|
cerr << " Alias Analysis Counter Summary: " << No*100/AASum << "%/"
|
|
|
|
<< May*100/AASum << "%/" << Must*100/AASum<<"%\n\n";
|
2003-06-17 17:07:20 +02:00
|
|
|
}
|
2003-02-26 20:27:05 +01:00
|
|
|
|
2006-12-07 02:30:32 +01:00
|
|
|
cerr << " " << MRSum << " Total Mod/Ref Queries Performed\n";
|
2003-06-17 17:07:20 +02:00
|
|
|
if (MRSum) {
|
|
|
|
printLine("no mod/ref", NoMR, MRSum);
|
|
|
|
printLine("ref", JustRef, MRSum);
|
|
|
|
printLine("mod", JustMod, MRSum);
|
|
|
|
printLine("mod/ref", MR, MRSum);
|
2006-12-07 02:30:32 +01:00
|
|
|
cerr << " Mod/Ref Analysis Counter Summary: " <<NoMR*100/MRSum<< "%/"
|
|
|
|
<< JustRef*100/MRSum << "%/" << JustMod*100/MRSum << "%/"
|
|
|
|
<< MR*100/MRSum <<"%\n\n";
|
2003-06-17 17:07:20 +02:00
|
|
|
}
|
2003-02-07 21:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-20 06:48:05 +02:00
|
|
|
bool runOnModule(Module &M) {
|
2005-03-23 22:59:07 +01:00
|
|
|
this->M = &M;
|
2003-02-26 20:27:05 +01:00
|
|
|
InitializeAliasAnalysis(this);
|
2003-02-07 21:39:17 +01:00
|
|
|
Name = dynamic_cast<Pass*>(&getAnalysis<AliasAnalysis>())->getPassName();
|
|
|
|
return false;
|
|
|
|
}
|
2003-02-07 20:46:03 +01:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
2003-02-26 20:27:05 +01:00
|
|
|
AliasAnalysis::getAnalysisUsage(AU);
|
2003-02-07 20:46:03 +01:00
|
|
|
AU.addRequired<AliasAnalysis>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2004-03-15 05:06:46 +01:00
|
|
|
// FIXME: We could count these too...
|
|
|
|
bool pointsToConstantMemory(const Value *P) {
|
|
|
|
return getAnalysis<AliasAnalysis>().pointsToConstantMemory(P);
|
|
|
|
}
|
2007-12-01 08:51:45 +01:00
|
|
|
bool doesNotAccessMemory(CallSite CS) {
|
|
|
|
return getAnalysis<AliasAnalysis>().doesNotAccessMemory(CS);
|
|
|
|
}
|
2004-03-15 05:06:46 +01:00
|
|
|
bool doesNotAccessMemory(Function *F) {
|
|
|
|
return getAnalysis<AliasAnalysis>().doesNotAccessMemory(F);
|
|
|
|
}
|
2007-12-01 08:51:45 +01:00
|
|
|
bool onlyReadsMemory(CallSite CS) {
|
|
|
|
return getAnalysis<AliasAnalysis>().onlyReadsMemory(CS);
|
|
|
|
}
|
2004-03-15 05:06:46 +01:00
|
|
|
bool onlyReadsMemory(Function *F) {
|
|
|
|
return getAnalysis<AliasAnalysis>().onlyReadsMemory(F);
|
|
|
|
}
|
2005-04-21 23:13:18 +02:00
|
|
|
|
|
|
|
|
2003-02-07 20:46:03 +01:00
|
|
|
// Forwarding functions: just delegate to a real AA implementation, counting
|
|
|
|
// the number of responses...
|
2003-02-26 20:27:05 +01:00
|
|
|
AliasResult alias(const Value *V1, unsigned V1Size,
|
2005-03-23 22:59:07 +01:00
|
|
|
const Value *V2, unsigned V2Size);
|
|
|
|
|
|
|
|
ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size);
|
2004-12-07 09:11:24 +01:00
|
|
|
ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) {
|
|
|
|
return AliasAnalysis::getModRefInfo(CS1,CS2);
|
|
|
|
}
|
2003-02-07 20:46:03 +01:00
|
|
|
};
|
|
|
|
}
|
2005-01-08 23:01:16 +01:00
|
|
|
|
2008-05-13 02:00:25 +02: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-08 23:01:16 +01:00
|
|
|
ModulePass *llvm::createAliasAnalysisCounterPass() {
|
|
|
|
return new AliasAnalysisCounter();
|
|
|
|
}
|
2005-03-23 22:59:07 +01:00
|
|
|
|
2005-04-21 23:13:18 +02:00
|
|
|
AliasAnalysis::AliasResult
|
2005-03-23 22:59:07 +01:00
|
|
|
AliasAnalysisCounter::alias(const Value *V1, unsigned V1Size,
|
|
|
|
const Value *V2, unsigned V2Size) {
|
|
|
|
AliasResult R = getAnalysis<AliasAnalysis>().alias(V1, V1Size, V2, V2Size);
|
2005-04-21 23:13:18 +02:00
|
|
|
|
2005-03-23 22:59:07 +01:00
|
|
|
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)) {
|
2006-12-07 02:30:32 +01:00
|
|
|
cerr << AliasString << ":\t";
|
|
|
|
cerr << "[" << V1Size << "B] ";
|
2008-08-19 06:42:37 +02:00
|
|
|
WriteAsOperand(*cerr.stream(), V1, true, M);
|
|
|
|
cerr << ", ";
|
2006-12-07 02:30:32 +01:00
|
|
|
cerr << "[" << V2Size << "B] ";
|
2008-08-19 06:42:37 +02:00
|
|
|
WriteAsOperand(*cerr.stream(), V2, true, M);
|
|
|
|
cerr << "\n";
|
2005-03-23 22:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
2005-04-21 23:13:18 +02:00
|
|
|
AliasAnalysis::ModRefResult
|
2005-03-23 22:59:07 +01:00
|
|
|
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)) {
|
2006-12-07 02:30:32 +01:00
|
|
|
cerr << MRString << ": Ptr: ";
|
|
|
|
cerr << "[" << Size << "B] ";
|
2006-12-07 21:28:15 +01:00
|
|
|
WriteAsOperand(*cerr.stream(), P, true, M);
|
2006-12-07 02:30:32 +01:00
|
|
|
cerr << "\t<->" << *CS.getInstruction();
|
2005-03-23 22:59:07 +01:00
|
|
|
}
|
|
|
|
return R;
|
|
|
|
}
|