2006-11-14 05:21:04 +00:00
|
|
|
//===- AliasDebugger.cpp - Simple Alias Analysis Use Checker --------------===//
|
|
|
|
//
|
|
|
|
// 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.
|
2006-11-14 05:21:04 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This simple pass checks alias analysis users to ensure that if they
|
|
|
|
// create a new value, they do not query AA without informing it of the value.
|
|
|
|
// It acts as a shim over any other AA pass you want.
|
|
|
|
//
|
|
|
|
// Yes keeping track of every value in the program is expensive, but this is
|
|
|
|
// a debugging pass.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Analysis/Passes.h"
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Instructions.h"
|
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
|
|
|
#include <set>
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2009-10-25 06:33:48 +00:00
|
|
|
class AliasDebugger : public ModulePass, public AliasAnalysis {
|
2006-11-14 05:21:04 +00:00
|
|
|
|
|
|
|
//What we do is simple. Keep track of every value the AA could
|
|
|
|
//know about, and verify that queries are one of those.
|
|
|
|
//A query to a value that didn't exist when the AA was created
|
|
|
|
//means someone forgot to update the AA when creating new values
|
|
|
|
|
|
|
|
std::set<const Value*> Vals;
|
|
|
|
|
|
|
|
public:
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID; // Class identification, replacement for typeinfo
|
2010-08-06 18:33:48 +00:00
|
|
|
AliasDebugger() : ModulePass(ID) {}
|
2008-03-18 00:39:19 +00:00
|
|
|
|
2006-11-14 05:21:04 +00:00
|
|
|
bool runOnModule(Module &M) {
|
|
|
|
InitializeAliasAnalysis(this); // set up super class
|
|
|
|
|
|
|
|
for(Module::global_iterator I = M.global_begin(),
|
2010-05-28 22:31:51 +00:00
|
|
|
E = M.global_end(); I != E; ++I) {
|
2006-11-14 05:21:04 +00:00
|
|
|
Vals.insert(&*I);
|
2010-05-28 22:31:51 +00:00
|
|
|
for (User::const_op_iterator OI = I->op_begin(),
|
|
|
|
OE = I->op_end(); OI != OE; ++OI)
|
|
|
|
Vals.insert(*OI);
|
|
|
|
}
|
2006-11-14 05:21:04 +00:00
|
|
|
|
|
|
|
for(Module::iterator I = M.begin(),
|
|
|
|
E = M.end(); I != E; ++I){
|
|
|
|
Vals.insert(&*I);
|
2007-01-30 20:08:39 +00:00
|
|
|
if(!I->isDeclaration()) {
|
2006-11-14 05:21:04 +00:00
|
|
|
for (Function::arg_iterator AI = I->arg_begin(), AE = I->arg_end();
|
|
|
|
AI != AE; ++AI)
|
|
|
|
Vals.insert(&*AI);
|
|
|
|
for (Function::const_iterator FI = I->begin(), FE = I->end();
|
|
|
|
FI != FE; ++FI)
|
|
|
|
for (BasicBlock::const_iterator BI = FI->begin(), BE = FI->end();
|
2010-05-28 22:31:51 +00:00
|
|
|
BI != BE; ++BI) {
|
2006-11-14 05:21:04 +00:00
|
|
|
Vals.insert(&*BI);
|
2010-05-28 22:31:51 +00:00
|
|
|
for (User::const_op_iterator OI = BI->op_begin(),
|
|
|
|
OE = BI->op_end(); OI != OE; ++OI)
|
|
|
|
Vals.insert(*OI);
|
|
|
|
}
|
2006-11-14 05:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AliasAnalysis::getAnalysisUsage(AU);
|
|
|
|
AU.setPreservesAll(); // Does not transform code
|
|
|
|
}
|
|
|
|
|
2010-01-20 20:09:02 +00: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 18:33:48 +00:00
|
|
|
virtual void *getAdjustedAnalysisPointer(AnalysisID PI) {
|
|
|
|
if (PI == &AliasAnalysis::ID)
|
2010-01-20 20:09:02 +00:00
|
|
|
return (AliasAnalysis*)this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2006-11-14 05:21:04 +00:00
|
|
|
//------------------------------------------------
|
|
|
|
// Implement the AliasAnalysis API
|
|
|
|
//
|
2010-09-14 21:25:10 +00:00
|
|
|
AliasResult alias(const Location &LocA, const Location &LocB) {
|
|
|
|
assert(Vals.find(LocA.Ptr) != Vals.end() &&
|
|
|
|
"Never seen value in AA before");
|
|
|
|
assert(Vals.find(LocB.Ptr) != Vals.end() &&
|
|
|
|
"Never seen value in AA before");
|
|
|
|
return AliasAnalysis::alias(LocA, LocB);
|
2006-11-14 05:21:04 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 21:48:53 +00:00
|
|
|
ModRefResult getModRefInfo(ImmutableCallSite CS,
|
2010-09-14 21:25:10 +00:00
|
|
|
const Location &Loc) {
|
|
|
|
assert(Vals.find(Loc.Ptr) != Vals.end() && "Never seen value in AA before");
|
|
|
|
return AliasAnalysis::getModRefInfo(CS, Loc);
|
2006-11-14 05:21:04 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 21:48:53 +00:00
|
|
|
ModRefResult getModRefInfo(ImmutableCallSite CS1,
|
|
|
|
ImmutableCallSite CS2) {
|
2006-11-14 05:21:04 +00:00
|
|
|
return AliasAnalysis::getModRefInfo(CS1,CS2);
|
|
|
|
}
|
|
|
|
|
2010-09-14 21:25:10 +00:00
|
|
|
bool pointsToConstantMemory(const Location &Loc) {
|
|
|
|
assert(Vals.find(Loc.Ptr) != Vals.end() && "Never seen value in AA before");
|
|
|
|
return AliasAnalysis::pointsToConstantMemory(Loc);
|
2006-11-14 05:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void deleteValue(Value *V) {
|
|
|
|
assert(Vals.find(V) != Vals.end() && "Never seen value in AA before");
|
|
|
|
AliasAnalysis::deleteValue(V);
|
|
|
|
}
|
|
|
|
virtual void copyValue(Value *From, Value *To) {
|
|
|
|
Vals.insert(To);
|
|
|
|
AliasAnalysis::copyValue(From, To);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
char AliasDebugger::ID = 0;
|
2010-07-21 23:07:00 +00:00
|
|
|
INITIALIZE_AG_PASS(AliasDebugger, AliasAnalysis, "debug-aa",
|
|
|
|
"AA use debugger", false, true, false);
|
2008-05-13 00:00:25 +00:00
|
|
|
|
2006-11-14 05:21:04 +00:00
|
|
|
Pass *llvm::createAliasDebugger() { return new AliasDebugger(); }
|
|
|
|
|