Clean up DSGraph::removeDeadNodes interface
[oota-llvm.git] / include / llvm / Analysis / DataStructure.h
1 //===- DataStructure.h - Build data structure graphs ------------*- C++ -*-===//
2 //
3 // Implement the LLVM data structure analysis library.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #ifndef LLVM_ANALYSIS_DATA_STRUCTURE_H
8 #define LLVM_ANALYSIS_DATA_STRUCTURE_H
9
10 #include "llvm/Pass.h"
11 #include <set>
12
13 class Type;
14 class DSGraph;
15 class DSNode;
16 class DSCallSite;
17
18 // FIXME: move this stuff to a private header
19 namespace DataStructureAnalysis {
20   // isPointerType - Return true if this first class type is big enough to hold
21   // a pointer.
22   //
23   bool isPointerType(const Type *Ty);
24 }
25
26
27 // LocalDataStructures - The analysis that computes the local data structure
28 // graphs for all of the functions in the program.
29 //
30 // FIXME: This should be a Function pass that can be USED by a Pass, and would
31 // be automatically preserved.  Until we can do that, this is a Pass.
32 //
33 class LocalDataStructures : public Pass {
34   // DSInfo, one graph for each function
35   std::map<const Function*, DSGraph*> DSInfo;
36   DSGraph *GlobalsGraph;
37 public:
38   ~LocalDataStructures() { releaseMemory(); }
39
40   virtual bool run(Module &M);
41
42   // getDSGraph - Return the data structure graph for the specified function.
43   DSGraph &getDSGraph(const Function &F) const {
44     std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
45     assert(I != DSInfo.end() && "Function not in module!");
46     return *I->second;
47   }
48
49   // print - Print out the analysis results...
50   void print(std::ostream &O, const Module *M) const;
51
52   // If the pass pipeline is done with this pass, we can release our memory...
53   virtual void releaseMemory();
54
55   // getAnalysisUsage - This obviously provides a data structure graph.
56   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
57     AU.setPreservesAll();
58   }
59 };
60
61
62 // BUDataStructures - The analysis that computes the interprocedurally closed
63 // data structure graphs for all of the functions in the program.  This pass
64 // only performs a "Bottom Up" propagation (hence the name).
65 //
66 class BUDataStructures : public Pass {
67   // DSInfo, one graph for each function
68   std::map<const Function*, DSGraph*> DSInfo;
69 public:
70   ~BUDataStructures() { releaseMemory(); }
71
72   virtual bool run(Module &M);
73
74   // getDSGraph - Return the data structure graph for the specified function.
75   DSGraph &getDSGraph(const Function &F) const {
76     std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
77     assert(I != DSInfo.end() && "Function not in module!");
78     return *I->second;
79   }
80
81    // print - Print out the analysis results...
82   void print(std::ostream &O, const Module *M) const;
83
84   // If the pass pipeline is done with this pass, we can release our memory...
85   virtual void releaseMemory();
86
87   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
88     AU.setPreservesAll();
89     AU.addRequired<LocalDataStructures>();
90   }
91 private:
92   DSGraph &calculateGraph(Function &F);
93 };
94
95
96 // TDDataStructures - Analysis that computes new data structure graphs
97 // for each function using the closed graphs for the callers computed
98 // by the bottom-up pass.
99 //
100 class TDDataStructures : public Pass {
101   // DSInfo, one graph for each function
102   std::map<const Function*, DSGraph*> DSInfo;
103   std::set<const Function*> GraphDone;
104 public:
105   ~TDDataStructures() { releaseMemory(); }
106
107   virtual bool run(Module &M);
108
109   // getDSGraph - Return the data structure graph for the specified function.
110   DSGraph &getDSGraph(const Function &F) const {
111     std::map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
112     assert(I != DSInfo.end() && "Function not in module!");
113     return *I->second;
114   }
115
116   // print - Print out the analysis results...
117   void print(std::ostream &O, const Module *M) const;
118
119   // If the pass pipeline is done with this pass, we can release our memory...
120   virtual void releaseMemory();
121
122   // getAnalysisUsage - This obviously provides a data structure graph.
123   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
124     AU.setPreservesAll();
125     AU.addRequired<BUDataStructures>();
126   }
127 private:
128   void calculateGraph(Function &F);
129   DSGraph &getOrCreateDSGraph(Function &F);
130
131   void ResolveCallSite(DSGraph &Graph, const DSCallSite &CallSite);
132 };
133
134 #endif