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.
10 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_ANALYSIS_MEMORYDEPANALYSIS_H
13 #define LLVM_ANALYSIS_MEMORYDEPANALYSIS_H
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"
30 ///---------------------------------------------------------------------------
31 /// class MemoryDepGraph:
32 /// Dependence analysis for load/store/call instructions using IPModRef info
33 /// computed at the granularity of individual DSGraph nodes.
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 ///---------------------------------------------------------------------------
40 class MemoryDepAnalysis: /* Use if FunctionPass: public DependenceGraph, */
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;
47 /// Information about one function being analyzed.
48 const DSGraph* funcGraph;
49 const FunctionModRefInfo* funcModRef;
51 /// Internal routine that processes each SCC of the CFG.
52 void MemoryDepAnalysis::ProcessSCC(SCC<Function*>& S,
53 ModRefTable& ModRefAfter);
55 friend class PgmDependenceGraph;
59 : /*DependenceGraph(),*/ funcDepGraph(NULL),
60 funcGraph(NULL), funcModRef(NULL) { }
63 ///------------------------------------------------------------------------
64 /// TEMPORARY FUNCTIONS TO MAKE THIS A MODULE PASS ---
65 /// These functions will go away once this class becomes a FunctionPass.
67 /// Driver function to compute dependence graphs for every function.
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.
74 DependenceGraph& getGraph(Function& F) {
75 hash_map<Function*, DependenceGraph*>::iterator I = funcMap.find(&F);
76 assert(I != funcMap.end());
79 const DependenceGraph& getGraph(Function& F) const {
80 hash_map<Function*, DependenceGraph*>::const_iterator
82 assert(I != funcMap.end());
86 /// Release depGraphs held in the Function -> DepGraph map.
88 virtual void releaseMemory();
90 ///----END TEMPORARY FUNCTIONS---------------------------------------------
93 /// Driver functions to compute the Load/Store Dep. Graph per function.
95 bool runOnFunction(Function& _func);
97 /// getAnalysisUsage - This does not modify anything.
98 /// It uses the Top-Down DS Graph and IPModRef.
100 void getAnalysisUsage(AnalysisUsage &AU) const {
101 AU.setPreservesAll();
102 AU.addRequired<TDDataStructures>();
103 AU.addRequired<IPModRef>();
106 /// Debugging support methods
108 void print(std::ostream &O) const;
113 //===----------------------------------------------------------------------===//