mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
Simple N^2 alias anlysis accuracy checker
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5498 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b71310982a
commit
9798ca55e1
74
lib/Analysis/AliasAnalysisEvaluator.cpp
Normal file
74
lib/Analysis/AliasAnalysisEvaluator.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
//===- AliasAnalysisEvaluator.cpp - Alias Analysis Accuracy Evaluator -----===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Analysis/AliasAnalysis.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Function.h"
|
||||
#include "llvm/Support/InstIterator.h"
|
||||
#include "llvm/Type.h"
|
||||
|
||||
namespace {
|
||||
class AAEval : public FunctionPass {
|
||||
unsigned No, May, Must;
|
||||
|
||||
public:
|
||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.addRequired<AliasAnalysis>();
|
||||
AU.setPreservesAll();
|
||||
}
|
||||
|
||||
bool doInitialization(Module &M) { No = May = Must = 0; return false; }
|
||||
bool runOnFunction(Function &F);
|
||||
bool doFinalization(Module &M);
|
||||
};
|
||||
|
||||
RegisterOpt<AAEval>
|
||||
X("aa-eval", "Exhaustive Alias Analysis Precision Evaluator");
|
||||
}
|
||||
|
||||
bool AAEval::runOnFunction(Function &F) {
|
||||
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
||||
|
||||
std::vector<Value *> Pointers;
|
||||
|
||||
for (Function::aiterator I = F.abegin(), E = F.aend(); I != E; ++I)
|
||||
if (isa<PointerType>(I->getType())) // Add all pointer arguments
|
||||
Pointers.push_back(I);
|
||||
|
||||
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
|
||||
if (isa<PointerType>((*I)->getType())) // Add all pointer instructions
|
||||
Pointers.push_back(*I);
|
||||
|
||||
// iterate over the worklist, and run the full (n^2)/2 disambiguations
|
||||
for (std::vector<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end();
|
||||
I1 != E; ++I1)
|
||||
for (std::vector<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2)
|
||||
switch (AA.alias(*I1, *I2)) {
|
||||
case AliasAnalysis::NoAlias: ++No; break;
|
||||
case AliasAnalysis::MayAlias: ++May; break;
|
||||
case AliasAnalysis::MustAlias: ++Must; break;
|
||||
default:
|
||||
std::cerr << "Unknown alias query result!\n";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AAEval::doFinalization(Module &M) {
|
||||
unsigned Sum = No+May+Must;
|
||||
std::cerr << "===== Alias Analysis Evaluator Report =====\n";
|
||||
std::cerr << " " << Sum << " Total Alias Queries Performed\n";
|
||||
std::cerr << " " << No << " no alias responses (" << No*100/Sum << "%)\n";
|
||||
std::cerr << " " << May << " may alias responses (" << May*100/Sum << "%)\n";
|
||||
std::cerr << " " << Must << " must alias responses (" <<Must*100/Sum<<"%)\n";
|
||||
return false;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user