2003-02-07 05:29:49 +08:00
|
|
|
//===- AliasAnalysisEvaluator.cpp - Alias Analysis Accuracy Evaluator -----===//
|
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-07 05:29:49 +08: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-04 00:50:05 +08:00
|
|
|
#include "llvm/Analysis/Passes.h"
|
|
|
|
#include "llvm/ADT/SetVector.h"
|
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
2014-03-04 18:30:26 +08:00
|
|
|
#include "llvm/IR/InstIterator.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2004-03-12 14:15:08 +08:00
|
|
|
#include "llvm/Pass.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-12-24 03:21:19 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-25 08:23:56 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2003-12-10 23:33:59 +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> PrintAll("print-all-alias-modref-info", cl::ReallyHidden);
|
2004-07-17 14:28:49 +08:00
|
|
|
|
2008-05-13 08:00:25 +08:00
|
|
|
static cl::opt<bool> PrintNoAlias("print-no-aliases", cl::ReallyHidden);
|
|
|
|
static cl::opt<bool> PrintMayAlias("print-may-aliases", cl::ReallyHidden);
|
2010-12-11 03:52:40 +08:00
|
|
|
static cl::opt<bool> PrintPartialAlias("print-partial-aliases", cl::ReallyHidden);
|
2008-05-13 08:00:25 +08:00
|
|
|
static cl::opt<bool> PrintMustAlias("print-must-aliases", cl::ReallyHidden);
|
2004-03-12 14:15:08 +08:00
|
|
|
|
2008-05-13 08:00:25 +08: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-10 04:40:13 +08:00
|
|
|
|
2014-07-24 20:16:19 +08:00
|
|
|
static cl::opt<bool> EvalAAMD("evaluate-aa-metadata", cl::ReallyHidden);
|
2013-03-23 06:34:41 +08:00
|
|
|
|
2008-05-13 08:00:25 +08:00
|
|
|
namespace {
|
2010-07-07 22:27:09 +08:00
|
|
|
class AAEval : public FunctionPass {
|
2010-12-11 03:52:40 +08:00
|
|
|
unsigned NoAlias, MayAlias, PartialAlias, MustAlias;
|
2004-03-12 14:15:08 +08:00
|
|
|
unsigned NoModRef, Mod, Ref, ModRef;
|
2003-02-07 05:29:49 +08:00
|
|
|
|
2010-07-07 22:27:09 +08:00
|
|
|
public:
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2010-10-20 01:21:58 +08:00
|
|
|
AAEval() : FunctionPass(ID) {
|
|
|
|
initializeAAEvalPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2007-05-02 05:15:47 +08:00
|
|
|
|
2014-03-05 15:30:04 +08:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2003-02-07 05:29:49 +08:00
|
|
|
AU.addRequired<AliasAnalysis>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
2005-04-22 05:13:18 +08:00
|
|
|
|
2014-03-05 15:30:04 +08:00
|
|
|
bool doInitialization(Module &M) override {
|
2010-12-11 03:52:40 +08:00
|
|
|
NoAlias = MayAlias = PartialAlias = MustAlias = 0;
|
2004-03-12 14:15:08 +08:00
|
|
|
NoModRef = Mod = Ref = ModRef = 0;
|
2004-07-17 14:28:49 +08:00
|
|
|
|
|
|
|
if (PrintAll) {
|
2010-12-11 03:52:40 +08:00
|
|
|
PrintNoAlias = PrintMayAlias = true;
|
|
|
|
PrintPartialAlias = PrintMustAlias = true;
|
2004-07-17 14:28:49 +08:00
|
|
|
PrintNoModRef = PrintMod = PrintRef = PrintModRef = true;
|
|
|
|
}
|
2005-04-22 05:13:18 +08:00
|
|
|
return false;
|
2004-03-12 14:15:08 +08:00
|
|
|
}
|
|
|
|
|
2014-03-05 15:30:04 +08:00
|
|
|
bool runOnFunction(Function &F) override;
|
|
|
|
bool doFinalization(Module &M) override;
|
2003-02-07 05:29:49 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-07-07 22:27:09 +08:00
|
|
|
char AAEval::ID = 0;
|
2010-10-13 03:48:12 +08: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-08 06:25:06 +08:00
|
|
|
"Exhaustive Alias Analysis Precision Evaluator", false, true)
|
2008-05-13 08:00:25 +08:00
|
|
|
|
2010-07-07 22:27:09 +08:00
|
|
|
FunctionPass *llvm::createAAEvalPass() { return new AAEval(); }
|
2005-01-09 06:01:16 +08:00
|
|
|
|
2009-08-23 13:17:37 +08:00
|
|
|
static void PrintResults(const char *Msg, bool P, const Value *V1,
|
|
|
|
const Value *V2, const Module *M) {
|
2003-02-10 04:40:13 +08:00
|
|
|
if (P) {
|
2009-08-23 13:17:37 +08:00
|
|
|
std::string o1, o2;
|
|
|
|
{
|
|
|
|
raw_string_ostream os1(o1), os2(o2);
|
2014-01-09 10:29:41 +08:00
|
|
|
V1->printAsOperand(os1, true, M);
|
|
|
|
V2->printAsOperand(os2, true, M);
|
2009-08-23 13:17:37 +08:00
|
|
|
}
|
|
|
|
|
2008-02-28 16:38:45 +08:00
|
|
|
if (o2 < o1)
|
2009-07-25 08:23:56 +08:00
|
|
|
std::swap(o1, o2);
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " " << Msg << ":\t"
|
2009-07-25 08:23:56 +08:00
|
|
|
<< o1 << ", "
|
|
|
|
<< o2 << "\n";
|
2003-02-10 04:40:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-22 05:13:18 +08:00
|
|
|
static inline void
|
2004-07-17 14:43:20 +08:00
|
|
|
PrintModRefResults(const char *Msg, bool P, Instruction *I, Value *Ptr,
|
|
|
|
Module *M) {
|
|
|
|
if (P) {
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " " << Msg << ": Ptr: ";
|
2014-01-09 10:29:41 +08:00
|
|
|
Ptr->printAsOperand(errs(), true, M);
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << "\t<->" << *I << '\n';
|
2004-07-17 14:43:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-05 06:56:29 +08: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-23 06:34:41 +08: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-09 00:46:24 +08:00
|
|
|
static inline bool isInterestingPointer(Value *V) {
|
|
|
|
return V->getType()->isPointerTy()
|
|
|
|
&& !isa<ConstantPointerNull>(V);
|
|
|
|
}
|
|
|
|
|
2010-07-07 22:27:09 +08:00
|
|
|
bool AAEval::runOnFunction(Function &F) {
|
|
|
|
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
|
|
|
|
|
|
|
SetVector<Value *> Pointers;
|
|
|
|
SetVector<CallSite> CallSites;
|
2013-03-23 06:34:41 +08:00
|
|
|
SetVector<Value *> Loads;
|
|
|
|
SetVector<Value *> Stores;
|
2010-07-07 22:27:09 +08:00
|
|
|
|
2005-03-15 12:54:21 +08:00
|
|
|
for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
|
2010-04-09 00:46:24 +08:00
|
|
|
if (I->getType()->isPointerTy()) // Add all pointer arguments.
|
2003-06-29 08:07:11 +08:00
|
|
|
Pointers.insert(I);
|
2003-02-07 05:29:49 +08:00
|
|
|
|
2003-06-29 08:07:11 +08:00
|
|
|
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
|
2010-04-09 00:46:24 +08:00
|
|
|
if (I->getType()->isPointerTy()) // Add all pointer instructions.
|
2004-04-27 23:13:33 +08:00
|
|
|
Pointers.insert(&*I);
|
2014-07-24 20:16:19 +08:00
|
|
|
if (EvalAAMD && isa<LoadInst>(&*I))
|
2013-03-23 06:34:41 +08:00
|
|
|
Loads.insert(&*I);
|
2014-07-24 20:16:19 +08:00
|
|
|
if (EvalAAMD && isa<StoreInst>(&*I))
|
2013-03-23 06:34:41 +08:00
|
|
|
Stores.insert(&*I);
|
2005-03-18 04:25:04 +08:00
|
|
|
Instruction &Inst = *I;
|
2010-07-28 23:31:37 +08:00
|
|
|
if (CallSite CS = cast<Value>(&Inst)) {
|
2010-04-09 00:46:24 +08: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 23:31:37 +08:00
|
|
|
CallSites.insert(CS);
|
2010-04-09 00:46:24 +08: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 14:15:08 +08:00
|
|
|
}
|
|
|
|
|
2010-12-11 03:52:40 +08:00
|
|
|
if (PrintNoAlias || PrintMayAlias || PrintPartialAlias || PrintMustAlias ||
|
2010-07-07 22:27:09 +08:00
|
|
|
PrintNoModRef || PrintMod || PrintRef || PrintModRef)
|
|
|
|
errs() << "Function: " << F.getName() << ": " << Pointers.size()
|
|
|
|
<< " pointers, " << CallSites.size() << " call sites\n";
|
2003-02-10 04:40:13 +08:00
|
|
|
|
2003-02-07 05:29:49 +08:00
|
|
|
// iterate over the worklist, and run the full (n^2)/2 disambiguations
|
2009-08-26 22:32:17 +08:00
|
|
|
for (SetVector<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end();
|
2004-11-27 05:05:39 +08:00
|
|
|
I1 != E; ++I1) {
|
2010-10-20 06:54:46 +08:00
|
|
|
uint64_t I1Size = AliasAnalysis::UnknownSize;
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *I1ElTy = cast<PointerType>((*I1)->getType())->getElementType();
|
2010-07-07 22:27:09 +08:00
|
|
|
if (I1ElTy->isSized()) I1Size = AA.getTypeStoreSize(I1ElTy);
|
2004-11-27 05:05:39 +08:00
|
|
|
|
2009-08-26 22:32:17 +08:00
|
|
|
for (SetVector<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2) {
|
2010-10-20 06:54:46 +08:00
|
|
|
uint64_t I2Size = AliasAnalysis::UnknownSize;
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *I2ElTy =cast<PointerType>((*I2)->getType())->getElementType();
|
2010-07-07 22:27:09 +08:00
|
|
|
if (I2ElTy->isSized()) I2Size = AA.getTypeStoreSize(I2ElTy);
|
2004-11-27 05:05:39 +08:00
|
|
|
|
2010-07-07 22:27:09 +08:00
|
|
|
switch (AA.alias(*I1, I1Size, *I2, I2Size)) {
|
2003-02-10 04:40:13 +08:00
|
|
|
case AliasAnalysis::NoAlias:
|
2010-07-07 22:27:09 +08:00
|
|
|
PrintResults("NoAlias", PrintNoAlias, *I1, *I2, F.getParent());
|
2004-03-12 14:15:08 +08:00
|
|
|
++NoAlias; break;
|
2003-02-10 04:40:13 +08:00
|
|
|
case AliasAnalysis::MayAlias:
|
2010-07-07 22:27:09 +08:00
|
|
|
PrintResults("MayAlias", PrintMayAlias, *I1, *I2, F.getParent());
|
2004-03-12 14:15:08 +08:00
|
|
|
++MayAlias; break;
|
2010-12-11 03:52:40 +08:00
|
|
|
case AliasAnalysis::PartialAlias:
|
|
|
|
PrintResults("PartialAlias", PrintPartialAlias, *I1, *I2,
|
|
|
|
F.getParent());
|
|
|
|
++PartialAlias; break;
|
2003-02-10 04:40:13 +08:00
|
|
|
case AliasAnalysis::MustAlias:
|
2010-07-07 22:27:09 +08:00
|
|
|
PrintResults("MustAlias", PrintMustAlias, *I1, *I2, F.getParent());
|
2004-03-12 14:15:08 +08:00
|
|
|
++MustAlias; break;
|
2003-02-07 05:29:49 +08:00
|
|
|
}
|
2004-11-27 05:05:39 +08:00
|
|
|
}
|
|
|
|
}
|
2003-02-07 05:29:49 +08:00
|
|
|
|
2014-07-24 20:16:19 +08:00
|
|
|
if (EvalAAMD) {
|
2013-03-23 06:34:41 +08:00
|
|
|
// 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 14:15:08 +08:00
|
|
|
// Mod/ref alias analysis: compare all pairs of calls and values
|
2009-08-26 22:32:17 +08:00
|
|
|
for (SetVector<CallSite>::iterator C = CallSites.begin(),
|
2005-03-27 06:16:44 +08:00
|
|
|
Ce = CallSites.end(); C != Ce; ++C) {
|
|
|
|
Instruction *I = C->getInstruction();
|
2005-04-22 05:13:18 +08:00
|
|
|
|
2009-08-26 22:32:17 +08:00
|
|
|
for (SetVector<Value *>::iterator V = Pointers.begin(), Ve = Pointers.end();
|
2005-03-27 06:16:44 +08:00
|
|
|
V != Ve; ++V) {
|
2010-10-20 06:54:46 +08:00
|
|
|
uint64_t Size = AliasAnalysis::UnknownSize;
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *ElTy = cast<PointerType>((*V)->getType())->getElementType();
|
2010-07-07 22:27:09 +08:00
|
|
|
if (ElTy->isSized()) Size = AA.getTypeStoreSize(ElTy);
|
2005-04-22 05:13:18 +08:00
|
|
|
|
2010-07-07 22:27:09 +08:00
|
|
|
switch (AA.getModRefInfo(*C, *V, Size)) {
|
2004-11-27 05:05:39 +08:00
|
|
|
case AliasAnalysis::NoModRef:
|
2010-07-07 22:27:09 +08:00
|
|
|
PrintModRefResults("NoModRef", PrintNoModRef, I, *V, F.getParent());
|
2004-11-27 05:05:39 +08:00
|
|
|
++NoModRef; break;
|
|
|
|
case AliasAnalysis::Mod:
|
2010-08-05 07:37:55 +08:00
|
|
|
PrintModRefResults("Just Mod", PrintMod, I, *V, F.getParent());
|
2004-11-27 05:05:39 +08:00
|
|
|
++Mod; break;
|
|
|
|
case AliasAnalysis::Ref:
|
2010-08-05 07:37:55 +08:00
|
|
|
PrintModRefResults("Just Ref", PrintRef, I, *V, F.getParent());
|
2004-11-27 05:05:39 +08:00
|
|
|
++Ref; break;
|
|
|
|
case AliasAnalysis::ModRef:
|
2010-08-05 07:37:55 +08:00
|
|
|
PrintModRefResults("Both ModRef", PrintModRef, I, *V, F.getParent());
|
2004-11-27 05:05:39 +08:00
|
|
|
++ModRef; break;
|
2004-03-12 14:15:08 +08:00
|
|
|
}
|
2004-11-27 05:05:39 +08:00
|
|
|
}
|
2004-07-17 15:40:34 +08:00
|
|
|
}
|
2005-04-22 05:13:18 +08:00
|
|
|
|
2010-08-05 06:56:29 +08: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-05 07:37:55 +08:00
|
|
|
PrintModRefResults("Just Mod", PrintMod, *C, *D, F.getParent());
|
2010-08-05 06:56:29 +08:00
|
|
|
++Mod; break;
|
|
|
|
case AliasAnalysis::Ref:
|
2010-08-05 07:37:55 +08:00
|
|
|
PrintModRefResults("Just Ref", PrintRef, *C, *D, F.getParent());
|
2010-08-05 06:56:29 +08:00
|
|
|
++Ref; break;
|
|
|
|
case AliasAnalysis::ModRef:
|
2010-08-05 07:37:55 +08:00
|
|
|
PrintModRefResults("Both ModRef", PrintModRef, *C, *D, F.getParent());
|
2010-08-05 06:56:29 +08:00
|
|
|
++ModRef; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-07 22:27:09 +08:00
|
|
|
return false;
|
2003-02-07 05:29:49 +08:00
|
|
|
}
|
|
|
|
|
2005-03-27 07:56:33 +08:00
|
|
|
static void PrintPercent(unsigned Num, unsigned Sum) {
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << "(" << Num*100ULL/Sum << "."
|
2009-07-25 08:23:56 +08:00
|
|
|
<< ((Num*1000ULL/Sum) % 10) << "%)\n";
|
2005-03-27 07:56:33 +08:00
|
|
|
}
|
|
|
|
|
2010-07-07 22:27:09 +08:00
|
|
|
bool AAEval::doFinalization(Module &M) {
|
2010-12-11 03:52:40 +08:00
|
|
|
unsigned AliasSum = NoAlias + MayAlias + PartialAlias + MustAlias;
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << "===== Alias Analysis Evaluator Report =====\n";
|
2004-03-12 14:15:08 +08:00
|
|
|
if (AliasSum == 0) {
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " Alias Analysis Evaluator Summary: No pointers!\n";
|
2005-04-22 05:13:18 +08:00
|
|
|
} else {
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " " << AliasSum << " Total Alias Queries Performed\n";
|
|
|
|
errs() << " " << NoAlias << " no alias responses ";
|
2005-03-27 07:56:33 +08:00
|
|
|
PrintPercent(NoAlias, AliasSum);
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " " << MayAlias << " may alias responses ";
|
2005-03-27 07:56:33 +08:00
|
|
|
PrintPercent(MayAlias, AliasSum);
|
2010-12-11 03:52:40 +08:00
|
|
|
errs() << " " << PartialAlias << " partial alias responses ";
|
|
|
|
PrintPercent(PartialAlias, AliasSum);
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " " << MustAlias << " must alias responses ";
|
2005-03-27 07:56:33 +08:00
|
|
|
PrintPercent(MustAlias, AliasSum);
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " Alias Analysis Evaluator Pointer Alias Summary: "
|
2009-07-25 08:23:56 +08:00
|
|
|
<< NoAlias*100/AliasSum << "%/" << MayAlias*100/AliasSum << "%/"
|
2010-12-11 03:52:40 +08:00
|
|
|
<< PartialAlias*100/AliasSum << "%/"
|
2009-07-25 08:23:56 +08:00
|
|
|
<< MustAlias*100/AliasSum << "%\n";
|
2004-03-12 14:15:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Display the summary for mod/ref analysis
|
|
|
|
unsigned ModRefSum = NoModRef + Mod + Ref + ModRef;
|
|
|
|
if (ModRefSum == 0) {
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " Alias Analysis Mod/Ref Evaluator Summary: no mod/ref!\n";
|
2004-03-12 14:15:08 +08:00
|
|
|
} else {
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " " << ModRefSum << " Total ModRef Queries Performed\n";
|
|
|
|
errs() << " " << NoModRef << " no mod/ref responses ";
|
2005-03-27 07:56:33 +08:00
|
|
|
PrintPercent(NoModRef, ModRefSum);
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " " << Mod << " mod responses ";
|
2005-03-27 07:56:33 +08:00
|
|
|
PrintPercent(Mod, ModRefSum);
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " " << Ref << " ref responses ";
|
2005-03-27 07:56:33 +08:00
|
|
|
PrintPercent(Ref, ModRefSum);
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " " << ModRef << " mod & ref responses ";
|
2005-03-27 07:56:33 +08:00
|
|
|
PrintPercent(ModRef, ModRefSum);
|
2009-12-24 06:49:57 +08:00
|
|
|
errs() << " Alias Analysis Evaluator Mod/Ref Summary: "
|
2009-07-25 08:23:56 +08:00
|
|
|
<< NoModRef*100/ModRefSum << "%/" << Mod*100/ModRefSum << "%/"
|
|
|
|
<< Ref*100/ModRefSum << "%/" << ModRef*100/ModRefSum << "%\n";
|
2003-02-09 07:04:50 +08:00
|
|
|
}
|
2010-07-07 22:27:09 +08:00
|
|
|
|
|
|
|
return false;
|
2003-02-07 05:29:49 +08:00
|
|
|
}
|