Remove VISIBILITY_HIDDEN from class/struct found inside anonymous namespaces.
[oota-llvm.git] / lib / Analysis / AliasDebugger.cpp
1 //===- AliasDebugger.cpp - Simple Alias Analysis Use Checker --------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This simple pass checks alias analysis users to ensure that if they
11 // create a new value, they do not query AA without informing it of the value.
12 // It acts as a shim over any other AA pass you want.
13 //
14 // Yes keeping track of every value in the program is expensive, but this is 
15 // a debugging pass.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #include "llvm/Analysis/Passes.h"
20 #include "llvm/Module.h"
21 #include "llvm/Pass.h"
22 #include "llvm/Instructions.h"
23 #include "llvm/Constants.h"
24 #include "llvm/DerivedTypes.h"
25 #include "llvm/Analysis/AliasAnalysis.h"
26 #include "llvm/Support/Compiler.h"
27 #include <set>
28 using namespace llvm;
29
30 namespace {
31   
32   class AliasDebugger : public ModulePass, public AliasAnalysis {
33
34     //What we do is simple.  Keep track of every value the AA could
35     //know about, and verify that queries are one of those.
36     //A query to a value that didn't exist when the AA was created
37     //means someone forgot to update the AA when creating new values
38
39     std::set<const Value*> Vals;
40     
41   public:
42     static char ID; // Class identification, replacement for typeinfo
43     AliasDebugger() : ModulePass(&ID) {}
44
45     bool runOnModule(Module &M) {
46       InitializeAliasAnalysis(this);                 // set up super class
47
48       for(Module::global_iterator I = M.global_begin(),
49             E = M.global_end(); I != E; ++I)
50         Vals.insert(&*I);
51
52       for(Module::iterator I = M.begin(),
53             E = M.end(); I != E; ++I){
54         Vals.insert(&*I);
55         if(!I->isDeclaration()) {
56           for (Function::arg_iterator AI = I->arg_begin(), AE = I->arg_end();
57                AI != AE; ++AI) 
58             Vals.insert(&*AI);     
59           for (Function::const_iterator FI = I->begin(), FE = I->end();
60                FI != FE; ++FI) 
61             for (BasicBlock::const_iterator BI = FI->begin(), BE = FI->end();
62                  BI != BE; ++BI)
63               Vals.insert(&*BI);
64         }
65         
66       }
67       return false;
68     }
69
70     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
71       AliasAnalysis::getAnalysisUsage(AU);
72       AU.setPreservesAll();                         // Does not transform code
73     }
74
75     //------------------------------------------------
76     // Implement the AliasAnalysis API
77     //
78     AliasResult alias(const Value *V1, unsigned V1Size,
79                       const Value *V2, unsigned V2Size) {
80       assert(Vals.find(V1) != Vals.end() && "Never seen value in AA before");
81       assert(Vals.find(V2) != Vals.end() && "Never seen value in AA before");    
82       return AliasAnalysis::alias(V1, V1Size, V2, V2Size);
83     }
84
85     ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size) {
86       assert(Vals.find(P) != Vals.end() && "Never seen value in AA before");
87       return AliasAnalysis::getModRefInfo(CS, P, Size);
88     }
89
90     ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) {
91       return AliasAnalysis::getModRefInfo(CS1,CS2);
92     }
93     
94     void getMustAliases(Value *P, std::vector<Value*> &RetVals) {
95       assert(Vals.find(P) != Vals.end() && "Never seen value in AA before");
96       return AliasAnalysis::getMustAliases(P, RetVals);
97     }
98
99     bool pointsToConstantMemory(const Value *P) {
100       assert(Vals.find(P) != Vals.end() && "Never seen value in AA before");
101       return AliasAnalysis::pointsToConstantMemory(P);
102     }
103
104     virtual void deleteValue(Value *V) {
105       assert(Vals.find(V) != Vals.end() && "Never seen value in AA before");
106       AliasAnalysis::deleteValue(V);
107     }
108     virtual void copyValue(Value *From, Value *To) {
109       Vals.insert(To);
110       AliasAnalysis::copyValue(From, To);
111     }
112
113   };
114 }
115
116 char AliasDebugger::ID = 0;
117 static RegisterPass<AliasDebugger>
118 X("debug-aa", "AA use debugger", false, true);
119 static RegisterAnalysisGroup<AliasAnalysis> Y(X);
120
121 Pass *llvm::createAliasDebugger() { return new AliasDebugger(); }
122