1 //===- DataStructure.h - Build data structure graphs ------------*- C++ -*-===//
3 // Implement the LLVM data structure analysis library.
5 //===----------------------------------------------------------------------===//
7 #ifndef LLVM_ANALYSIS_DATA_STRUCTURE_H
8 #define LLVM_ANALYSIS_DATA_STRUCTURE_H
10 #include "llvm/Pass.h"
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
23 bool isPointerType(const Type *Ty);
27 // LocalDataStructures - The analysis that computes the local data structure
28 // graphs for all of the functions in the program.
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.
33 class LocalDataStructures : public Pass {
34 // DSInfo, one graph for each function
35 std::map<const Function*, DSGraph*> DSInfo;
36 DSGraph *GlobalsGraph;
38 ~LocalDataStructures() { releaseMemory(); }
40 virtual bool run(Module &M);
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!");
49 // print - Print out the analysis results...
50 void print(std::ostream &O, const Module *M) const;
52 // If the pass pipeline is done with this pass, we can release our memory...
53 virtual void releaseMemory();
55 // getAnalysisUsage - This obviously provides a data structure graph.
56 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
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).
66 class BUDataStructures : public Pass {
67 // DSInfo, one graph for each function
68 std::map<const Function*, DSGraph*> DSInfo;
70 ~BUDataStructures() { releaseMemory(); }
72 virtual bool run(Module &M);
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!");
81 // print - Print out the analysis results...
82 void print(std::ostream &O, const Module *M) const;
84 // If the pass pipeline is done with this pass, we can release our memory...
85 virtual void releaseMemory();
87 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
89 AU.addRequired<LocalDataStructures>();
92 DSGraph &calculateGraph(Function &F);
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.
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;
105 ~TDDataStructures() { releaseMemory(); }
107 virtual bool run(Module &M);
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!");
116 // print - Print out the analysis results...
117 void print(std::ostream &O, const Module *M) const;
119 // If the pass pipeline is done with this pass, we can release our memory...
120 virtual void releaseMemory();
122 // getAnalysisUsage - This obviously provides a data structure graph.
123 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
124 AU.setPreservesAll();
125 AU.addRequired<BUDataStructures>();
128 void calculateGraph(Function &F);
129 DSGraph &getOrCreateDSGraph(Function &F);
131 void ResolveCallSite(DSGraph &Graph, const DSCallSite &CallSite);