1 //===- MemoryDepAnalysis.h - Compute dep graph for memory ops ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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.
15 // The result of this pass is a DependenceGraph for each function
16 // representing the memory-based data dependences between instructions.
18 //===----------------------------------------------------------------------===//
20 #ifndef LLVM_ANALYSIS_MEMORYDEPANALYSIS_H
21 #define LLVM_ANALYSIS_MEMORYDEPANALYSIS_H
23 #include "llvm/Analysis/DependenceGraph.h"
24 #include "llvm/Pass.h"
25 #include "Support/hash_map"
31 class FunctionModRefInfo;
33 ///---------------------------------------------------------------------------
34 /// class MemoryDepGraph:
35 /// Dependence analysis for load/store/call instructions using IPModRef info
36 /// computed at the granularity of individual DSGraph nodes.
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 ///---------------------------------------------------------------------------
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;
49 /// Information about one function being analyzed.
50 const DSGraph* funcGraph;
51 const FunctionModRefInfo* funcModRef;
53 /// Internal routine that processes each SCC of the CFG.
54 void ProcessSCC(std::vector<BasicBlock*> &SCC, ModRefTable& ModRefAfter,
57 friend class PgmDependenceGraph;
60 MemoryDepAnalysis() : funcDepGraph(0), funcGraph(0), funcModRef(0) {}
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();
87 /// Driver functions to compute the Load/Store Dep. Graph per function.
89 bool runOnFunction(Function &F);
91 /// getAnalysisUsage - This does not modify anything. It uses the Top-Down DS
92 /// Graph and IPModRef.
93 void getAnalysisUsage(AnalysisUsage &AU) const;
95 /// Debugging support methods
97 void print(std::ostream &O) const;
101 } // End llvm namespace