1 //===- MemoryDepAnalysis.h - Compute dep graph for memory ops ---*- C++ -*-===//
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.
8 // The result of this pass is a DependenceGraph for each function
9 // representing the memory-based data dependences between instructions.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_ANALYSIS_MEMORYDEPANALYSIS_H
14 #define LLVM_ANALYSIS_MEMORYDEPANALYSIS_H
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"
26 ///---------------------------------------------------------------------------
27 /// class MemoryDepGraph:
28 /// Dependence analysis for load/store/call instructions using IPModRef info
29 /// computed at the granularity of individual DSGraph nodes.
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 ///---------------------------------------------------------------------------
36 class MemoryDepAnalysis: /* Use if FunctionPass: public DependenceGraph, */
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;
43 /// Information about one function being analyzed.
44 const DSGraph* funcGraph;
45 const FunctionModRefInfo* funcModRef;
47 /// Internal routine that processes each SCC of the CFG.
48 void MemoryDepAnalysis::ProcessSCC(SCC<Function*>& S,
49 ModRefTable& ModRefAfter);
51 friend class PgmDependenceGraph;
55 : /*DependenceGraph(),*/ funcDepGraph(NULL),
56 funcGraph(NULL), funcModRef(NULL) { }
59 ///------------------------------------------------------------------------
60 /// TEMPORARY FUNCTIONS TO MAKE THIS A MODULE PASS ---
61 /// These functions will go away once this class becomes a FunctionPass.
63 /// Driver function to compute dependence graphs for every function.
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.
70 DependenceGraph& getGraph(Function& F) {
71 hash_map<Function*, DependenceGraph*>::iterator I = funcMap.find(&F);
72 assert(I != funcMap.end());
75 const DependenceGraph& getGraph(Function& F) const {
76 hash_map<Function*, DependenceGraph*>::const_iterator
78 assert(I != funcMap.end());
82 /// Release depGraphs held in the Function -> DepGraph map.
84 virtual void releaseMemory();
86 ///----END TEMPORARY FUNCTIONS---------------------------------------------
89 /// Driver functions to compute the Load/Store Dep. Graph per function.
91 bool runOnFunction(Function& _func);
93 /// getAnalysisUsage - This does not modify anything.
94 /// It uses the Top-Down DS Graph and IPModRef.
96 void getAnalysisUsage(AnalysisUsage &AU) const {
98 AU.addRequired<TDDataStructures>();
99 AU.addRequired<IPModRef>();
102 /// Debugging support methods
104 void print(std::ostream &O) const;
109 //===----------------------------------------------------------------------===//