LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

AliasDebugger.cpp

Go to the documentation of this file.
00001 //===- AliasDebugger.cpp - Simple Alias Analysis Use Checker --------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This simple pass checks alias analysis users to ensure that if they
00011 // create a new value, they do not query AA without informing it of the value.
00012 // It acts as a shim over any other AA pass you want.
00013 //
00014 // Yes keeping track of every value in the program is expensive, but this is 
00015 // a debugging pass.
00016 //
00017 //===----------------------------------------------------------------------===//
00018 
00019 #include "llvm/Analysis/Passes.h"
00020 #include "llvm/Module.h"
00021 #include "llvm/Pass.h"
00022 #include "llvm/Instructions.h"
00023 #include "llvm/Constants.h"
00024 #include "llvm/DerivedTypes.h"
00025 #include "llvm/Analysis/AliasAnalysis.h"
00026 #include "llvm/Support/Compiler.h"
00027 #include <set>
00028 using namespace llvm;
00029 
00030 namespace {
00031   
00032   class VISIBILITY_HIDDEN AliasDebugger 
00033       : public ModulePass, public AliasAnalysis {
00034 
00035     //What we do is simple.  Keep track of every value the AA could
00036     //know about, and verify that queries are one of those.
00037     //A query to a value that didn't exist when the AA was created
00038     //means someone forgot to update the AA when creating new values
00039 
00040     std::set<const Value*> Vals;
00041     
00042   public:
00043     static char ID; // Class identification, replacement for typeinfo
00044     AliasDebugger() : ModulePass((intptr_t)&ID) {}
00045 
00046     bool runOnModule(Module &M) {
00047       InitializeAliasAnalysis(this);                 // set up super class
00048 
00049       for(Module::global_iterator I = M.global_begin(),
00050             E = M.global_end(); I != E; ++I)
00051         Vals.insert(&*I);
00052 
00053       for(Module::iterator I = M.begin(),
00054             E = M.end(); I != E; ++I){
00055         Vals.insert(&*I);
00056         if(!I->isDeclaration()) {
00057           for (Function::arg_iterator AI = I->arg_begin(), AE = I->arg_end();
00058                AI != AE; ++AI) 
00059             Vals.insert(&*AI);     
00060           for (Function::const_iterator FI = I->begin(), FE = I->end();
00061                FI != FE; ++FI) 
00062             for (BasicBlock::const_iterator BI = FI->begin(), BE = FI->end();
00063                  BI != BE; ++BI)
00064               Vals.insert(&*BI);
00065         }
00066         
00067       }
00068       return false;
00069     }
00070 
00071     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00072       AliasAnalysis::getAnalysisUsage(AU);
00073       AU.setPreservesAll();                         // Does not transform code
00074     }
00075 
00076     //------------------------------------------------
00077     // Implement the AliasAnalysis API
00078     //
00079     AliasResult alias(const Value *V1, unsigned V1Size,
00080                       const Value *V2, unsigned V2Size) {
00081       assert(Vals.find(V1) != Vals.end() && "Never seen value in AA before");
00082       assert(Vals.find(V2) != Vals.end() && "Never seen value in AA before");    
00083       return AliasAnalysis::alias(V1, V1Size, V2, V2Size);
00084     }
00085 
00086     ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size) {
00087       assert(Vals.find(P) != Vals.end() && "Never seen value in AA before");
00088       return AliasAnalysis::getModRefInfo(CS, P, Size);
00089     }
00090 
00091     ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) {
00092       return AliasAnalysis::getModRefInfo(CS1,CS2);
00093     }
00094     
00095     void getMustAliases(Value *P, std::vector<Value*> &RetVals) {
00096       assert(Vals.find(P) != Vals.end() && "Never seen value in AA before");
00097       return AliasAnalysis::getMustAliases(P, RetVals);
00098     }
00099 
00100     bool pointsToConstantMemory(const Value *P) {
00101       assert(Vals.find(P) != Vals.end() && "Never seen value in AA before");
00102       return AliasAnalysis::pointsToConstantMemory(P);
00103     }
00104 
00105     /// getModRefBehavior - Return the behavior of the specified function if
00106     /// called from the specified call site.  The call site may be null in which
00107     /// case the most generic behavior of this function should be returned.
00108     virtual ModRefBehavior getModRefBehavior(Function *F, CallSite CS,
00109                                          std::vector<PointerAccessInfo> *Info) {
00110       assert(Vals.find(F) != Vals.end() && "Never seen value in AA before");
00111       return AliasAnalysis::getModRefBehavior(F, CS, Info);
00112     }
00113 
00114     virtual void deleteValue(Value *V) {
00115       assert(Vals.find(V) != Vals.end() && "Never seen value in AA before");
00116       AliasAnalysis::deleteValue(V);
00117     }
00118     virtual void copyValue(Value *From, Value *To) {
00119       Vals.insert(To);
00120       AliasAnalysis::copyValue(From, To);
00121     }
00122 
00123   };
00124 }
00125 
00126 char AliasDebugger::ID = 0;
00127 static RegisterPass<AliasDebugger>
00128 X("debug-aa", "AA use debugger", false, true);
00129 static RegisterAnalysisGroup<AliasAnalysis> Y(X);
00130 
00131 Pass *llvm::createAliasDebugger() { return new AliasDebugger(); }
00132 



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.