2003-02-07 19:46:03 +00:00
|
|
|
//===- AliasAnalysisCounter.cpp - Alias Analysis Query Counter ------------===//
|
2003-10-20 19:43:21 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2003-02-07 19:46:03 +00: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 22:01:16 +00:00
|
|
|
#include "llvm/Analysis/Passes.h"
|
2003-02-07 19:46:03 +00:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include <iostream>
|
2003-12-10 15:34:03 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2003-02-07 19:46:03 +00:00
|
|
|
namespace {
|
2004-09-20 04:48:05 +00:00
|
|
|
class AliasAnalysisCounter : public ModulePass, public AliasAnalysis {
|
2003-02-07 20:39:17 +00:00
|
|
|
unsigned No, May, Must;
|
2003-02-26 19:27:05 +00:00
|
|
|
unsigned NoMR, JustRef, JustMod, MR;
|
2003-02-07 20:39:17 +00:00
|
|
|
const char *Name;
|
|
|
|
public:
|
2003-02-26 19:27:05 +00:00
|
|
|
AliasAnalysisCounter() {
|
|
|
|
No = May = Must = 0;
|
|
|
|
NoMR = JustRef = JustMod = MR = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void printLine(const char *Desc, unsigned Val, unsigned Sum) {
|
|
|
|
std::cerr << " " << Val << " " << Desc << " responses ("
|
|
|
|
<< Val*100/Sum << "%)\n";
|
|
|
|
}
|
2003-02-07 20:39:17 +00:00
|
|
|
~AliasAnalysisCounter() {
|
2003-02-26 19:27:05 +00:00
|
|
|
unsigned AASum = No+May+Must;
|
|
|
|
unsigned MRSum = NoMR+JustRef+JustMod+MR;
|
|
|
|
if (AASum + MRSum) { // Print a report if any counted queries occurred...
|
2003-02-07 20:39:17 +00:00
|
|
|
std::cerr
|
|
|
|
<< "\n===== Alias Analysis Counter Report =====\n"
|
|
|
|
<< " Analysis counted: " << Name << "\n"
|
2003-02-26 19:27:05 +00:00
|
|
|
<< " " << AASum << " Total Alias Queries Performed\n";
|
2003-06-17 15:07:20 +00:00
|
|
|
if (AASum) {
|
|
|
|
printLine("no alias", No, AASum);
|
|
|
|
printLine("may alias", May, AASum);
|
|
|
|
printLine("must alias", Must, AASum);
|
|
|
|
std::cerr
|
|
|
|
<< " Alias Analysis Counter Summary: " << No*100/AASum << "%/"
|
|
|
|
<< May*100/AASum << "%/" << Must*100/AASum<<"%\n\n";
|
|
|
|
}
|
2003-02-26 19:27:05 +00:00
|
|
|
|
|
|
|
std::cerr
|
|
|
|
<< " " << MRSum << " Total Mod/Ref Queries Performed\n";
|
2003-06-17 15:07:20 +00:00
|
|
|
if (MRSum) {
|
|
|
|
printLine("no mod/ref", NoMR, MRSum);
|
|
|
|
printLine("ref", JustRef, MRSum);
|
|
|
|
printLine("mod", JustMod, MRSum);
|
|
|
|
printLine("mod/ref", MR, MRSum);
|
|
|
|
std::cerr
|
|
|
|
<< " Mod/Ref Analysis Counter Summary: " << NoMR*100/MRSum<< "%/"
|
|
|
|
<< JustRef*100/MRSum << "%/" << JustMod*100/MRSum << "%/"
|
|
|
|
<< MR*100/MRSum <<"%\n\n";
|
|
|
|
}
|
2003-02-07 20:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-20 04:48:05 +00:00
|
|
|
bool runOnModule(Module &M) {
|
2003-02-26 19:27:05 +00:00
|
|
|
InitializeAliasAnalysis(this);
|
2003-02-07 20:39:17 +00:00
|
|
|
Name = dynamic_cast<Pass*>(&getAnalysis<AliasAnalysis>())->getPassName();
|
|
|
|
return false;
|
|
|
|
}
|
2003-02-07 19:46:03 +00:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
2003-02-26 19:27:05 +00:00
|
|
|
AliasAnalysis::getAnalysisUsage(AU);
|
2003-02-07 19:46:03 +00:00
|
|
|
AU.addRequired<AliasAnalysis>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2003-02-26 19:27:05 +00:00
|
|
|
AliasResult count(AliasResult R) {
|
2003-02-07 19:46:03 +00:00
|
|
|
switch (R) {
|
|
|
|
default: assert(0 && "Unknown alias type!");
|
|
|
|
case NoAlias: No++; return NoAlias;
|
|
|
|
case MayAlias: May++; return MayAlias;
|
|
|
|
case MustAlias: Must++; return MustAlias;
|
|
|
|
}
|
|
|
|
}
|
2003-02-26 19:27:05 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2004-03-15 04:06:46 +00:00
|
|
|
|
|
|
|
// FIXME: We could count these too...
|
|
|
|
bool pointsToConstantMemory(const Value *P) {
|
|
|
|
return getAnalysis<AliasAnalysis>().pointsToConstantMemory(P);
|
|
|
|
}
|
|
|
|
bool doesNotAccessMemory(Function *F) {
|
|
|
|
return getAnalysis<AliasAnalysis>().doesNotAccessMemory(F);
|
|
|
|
}
|
|
|
|
bool onlyReadsMemory(Function *F) {
|
|
|
|
return getAnalysis<AliasAnalysis>().onlyReadsMemory(F);
|
|
|
|
}
|
|
|
|
|
2003-02-07 19:46:03 +00:00
|
|
|
|
|
|
|
// Forwarding functions: just delegate to a real AA implementation, counting
|
|
|
|
// the number of responses...
|
2003-02-26 19:27:05 +00:00
|
|
|
AliasResult alias(const Value *V1, unsigned V1Size,
|
|
|
|
const Value *V2, unsigned V2Size) {
|
|
|
|
return count(getAnalysis<AliasAnalysis>().alias(V1, V1Size, V2, V2Size));
|
2003-02-07 19:46:03 +00:00
|
|
|
}
|
2003-02-26 19:27:05 +00:00
|
|
|
ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size) {
|
|
|
|
return count(getAnalysis<AliasAnalysis>().getModRefInfo(CS, P, Size));
|
2003-02-07 19:46:03 +00:00
|
|
|
}
|
2004-12-07 08:11:24 +00:00
|
|
|
ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) {
|
|
|
|
return AliasAnalysis::getModRefInfo(CS1,CS2);
|
|
|
|
}
|
2003-02-07 19:46:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RegisterOpt<AliasAnalysisCounter>
|
|
|
|
X("count-aa", "Count Alias Analysis Query Responses");
|
|
|
|
RegisterAnalysisGroup<AliasAnalysis, AliasAnalysisCounter> Y;
|
|
|
|
}
|
2005-01-08 22:01:16 +00:00
|
|
|
|
|
|
|
ModulePass *llvm::createAliasAnalysisCounterPass() {
|
|
|
|
return new AliasAnalysisCounter();
|
|
|
|
}
|