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