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"
29 class FunctionModRefInfo;
31 ///---------------------------------------------------------------------------
32 /// class MemoryDepGraph:
33 /// Dependence analysis for load/store/call instructions using IPModRef info
34 /// computed at the granularity of individual DSGraph nodes.
36 /// This pass computes memory dependences for each function in a module.
37 /// It can be made a FunctionPass once a Pass (such as Parallelize) is
38 /// allowed to use a FunctionPass such as this one.
39 ///---------------------------------------------------------------------------
41 class MemoryDepAnalysis : public Pass {
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 ProcessSCC(std::vector<BasicBlock*> &SCC, ModRefTable& ModRefAfter,
55 friend class PgmDependenceGraph;
58 MemoryDepAnalysis() : funcDepGraph(0), funcGraph(0), funcModRef(0) {}
61 /// Driver function to compute dependence graphs for every function.
64 /// getGraph() -- Retrieve the dependence graph for a function.
65 /// This is temporary and will go away once this is a FunctionPass.
66 /// At that point, this class should directly inherit from DependenceGraph.
68 DependenceGraph& getGraph(Function& F) {
69 hash_map<Function*, DependenceGraph*>::iterator I = funcMap.find(&F);
70 assert(I != funcMap.end());
73 const DependenceGraph& getGraph(Function& F) const {
74 hash_map<Function*, DependenceGraph*>::const_iterator
76 assert(I != funcMap.end());
80 /// Release depGraphs held in the Function -> DepGraph map.
82 virtual void releaseMemory();
85 /// Driver functions to compute the Load/Store Dep. Graph per function.
87 bool runOnFunction(Function &F);
89 /// getAnalysisUsage - This does not modify anything. It uses the Top-Down DS
90 /// Graph and IPModRef.
91 void getAnalysisUsage(AnalysisUsage &AU) const;
93 /// Debugging support methods
95 void print(std::ostream &O) const;