LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MemoryDepAnalysis.h

Go to the documentation of this file.
00001 //===- MemoryDepAnalysis.h - Compute dep graph for memory ops ---*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file provides a pass (MemoryDepAnalysis) that computes memory-based
00011 // data dependences between instructions for each function in a module.  
00012 // Memory-based dependences occur due to load and store operations, but
00013 // also the side-effects of call instructions.
00014 //
00015 // The result of this pass is a DependenceGraph for each function
00016 // representing the memory-based data dependences between instructions.
00017 //
00018 //===----------------------------------------------------------------------===//
00019 
00020 #ifndef LLVM_ANALYSIS_MEMORYDEPANALYSIS_H
00021 #define LLVM_ANALYSIS_MEMORYDEPANALYSIS_H
00022 
00023 #include "DependenceGraph.h"
00024 #include "llvm/Pass.h"
00025 #include "llvm/ADT/hash_map"
00026 
00027 namespace llvm {
00028 
00029 class ModRefTable;
00030 class DSGraph;
00031 class FunctionModRefInfo;
00032 
00033 ///---------------------------------------------------------------------------
00034 /// class MemoryDepGraph:
00035 ///   Dependence analysis for load/store/call instructions using IPModRef info
00036 ///   computed at the granularity of individual DSGraph nodes.
00037 ///
00038 /// This pass computes memory dependences for each function in a module.
00039 /// It can be made a FunctionPass once a Pass (such as Parallelize) is
00040 /// allowed to use a FunctionPass such as this one.
00041 ///---------------------------------------------------------------------------
00042 
00043 class MemoryDepAnalysis : public ModulePass {
00044   /// The following map and depGraph pointer are temporary until this class
00045   /// becomes a FunctionPass instead of a module Pass.
00046   hash_map<Function*, DependenceGraph*> funcMap;
00047   DependenceGraph* funcDepGraph;
00048 
00049   /// Information about one function being analyzed.
00050   const DSGraph*  funcGraph;
00051   const FunctionModRefInfo* funcModRef;
00052 
00053   /// Internal routine that processes each SCC of the CFG.
00054   ///
00055   void ProcessSCC(std::vector<BasicBlock*> &SCC, ModRefTable& ModRefAfter,
00056                   bool HasLoop);
00057 
00058   friend class PgmDependenceGraph;
00059 
00060 public:
00061   MemoryDepAnalysis() : funcDepGraph(0), funcGraph(0), funcModRef(0) {}
00062   ~MemoryDepAnalysis();
00063 
00064   /// Driver function to compute dependence graphs for every function.
00065   ///
00066   bool runOnModule(Module &M);
00067 
00068   /// getGraph - Retrieve the dependence graph for a function.
00069   /// This is temporary and will go away once this is a FunctionPass.
00070   /// At that point, this class should directly inherit from DependenceGraph.
00071   /// 
00072   DependenceGraph& getGraph(Function& F) {
00073     hash_map<Function*, DependenceGraph*>::iterator I = funcMap.find(&F);
00074     assert(I != funcMap.end());
00075     return *I->second;
00076   }
00077   const DependenceGraph& getGraph(Function& F) const {
00078     hash_map<Function*, DependenceGraph*>::const_iterator I = funcMap.find(&F);
00079     assert(I != funcMap.end());
00080     return *I->second;
00081   }
00082 
00083   /// Release depGraphs held in the Function -> DepGraph map.
00084   /// 
00085   virtual void releaseMemory();
00086 
00087   /// Driver functions to compute the Load/Store Dep. Graph per function.
00088   /// 
00089   bool runOnFunction(Function &F);
00090 
00091   /// getAnalysisUsage - This does not modify anything.  It uses the Top-Down DS
00092   /// Graph and IPModRef.
00093   void getAnalysisUsage(AnalysisUsage &AU) const;
00094 
00095   /// Debugging support methods
00096   /// 
00097   void print(std::ostream &O) const;
00098   void dump() const;
00099 };
00100 
00101 } // End llvm namespace
00102 
00103 #endif