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"
|
2009-12-23 20:15:13 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-11 22:10:48 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-23 06:37:46 +02:00
|
|
|
#include "llvm/Support/raw_ostream.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>
|
2009-08-30 06:25:40 +02:00
|
|
|
PrintAll("count-aa-print-all-queries", cl::ReallyHidden, cl::init(true));
|
2008-05-13 02:00:25 +02:00
|
|
|
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 {
|
2009-10-25 07:33:48 +01:00
|
|
|
class AliasAnalysisCounter : public ModulePass, public AliasAnalysis {
|
2010-12-10 20:53:05 +01:00
|
|
|
unsigned No, May, Partial, Must;
|
2003-02-26 20:27:05 +01:00
|
|
|
unsigned NoMR, JustRef, JustMod, MR;
|
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
|
2010-08-06 20:33:48 +02:00
|
|
|
AliasAnalysisCounter() : ModulePass(ID) {
|
2010-10-19 19:21:58 +02:00
|
|
|
initializeAliasAnalysisCounterPass(*PassRegistry::getPassRegistry());
|
2010-12-10 20:53:05 +01:00
|
|
|
No = May = Partial = Must = 0;
|
2003-02-26 20:27:05 +01:00
|
|
|
NoMR = JustRef = JustMod = MR = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void printLine(const char *Desc, unsigned Val, unsigned Sum) {
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << " " << Val << " " << Desc << " responses ("
|
2009-08-23 07:17:37 +02:00
|
|
|
<< Val*100/Sum << "%)\n";
|
2003-02-26 20:27:05 +01:00
|
|
|
}
|
2003-02-07 21:39:17 +01:00
|
|
|
~AliasAnalysisCounter() {
|
2010-12-10 20:53:05 +01:00
|
|
|
unsigned AASum = No+May+Partial+Must;
|
2003-02-26 20:27:05 +01:00
|
|
|
unsigned MRSum = NoMR+JustRef+JustMod+MR;
|
|
|
|
if (AASum + MRSum) { // Print a report if any counted queries occurred...
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << "\n===== Alias Analysis Counter Report =====\n"
|
2010-01-22 06:52:51 +01:00
|
|
|
<< " Analysis counted:\n"
|
2009-08-23 07:17:37 +02:00
|
|
|
<< " " << 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);
|
2010-12-10 20:53:05 +01:00
|
|
|
printLine("partial alias", Partial, AASum);
|
2003-06-17 17:07:20 +02:00
|
|
|
printLine("must alias", Must, AASum);
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << " Alias Analysis Counter Summary: " << No*100/AASum << "%/"
|
2010-12-10 20:53:05 +01:00
|
|
|
<< May*100/AASum << "%/"
|
|
|
|
<< Partial*100/AASum << "%/"
|
|
|
|
<< Must*100/AASum<<"%\n\n";
|
2003-06-17 17:07:20 +02:00
|
|
|
}
|
2003-02-26 20:27:05 +01:00
|
|
|
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << " " << 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);
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << " Mod/Ref Analysis Counter Summary: " <<NoMR*100/MRSum
|
2009-08-23 07:17:37 +02:00
|
|
|
<< "%/" << 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
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2010-01-20 21:09:02 +01: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-08-06 20:33:48 +02:00
|
|
|
virtual void *getAdjustedAnalysisPointer(AnalysisID PI) {
|
|
|
|
if (PI == &AliasAnalysis::ID)
|
2010-01-20 21:09:02 +01:00
|
|
|
return (AliasAnalysis*)this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2004-03-15 05:06:46 +01:00
|
|
|
// FIXME: We could count these too...
|
2010-11-08 17:45:26 +01:00
|
|
|
bool pointsToConstantMemory(const Location &Loc, bool OrLocal) {
|
|
|
|
return getAnalysis<AliasAnalysis>().pointsToConstantMemory(Loc, OrLocal);
|
2004-03-15 05:06:46 +01:00
|
|
|
}
|
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...
|
2010-09-14 23:25:10 +02:00
|
|
|
AliasResult alias(const Location &LocA, const Location &LocB);
|
2005-03-23 22:59:07 +01:00
|
|
|
|
2010-08-03 23:48:53 +02:00
|
|
|
ModRefResult getModRefInfo(ImmutableCallSite CS,
|
2010-09-14 23:25:10 +02:00
|
|
|
const Location &Loc);
|
2010-08-03 23:48:53 +02:00
|
|
|
ModRefResult getModRefInfo(ImmutableCallSite CS1,
|
|
|
|
ImmutableCallSite CS2) {
|
2004-12-07 09:11:24 +01:00
|
|
|
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;
|
2010-07-22 01:07:00 +02:00
|
|
|
INITIALIZE_AG_PASS(AliasAnalysisCounter, AliasAnalysis, "count-aa",
|
2010-10-08 00:25:06 +02:00
|
|
|
"Count Alias Analysis Query Responses", false, true, false)
|
2008-05-13 02:00:25 +02:00
|
|
|
|
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
|
2010-09-14 23:25:10 +02:00
|
|
|
AliasAnalysisCounter::alias(const Location &LocA, const Location &LocB) {
|
|
|
|
AliasResult R = getAnalysis<AliasAnalysis>().alias(LocA, LocB);
|
2005-04-21 23:13:18 +02:00
|
|
|
|
2005-03-23 22:59:07 +01:00
|
|
|
const char *AliasString;
|
|
|
|
switch (R) {
|
2009-07-14 18:55:14 +02:00
|
|
|
default: llvm_unreachable("Unknown alias type!");
|
2005-03-23 22:59:07 +01:00
|
|
|
case NoAlias: No++; AliasString = "No alias"; break;
|
|
|
|
case MayAlias: May++; AliasString = "May alias"; break;
|
2010-12-10 20:53:05 +01:00
|
|
|
case PartialAlias: Partial++; AliasString = "Partial alias"; break;
|
2005-03-23 22:59:07 +01:00
|
|
|
case MustAlias: Must++; AliasString = "Must alias"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PrintAll || (PrintAllFailures && R == MayAlias)) {
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << AliasString << ":\t";
|
2010-09-14 23:25:10 +02:00
|
|
|
errs() << "[" << LocA.Size << "B] ";
|
|
|
|
WriteAsOperand(errs(), LocA.Ptr, true, M);
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << ", ";
|
2010-09-14 23:25:10 +02:00
|
|
|
errs() << "[" << LocB.Size << "B] ";
|
|
|
|
WriteAsOperand(errs(), LocB.Ptr, true, M);
|
2009-12-23 23:49:57 +01:00
|
|
|
errs() << "\n";
|
2005-03-23 22:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
2005-04-21 23:13:18 +02:00
|
|
|
AliasAnalysis::ModRefResult
|
2010-08-03 23:48:53 +02:00
|
|
|
AliasAnalysisCounter::getModRefInfo(ImmutableCallSite CS,
|
2010-09-14 23:25:10 +02:00
|
|
|
const Location &Loc) {
|
|
|
|
ModRefResult R = getAnalysis<AliasAnalysis>().getModRefInfo(CS, Loc);
|
2005-03-23 22:59:07 +01:00
|
|
|
|
|
|
|
const char *MRString;
|
|
|
|
switch (R) {
|
2009-07-14 18:55:14 +02:00
|
|
|
default: llvm_unreachable("Unknown mod/ref type!");
|
2005-03-23 22:59:07 +01: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-23 23:49:57 +01:00
|
|
|
errs() << MRString << ": Ptr: ";
|
2010-09-14 23:25:10 +02:00
|
|
|
errs() << "[" << Loc.Size << "B] ";
|
|
|
|
WriteAsOperand(errs(), Loc.Ptr, true, M);
|
2010-03-01 18:42:55 +01:00
|
|
|
errs() << "\t<->" << *CS.getInstruction() << '\n';
|
2005-03-23 22:59:07 +01:00
|
|
|
}
|
|
|
|
return R;
|
|
|
|
}
|