Iterator that enumerates the ProgramDependenceGraph (PDG) for a function,
[oota-llvm.git] / include / llvm / Analysis / MemoryDepAnalysis.h
1 //===- MemoryDepAnalysis.h - Compute dep graph for memory ops ---*- C++ -*-===//
2 //
3 // This file provides a pass (MemoryDepAnalysis) that computes memory-based
4 // data dependences between instructions for each function in a module.  
5 // Memory-based dependences occur due to load and store operations, but
6 // also the side-effects of call instructions.
7 //
8 // The result of this pass is a DependenceGraph for each function
9 // representing the memory-based data dependences between instructions.
10 //===----------------------------------------------------------------------===//
11
12 #ifndef LLVM_ANALYSIS_MEMORYDEPANALYSIS_H
13 #define LLVM_ANALYSIS_MEMORYDEPANALYSIS_H
14
15 #include "llvm/Analysis/DependenceGraph.h"
16 #include "llvm/Analysis/IPModRef.h"
17 #include "llvm/Analysis/DataStructure.h"
18 #include "llvm/Pass.h"
19 #include "Support/TarjanSCCIterator.h"
20 #include "Support/NonCopyable.h"
21 #include "Support/hash_map"
22
23
24 class Instruction;
25 class Function;
26 class DSGraph;
27 class ModRefTable;
28
29
30 ///---------------------------------------------------------------------------
31 /// class MemoryDepGraph:
32 ///   Dependence analysis for load/store/call instructions using IPModRef info
33 ///   computed at the granularity of individual DSGraph nodes.
34 ///
35 /// This pass computes memory dependences for each function in a module.
36 /// It can be made a FunctionPass once a Pass (such as Parallelize) is
37 /// allowed to use a FunctionPass such as this one.
38 ///---------------------------------------------------------------------------
39
40 class MemoryDepAnalysis: /* Use if FunctionPass: public DependenceGraph, */
41                          public Pass {
42   /// The following map and depGraph pointer are temporary until this class
43   /// becomes a FunctionPass instead of a module Pass. */
44   hash_map<Function*, DependenceGraph*> funcMap;
45   DependenceGraph* funcDepGraph;
46
47   /// Information about one function being analyzed.
48   const DSGraph*  funcGraph;
49   const FunctionModRefInfo* funcModRef;
50
51   /// Internal routine that processes each SCC of the CFG.
52   void MemoryDepAnalysis::ProcessSCC(SCC<Function*>& S,
53                                      ModRefTable& ModRefAfter);
54
55   friend class PgmDependenceGraph;
56
57 public:
58   MemoryDepAnalysis()
59     : /*DependenceGraph(),*/ funcDepGraph(NULL),
60       funcGraph(NULL), funcModRef(NULL) { }
61   ~MemoryDepAnalysis();
62
63   ///------------------------------------------------------------------------
64   /// TEMPORARY FUNCTIONS TO MAKE THIS A MODULE PASS ---
65   /// These functions will go away once this class becomes a FunctionPass.
66   
67   /// Driver function to compute dependence graphs for every function.
68   bool run(Module& M);
69
70   /// getGraph() -- Retrieve the dependence graph for a function.
71   /// This is temporary and will go away once this is a FunctionPass.
72   /// At that point, this class should directly inherit from DependenceGraph.
73   /// 
74   DependenceGraph& getGraph(Function& F) {
75     hash_map<Function*, DependenceGraph*>::iterator I = funcMap.find(&F);
76     assert(I != funcMap.end());
77     return *I->second;
78   }
79   const DependenceGraph& getGraph(Function& F) const {
80     hash_map<Function*, DependenceGraph*>::const_iterator
81       I = funcMap.find(&F);
82     assert(I != funcMap.end());
83     return *I->second;
84   }
85
86   /// Release depGraphs held in the Function -> DepGraph map.
87   /// 
88   virtual void releaseMemory();
89
90   ///----END TEMPORARY FUNCTIONS---------------------------------------------
91
92
93   /// Driver functions to compute the Load/Store Dep. Graph per function.
94   /// 
95   bool runOnFunction(Function& _func);
96
97   /// getAnalysisUsage - This does not modify anything.
98   /// It uses the Top-Down DS Graph and IPModRef.
99   ///
100   void getAnalysisUsage(AnalysisUsage &AU) const {
101     AU.setPreservesAll();
102     AU.addRequired<TDDataStructures>();
103     AU.addRequired<IPModRef>();
104   }
105
106   /// Debugging support methods
107   /// 
108   void print(std::ostream &O) const;
109   void dump() const;
110 };
111
112
113 //===----------------------------------------------------------------------===//
114
115 #endif