2003-02-06 21:29:49 +00:00
|
|
|
//===- AliasAnalysisEvaluator.cpp - Alias Analysis Accuracy Evaluator -----===//
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-02-06 21:29:49 +00:00
|
|
|
//
|
|
|
|
// This file implements a simple N^2 alias analysis accuracy evaluator.
|
|
|
|
// Basically, for each function in the program, it simply queries to see how the
|
|
|
|
// alias analysis implementation answers alias queries between each pair of
|
|
|
|
// pointers in the function.
|
|
|
|
//
|
|
|
|
// This is inspired and adapted from code by: Naveen Neelakantam, Francesco
|
|
|
|
// Spadini, and Wojciech Stryjewski.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Analysis/Passes.h"
|
|
|
|
#include "llvm/ADT/SetVector.h"
|
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
2014-03-04 10:30:26 +00:00
|
|
|
#include "llvm/IR/InstIterator.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2004-03-12 06:15:08 +00:00
|
|
|
#include "llvm/Pass.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-12-23 19:21:19 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-25 00:23:56 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2003-12-10 15:33:59 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
static cl::opt<bool> PrintAll("print-all-alias-modref-info", cl::ReallyHidden);
|
2004-07-17 06:28:49 +00:00
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
static cl::opt<bool> PrintNoAlias("print-no-aliases", cl::ReallyHidden);
|
|
|
|
static cl::opt<bool> PrintMayAlias("print-may-aliases", cl::ReallyHidden);
|
2010-12-10 19:52:40 +00:00
|
|
|
static cl::opt<bool> PrintPartialAlias("print-partial-aliases", cl::ReallyHidden);
|
2008-05-13 00:00:25 +00:00
|
|
|
static cl::opt<bool> PrintMustAlias("print-must-aliases", cl::ReallyHidden);
|
2004-03-12 06:15:08 +00:00
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
static cl::opt<bool> PrintNoModRef("print-no-modref", cl::ReallyHidden);
|
|
|
|
static cl::opt<bool> PrintMod("print-mod", cl::ReallyHidden);
|
|
|
|
static cl::opt<bool> PrintRef("print-ref", cl::ReallyHidden);
|
|
|
|
static cl::opt<bool> PrintModRef("print-modref", cl::ReallyHidden);
|
2003-02-09 20:40:13 +00:00
|
|
|
|
2013-03-22 22:34:41 +00:00
|
|
|
static cl::opt<bool> EvalTBAA("evaluate-tbaa", cl::ReallyHidden);
|
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
namespace {
|
2010-07-07 14:27:09 +00:00
|
|
|
class AAEval : public FunctionPass {
|
2010-12-10 19:52:40 +00:00
|
|
|
unsigned NoAlias, MayAlias, PartialAlias, MustAlias;
|
2004-03-12 06:15:08 +00:00
|
|
|
unsigned NoModRef, Mod, Ref, ModRef;
|
2003-02-06 21:29:49 +00:00
|
|
|
|
2010-07-07 14:27:09 +00:00
|
|
|
public:
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2010-10-19 17:21:58 +00:00
|
|
|
AAEval() : FunctionPass(ID) {
|
|
|
|
initializeAAEvalPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2007-05-01 21:15:47 +00:00
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2003-02-06 21:29:49 +00:00
|
|
|
AU.addRequired<AliasAnalysis>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
bool doInitialization(Module &M) override {
|
2010-12-10 19:52:40 +00:00
|
|
|
NoAlias = MayAlias = PartialAlias = MustAlias = 0;
|
2004-03-12 06:15:08 +00:00
|
|
|
NoModRef = Mod = Ref = ModRef = 0;
|
2004-07-17 06:28:49 +00:00
|
|
|
|
|
|
|
if (PrintAll) {
|
2010-12-10 19:52:40 +00:00
|
|
|
PrintNoAlias = PrintMayAlias = true;
|
|
|
|
PrintPartialAlias = PrintMustAlias = true;
|
2004-07-17 06:28:49 +00:00
|
|
|
PrintNoModRef = PrintMod = PrintRef = PrintModRef = true;
|
|
|
|
}
|
2005-04-21 21:13:18 +00:00
|
|
|
return false;
|
2004-03-12 06:15:08 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
bool runOnFunction(Function &F) override;
|
|
|
|
bool doFinalization(Module &M) override;
|
2003-02-06 21:29:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-07-07 14:27:09 +00:00
|
|
|
char AAEval::ID = 0;
|
2010-10-12 19:48:12 +00:00
|
|
|
INITIALIZE_PASS_BEGIN(AAEval, "aa-eval",
|
|
|
|
"Exhaustive Alias Analysis Precision Evaluator", false, true)
|
|
|
|
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
|
|
|
|
INITIALIZE_PASS_END(AAEval, "aa-eval",
|
2010-10-07 22:25:06 +00:00
|
|
|
"Exhaustive Alias Analysis Precision Evaluator", false, true)
|
2008-05-13 00:00:25 +00:00
|
|
|
|
2010-07-07 14:27:09 +00:00
|
|
|
FunctionPass *llvm::createAAEvalPass() { return new AAEval(); }
|
2005-01-08 22:01:16 +00:00
|
|
|
|
2009-08-23 05:17:37 +00:00
|
|
|
static void PrintResults(const char *Msg, bool P, const Value *V1,
|
|
|
|
const Value *V2, const Module *M) {
|
2003-02-09 20:40:13 +00:00
|
|
|
if (P) {
|
2009-08-23 05:17:37 +00:00
|
|
|
std::string o1, o2;
|
|
|
|
{
|
|
|
|
raw_string_ostream os1(o1), os2(o2);
|
2014-01-09 02:29:41 +00:00
|
|
|
V1->printAsOperand(os1, true, M);
|
|
|
|
V2->printAsOperand(os2, true, M);
|
2009-08-23 05:17:37 +00:00
|
|
|
}
|
|
|
|
|
2008-02-28 08:38:45 +00:00
|
|
|
if (o2 < o1)
|
2009-07-25 00:23:56 +00:00
|
|
|
std::swap(o1, o2);
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " " << Msg << ":\t"
|
2009-07-25 00:23:56 +00:00
|
|
|
<< o1 << ", "
|
|
|
|
<< o2 << "\n";
|
2003-02-09 20:40:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-21 21:13:18 +00:00
|
|
|
static inline void
|
2004-07-17 06:43:20 +00:00
|
|
|
PrintModRefResults(const char *Msg, bool P, Instruction *I, Value *Ptr,
|
|
|
|
Module *M) {
|
|
|
|
if (P) {
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " " << Msg << ": Ptr: ";
|
2014-01-09 02:29:41 +00:00
|
|
|
Ptr->printAsOperand(errs(), true, M);
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << "\t<->" << *I << '\n';
|
2004-07-17 06:43:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 22:56:29 +00:00
|
|
|
static inline void
|
|
|
|
PrintModRefResults(const char *Msg, bool P, CallSite CSA, CallSite CSB,
|
|
|
|
Module *M) {
|
|
|
|
if (P) {
|
|
|
|
errs() << " " << Msg << ": " << *CSA.getInstruction()
|
|
|
|
<< " <-> " << *CSB.getInstruction() << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 22:34:41 +00:00
|
|
|
static inline void
|
|
|
|
PrintLoadStoreResults(const char *Msg, bool P, const Value *V1,
|
|
|
|
const Value *V2, const Module *M) {
|
|
|
|
if (P) {
|
|
|
|
errs() << " " << Msg << ": " << *V1
|
|
|
|
<< " <-> " << *V2 << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-08 16:46:24 +00:00
|
|
|
static inline bool isInterestingPointer(Value *V) {
|
|
|
|
return V->getType()->isPointerTy()
|
|
|
|
&& !isa<ConstantPointerNull>(V);
|
|
|
|
}
|
|
|
|
|
2010-07-07 14:27:09 +00:00
|
|
|
bool AAEval::runOnFunction(Function &F) {
|
|
|
|
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
|
|
|
|
|
|
|
SetVector<Value *> Pointers;
|
|
|
|
SetVector<CallSite> CallSites;
|
2013-03-22 22:34:41 +00:00
|
|
|
SetVector<Value *> Loads;
|
|
|
|
SetVector<Value *> Stores;
|
2010-07-07 14:27:09 +00:00
|
|
|
|
2005-03-15 04:54:21 +00:00
|
|
|
for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
|
2010-04-08 16:46:24 +00:00
|
|
|
if (I->getType()->isPointerTy()) // Add all pointer arguments.
|
2003-06-29 00:07:11 +00:00
|
|
|
Pointers.insert(I);
|
2003-02-06 21:29:49 +00:00
|
|
|
|
2003-06-29 00:07:11 +00:00
|
|
|
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
|
2010-04-08 16:46:24 +00:00
|
|
|
if (I->getType()->isPointerTy()) // Add all pointer instructions.
|
2004-04-27 15:13:33 +00:00
|
|
|
Pointers.insert(&*I);
|
2013-03-22 22:34:41 +00:00
|
|
|
if (EvalTBAA && isa<LoadInst>(&*I))
|
|
|
|
Loads.insert(&*I);
|
|
|
|
if (EvalTBAA && isa<StoreInst>(&*I))
|
|
|
|
Stores.insert(&*I);
|
2005-03-17 20:25:04 +00:00
|
|
|
Instruction &Inst = *I;
|
2010-07-28 15:31:37 +00:00
|
|
|
if (CallSite CS = cast<Value>(&Inst)) {
|
2010-04-08 16:46:24 +00:00
|
|
|
Value *Callee = CS.getCalledValue();
|
|
|
|
// Skip actual functions for direct function calls.
|
|
|
|
if (!isa<Function>(Callee) && isInterestingPointer(Callee))
|
|
|
|
Pointers.insert(Callee);
|
|
|
|
// Consider formals.
|
|
|
|
for (CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end();
|
|
|
|
AI != AE; ++AI)
|
|
|
|
if (isInterestingPointer(*AI))
|
|
|
|
Pointers.insert(*AI);
|
2010-07-28 15:31:37 +00:00
|
|
|
CallSites.insert(CS);
|
2010-04-08 16:46:24 +00:00
|
|
|
} else {
|
|
|
|
// Consider all operands.
|
|
|
|
for (Instruction::op_iterator OI = Inst.op_begin(), OE = Inst.op_end();
|
|
|
|
OI != OE; ++OI)
|
|
|
|
if (isInterestingPointer(*OI))
|
|
|
|
Pointers.insert(*OI);
|
|
|
|
}
|
2004-03-12 06:15:08 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 19:52:40 +00:00
|
|
|
if (PrintNoAlias || PrintMayAlias || PrintPartialAlias || PrintMustAlias ||
|
2010-07-07 14:27:09 +00:00
|
|
|
PrintNoModRef || PrintMod || PrintRef || PrintModRef)
|
|
|
|
errs() << "Function: " << F.getName() << ": " << Pointers.size()
|
|
|
|
<< " pointers, " << CallSites.size() << " call sites\n";
|
2003-02-09 20:40:13 +00:00
|
|
|
|
2003-02-06 21:29:49 +00:00
|
|
|
// iterate over the worklist, and run the full (n^2)/2 disambiguations
|
2009-08-26 14:32:17 +00:00
|
|
|
for (SetVector<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end();
|
2004-11-26 21:05:39 +00:00
|
|
|
I1 != E; ++I1) {
|
2010-10-19 22:54:46 +00:00
|
|
|
uint64_t I1Size = AliasAnalysis::UnknownSize;
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *I1ElTy = cast<PointerType>((*I1)->getType())->getElementType();
|
2010-07-07 14:27:09 +00:00
|
|
|
if (I1ElTy->isSized()) I1Size = AA.getTypeStoreSize(I1ElTy);
|
2004-11-26 21:05:39 +00:00
|
|
|
|
2009-08-26 14:32:17 +00:00
|
|
|
for (SetVector<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2) {
|
2010-10-19 22:54:46 +00:00
|
|
|
uint64_t I2Size = AliasAnalysis::UnknownSize;
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *I2ElTy =cast<PointerType>((*I2)->getType())->getElementType();
|
2010-07-07 14:27:09 +00:00
|
|
|
if (I2ElTy->isSized()) I2Size = AA.getTypeStoreSize(I2ElTy);
|
2004-11-26 21:05:39 +00:00
|
|
|
|
2010-07-07 14:27:09 +00:00
|
|
|
switch (AA.alias(*I1, I1Size, *I2, I2Size)) {
|
2003-02-09 20:40:13 +00:00
|
|
|
case AliasAnalysis::NoAlias:
|
2010-07-07 14:27:09 +00:00
|
|
|
PrintResults("NoAlias", PrintNoAlias, *I1, *I2, F.getParent());
|
2004-03-12 06:15:08 +00:00
|
|
|
++NoAlias; break;
|
2003-02-09 20:40:13 +00:00
|
|
|
case AliasAnalysis::MayAlias:
|
2010-07-07 14:27:09 +00:00
|
|
|
PrintResults("MayAlias", PrintMayAlias, *I1, *I2, F.getParent());
|
2004-03-12 06:15:08 +00:00
|
|
|
++MayAlias; break;
|
2010-12-10 19:52:40 +00:00
|
|
|
case AliasAnalysis::PartialAlias:
|
|
|
|
PrintResults("PartialAlias", PrintPartialAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
|
|
|
++PartialAlias; break;
|
2003-02-09 20:40:13 +00:00
|
|
|
case AliasAnalysis::MustAlias:
|
2010-07-07 14:27:09 +00:00
|
|
|
PrintResults("MustAlias", PrintMustAlias, *I1, *I2, F.getParent());
|
2004-03-12 06:15:08 +00:00
|
|
|
++MustAlias; break;
|
2003-02-06 21:29:49 +00:00
|
|
|
}
|
2004-11-26 21:05:39 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-06 21:29:49 +00:00
|
|
|
|
2013-03-22 22:34:41 +00:00
|
|
|
if (EvalTBAA) {
|
|
|
|
// iterate over all pairs of load, store
|
|
|
|
for (SetVector<Value *>::iterator I1 = Loads.begin(), E = Loads.end();
|
|
|
|
I1 != E; ++I1) {
|
|
|
|
for (SetVector<Value *>::iterator I2 = Stores.begin(), E2 = Stores.end();
|
|
|
|
I2 != E2; ++I2) {
|
|
|
|
switch (AA.alias(AA.getLocation(cast<LoadInst>(*I1)),
|
|
|
|
AA.getLocation(cast<StoreInst>(*I2)))) {
|
|
|
|
case AliasAnalysis::NoAlias:
|
|
|
|
PrintLoadStoreResults("NoAlias", PrintNoAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
|
|
|
++NoAlias; break;
|
|
|
|
case AliasAnalysis::MayAlias:
|
|
|
|
PrintLoadStoreResults("MayAlias", PrintMayAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
|
|
|
++MayAlias; break;
|
|
|
|
case AliasAnalysis::PartialAlias:
|
|
|
|
PrintLoadStoreResults("PartialAlias", PrintPartialAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
|
|
|
++PartialAlias; break;
|
|
|
|
case AliasAnalysis::MustAlias:
|
|
|
|
PrintLoadStoreResults("MustAlias", PrintMustAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
|
|
|
++MustAlias; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// iterate over all pairs of store, store
|
|
|
|
for (SetVector<Value *>::iterator I1 = Stores.begin(), E = Stores.end();
|
|
|
|
I1 != E; ++I1) {
|
|
|
|
for (SetVector<Value *>::iterator I2 = Stores.begin(); I2 != I1; ++I2) {
|
|
|
|
switch (AA.alias(AA.getLocation(cast<StoreInst>(*I1)),
|
|
|
|
AA.getLocation(cast<StoreInst>(*I2)))) {
|
|
|
|
case AliasAnalysis::NoAlias:
|
|
|
|
PrintLoadStoreResults("NoAlias", PrintNoAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
|
|
|
++NoAlias; break;
|
|
|
|
case AliasAnalysis::MayAlias:
|
|
|
|
PrintLoadStoreResults("MayAlias", PrintMayAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
|
|
|
++MayAlias; break;
|
|
|
|
case AliasAnalysis::PartialAlias:
|
|
|
|
PrintLoadStoreResults("PartialAlias", PrintPartialAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
|
|
|
++PartialAlias; break;
|
|
|
|
case AliasAnalysis::MustAlias:
|
|
|
|
PrintLoadStoreResults("MustAlias", PrintMustAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
|
|
|
++MustAlias; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-12 06:15:08 +00:00
|
|
|
// Mod/ref alias analysis: compare all pairs of calls and values
|
2009-08-26 14:32:17 +00:00
|
|
|
for (SetVector<CallSite>::iterator C = CallSites.begin(),
|
2005-03-26 22:16:44 +00:00
|
|
|
Ce = CallSites.end(); C != Ce; ++C) {
|
|
|
|
Instruction *I = C->getInstruction();
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2009-08-26 14:32:17 +00:00
|
|
|
for (SetVector<Value *>::iterator V = Pointers.begin(), Ve = Pointers.end();
|
2005-03-26 22:16:44 +00:00
|
|
|
V != Ve; ++V) {
|
2010-10-19 22:54:46 +00:00
|
|
|
uint64_t Size = AliasAnalysis::UnknownSize;
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *ElTy = cast<PointerType>((*V)->getType())->getElementType();
|
2010-07-07 14:27:09 +00:00
|
|
|
if (ElTy->isSized()) Size = AA.getTypeStoreSize(ElTy);
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2010-07-07 14:27:09 +00:00
|
|
|
switch (AA.getModRefInfo(*C, *V, Size)) {
|
2004-11-26 21:05:39 +00:00
|
|
|
case AliasAnalysis::NoModRef:
|
2010-07-07 14:27:09 +00:00
|
|
|
PrintModRefResults("NoModRef", PrintNoModRef, I, *V, F.getParent());
|
2004-11-26 21:05:39 +00:00
|
|
|
++NoModRef; break;
|
|
|
|
case AliasAnalysis::Mod:
|
2010-08-04 23:37:55 +00:00
|
|
|
PrintModRefResults("Just Mod", PrintMod, I, *V, F.getParent());
|
2004-11-26 21:05:39 +00:00
|
|
|
++Mod; break;
|
|
|
|
case AliasAnalysis::Ref:
|
2010-08-04 23:37:55 +00:00
|
|
|
PrintModRefResults("Just Ref", PrintRef, I, *V, F.getParent());
|
2004-11-26 21:05:39 +00:00
|
|
|
++Ref; break;
|
|
|
|
case AliasAnalysis::ModRef:
|
2010-08-04 23:37:55 +00:00
|
|
|
PrintModRefResults("Both ModRef", PrintModRef, I, *V, F.getParent());
|
2004-11-26 21:05:39 +00:00
|
|
|
++ModRef; break;
|
2004-03-12 06:15:08 +00:00
|
|
|
}
|
2004-11-26 21:05:39 +00:00
|
|
|
}
|
2004-07-17 07:40:34 +00:00
|
|
|
}
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2010-08-04 22:56:29 +00:00
|
|
|
// Mod/ref alias analysis: compare all pairs of calls
|
|
|
|
for (SetVector<CallSite>::iterator C = CallSites.begin(),
|
|
|
|
Ce = CallSites.end(); C != Ce; ++C) {
|
|
|
|
for (SetVector<CallSite>::iterator D = CallSites.begin(); D != Ce; ++D) {
|
|
|
|
if (D == C)
|
|
|
|
continue;
|
|
|
|
switch (AA.getModRefInfo(*C, *D)) {
|
|
|
|
case AliasAnalysis::NoModRef:
|
|
|
|
PrintModRefResults("NoModRef", PrintNoModRef, *C, *D, F.getParent());
|
|
|
|
++NoModRef; break;
|
|
|
|
case AliasAnalysis::Mod:
|
2010-08-04 23:37:55 +00:00
|
|
|
PrintModRefResults("Just Mod", PrintMod, *C, *D, F.getParent());
|
2010-08-04 22:56:29 +00:00
|
|
|
++Mod; break;
|
|
|
|
case AliasAnalysis::Ref:
|
2010-08-04 23:37:55 +00:00
|
|
|
PrintModRefResults("Just Ref", PrintRef, *C, *D, F.getParent());
|
2010-08-04 22:56:29 +00:00
|
|
|
++Ref; break;
|
|
|
|
case AliasAnalysis::ModRef:
|
2010-08-04 23:37:55 +00:00
|
|
|
PrintModRefResults("Both ModRef", PrintModRef, *C, *D, F.getParent());
|
2010-08-04 22:56:29 +00:00
|
|
|
++ModRef; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-07 14:27:09 +00:00
|
|
|
return false;
|
2003-02-06 21:29:49 +00:00
|
|
|
}
|
|
|
|
|
2005-03-26 23:56:33 +00:00
|
|
|
static void PrintPercent(unsigned Num, unsigned Sum) {
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << "(" << Num*100ULL/Sum << "."
|
2009-07-25 00:23:56 +00:00
|
|
|
<< ((Num*1000ULL/Sum) % 10) << "%)\n";
|
2005-03-26 23:56:33 +00:00
|
|
|
}
|
|
|
|
|
2010-07-07 14:27:09 +00:00
|
|
|
bool AAEval::doFinalization(Module &M) {
|
2010-12-10 19:52:40 +00:00
|
|
|
unsigned AliasSum = NoAlias + MayAlias + PartialAlias + MustAlias;
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << "===== Alias Analysis Evaluator Report =====\n";
|
2004-03-12 06:15:08 +00:00
|
|
|
if (AliasSum == 0) {
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " Alias Analysis Evaluator Summary: No pointers!\n";
|
2005-04-21 21:13:18 +00:00
|
|
|
} else {
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " " << AliasSum << " Total Alias Queries Performed\n";
|
|
|
|
errs() << " " << NoAlias << " no alias responses ";
|
2005-03-26 23:56:33 +00:00
|
|
|
PrintPercent(NoAlias, AliasSum);
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " " << MayAlias << " may alias responses ";
|
2005-03-26 23:56:33 +00:00
|
|
|
PrintPercent(MayAlias, AliasSum);
|
2010-12-10 19:52:40 +00:00
|
|
|
errs() << " " << PartialAlias << " partial alias responses ";
|
|
|
|
PrintPercent(PartialAlias, AliasSum);
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " " << MustAlias << " must alias responses ";
|
2005-03-26 23:56:33 +00:00
|
|
|
PrintPercent(MustAlias, AliasSum);
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " Alias Analysis Evaluator Pointer Alias Summary: "
|
2009-07-25 00:23:56 +00:00
|
|
|
<< NoAlias*100/AliasSum << "%/" << MayAlias*100/AliasSum << "%/"
|
2010-12-10 19:52:40 +00:00
|
|
|
<< PartialAlias*100/AliasSum << "%/"
|
2009-07-25 00:23:56 +00:00
|
|
|
<< MustAlias*100/AliasSum << "%\n";
|
2004-03-12 06:15:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Display the summary for mod/ref analysis
|
|
|
|
unsigned ModRefSum = NoModRef + Mod + Ref + ModRef;
|
|
|
|
if (ModRefSum == 0) {
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " Alias Analysis Mod/Ref Evaluator Summary: no mod/ref!\n";
|
2004-03-12 06:15:08 +00:00
|
|
|
} else {
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " " << ModRefSum << " Total ModRef Queries Performed\n";
|
|
|
|
errs() << " " << NoModRef << " no mod/ref responses ";
|
2005-03-26 23:56:33 +00:00
|
|
|
PrintPercent(NoModRef, ModRefSum);
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " " << Mod << " mod responses ";
|
2005-03-26 23:56:33 +00:00
|
|
|
PrintPercent(Mod, ModRefSum);
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " " << Ref << " ref responses ";
|
2005-03-26 23:56:33 +00:00
|
|
|
PrintPercent(Ref, ModRefSum);
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " " << ModRef << " mod & ref responses ";
|
2005-03-26 23:56:33 +00:00
|
|
|
PrintPercent(ModRef, ModRefSum);
|
2009-12-23 22:49:57 +00:00
|
|
|
errs() << " Alias Analysis Evaluator Mod/Ref Summary: "
|
2009-07-25 00:23:56 +00:00
|
|
|
<< NoModRef*100/ModRefSum << "%/" << Mod*100/ModRefSum << "%/"
|
|
|
|
<< Ref*100/ModRefSum << "%/" << ModRef*100/ModRefSum << "%\n";
|
2003-02-08 23:04:50 +00:00
|
|
|
}
|
2010-07-07 14:27:09 +00:00
|
|
|
|
|
|
|
return false;
|
2003-02-06 21:29:49 +00:00
|
|
|
}
|