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