CSFIActivity/ManagerDUGStandard.hpp

Go to the documentation of this file.
00001 
00016 #ifndef DUGManagerStandard_h
00017 #define DUGManagerStandard_h
00018 
00019 //--------------------------------------------------------------------
00020 // OpenAnalysis headers
00021 #include <OpenAnalysis/IRInterface/DUGIRInterface.hpp>
00022 #include <OpenAnalysis/Utils/OA_ptr.hpp>
00023 #include <OpenAnalysis/ExprTree/ExprTree.hpp>
00024 #include <OpenAnalysis/CFG/EachCFGInterface.hpp>
00025 #include <OpenAnalysis/CFG/CFGInterface.hpp>
00026 #include <OpenAnalysis/SideEffect/InterSideEffectStandard.hpp>
00027 #include <OpenAnalysis/SideEffect/ManagerInterSideEffectStandard.hpp>
00028 #include <OpenAnalysis/Location/Locations.hpp>
00029 #include <OpenAnalysis/Activity/DepDFSet.hpp>
00030 #include <OpenAnalysis/CSFIActivity/DUGStandard.hpp>
00031 
00032 
00033 /*
00034 #include <queue>
00035 #include <set>
00036 #include <map>
00037 #include <string>
00038 #include <algorithm>
00039 #include <cctype>
00040 */
00041 
00042 namespace OA {
00043   namespace DUG {
00044 
00050 class ManagerDUGStandard { 
00051 public:
00052   ManagerDUGStandard(OA_ptr<DUGIRInterface> _ir, 
00053                      OA_ptr<Activity::ActivityIRInterface> _air);
00054  ~ManagerDUGStandard () {}
00055 
00056   OA_ptr<DUGStandard> performAnalysis( OA_ptr<IRProcIterator>,
00057                                        OA_ptr<DataFlow::ParamBindings>,
00058                                        OA_ptr<OA::CallGraph::CallGraphInterface>);
00059 
00060   void transitiveClosureDepMatrix(OA_ptr<OA::CallGraph::CallGraphInterface>);
00061 
00062 private: // helper functions
00063 
00064   bool stmt_has_call(StmtHandle stmt);
00065 
00066   void insertEdge(SymHandle, SymHandle, EdgeType, CallHandle, ProcHandle, ProcHandle, ProcHandle);
00067   void labelCallRetEdges(StmtHandle, ProcHandle);
00068   void labelUseDefEdges(StmtHandle, ProcHandle);
00069   void collectIndependentSyms( ProcHandle);
00070   void collectDependentSyms( ProcHandle);
00071 
00072   void setDepMatrix(ProcHandle, SymHandle, SymHandle);
00073   void transitiveClosure(ProcHandle proc);
00074   void edgesBetweenActuals(ProcHandle proc);
00075 
00076   void setDepMatrix4Globals(SymHandle, SymHandle, ProcHandle);
00077   bool isPathThruOtherProcs(SymHandle, SymHandle, ProcHandle);
00078   bool isOutgoingToOtherProcs(SymHandle, ProcHandle);
00079   bool isIncomingFromOtherProcs(SymHandle, ProcHandle);
00080   bool hasEdgesToOtherProc(SymHandle, ProcHandle);
00081   bool hasEdgesFromOtherProc(SymHandle, ProcHandle);
00082   bool isLocal(SymHandle, ProcHandle);
00083   SymHandle getQuickAndDirtySymHandle(OA_ptr<MemRefExpr>);
00084 
00085 private: // member variables
00086 
00087   OA_ptr<DUGIRInterface> mIR;
00088   OA_ptr<Activity::ActivityIRInterface> mActIR;
00089   OA_ptr<DUGStandard> mDUG;     
00090   OA_ptr<DataFlow::ParamBindings> mParamBind;
00091 
00092   // dependence matrix
00093   std::map<ProcHandle, 
00094            std::map<SymHandle, 
00095                     std::map<SymHandle, bool> > > mProcToMatrix;
00096   std::map<ProcHandle, std::set<SymHandle> > mProcToSymSet;
00097   // just to prevent duplicate edges between the same nodes
00098   std::map<EdgeType, std::map<SymHandle, 
00099                               std::map<SymHandle, bool> > > mMatrix;
00100 
00101   // for making edges between actual parameters
00102   // proc -> call sites that call 'proc'
00103   std::map<ProcHandle, std::set<CallHandle> > mProcToCallsiteSet;
00104   // proc -> formal parameters of proc
00105   std::map<ProcHandle, std::set<SymHandle> > mProcToFormalSet;
00106   // call site -> (formal -> set of actuals)
00107   std::map<CallHandle, 
00108            std::map<SymHandle, 
00109                     std::set<SymHandle> > > mFormalToActualMap;
00110   // call site -> proc containing the call site, i.e. the caller
00111   std::map<CallHandle, ProcHandle> mCallsiteToProc;
00112 
00113   // procedures to be processed. 
00114   // all procedures reachable from the ones with DEP and INDEP vars
00115   std::set<ProcHandle> mProcsOfInterest;
00116 };
00117 
00119 
00120 class IndepLocVisitor : public virtual LocationVisitor {
00121   public:
00122       
00123     IndepLocVisitor(OA_ptr<DUGStandard> dug, 
00124                     ProcHandle proc, 
00125                     std::set<ProcHandle> ProcsOfInterest,
00126                     OA_ptr<DUGIRInterface> ir
00127                     ) 
00128                   : mDUG(dug), mProc(proc), mProcsOfInterest(ProcsOfInterest), mIR(ir) 
00129     { }
00130     ~IndepLocVisitor() { }
00131 
00132     void visitNamedLoc(NamedLoc& loc);
00133     void visitUnnamedLoc(UnnamedLoc& loc);
00134     void visitInvisibleLoc(InvisibleLoc& loc);
00135     void visitUnknownLoc(UnknownLoc& loc);
00136     void visitLocSubSet(LocSubSet& loc);
00137     
00138     std::set<ProcHandle> getmProcsOfInterest() 
00139     {
00140         return mProcsOfInterest;
00141     }
00142   private:
00143     OA_ptr<DUGStandard> mDUG;
00144     ProcHandle mProc;
00145     std::set<ProcHandle> mProcsOfInterest;
00146     OA_ptr<DUGIRInterface> mIR;
00147 
00148 };
00149 
00150 class depLocVisitor : public virtual LocationVisitor {
00151   public:
00152     depLocVisitor(OA_ptr<DUGStandard> dug, 
00153                   ProcHandle proc,
00154                   std::set<ProcHandle> ProcsOfInterest ,
00155                   OA_ptr<DUGIRInterface> ir
00156                   )
00157                  : mDUG(dug), mProc(proc), mProcsOfInterest(ProcsOfInterest), mIR(ir)
00158     { }
00159     ~depLocVisitor() {}
00160 
00161     void visitNamedLoc(NamedLoc& loc);
00162     void visitUnnamedLoc(UnnamedLoc& loc);
00163     void visitInvisibleLoc(InvisibleLoc& loc);
00164     void visitUnknownLoc(UnknownLoc& loc);
00165     void visitLocSubSet(LocSubSet& loc);
00166     std::set<ProcHandle> getmProcsOfInterest()
00167     {
00168         return mProcsOfInterest;
00169     }
00170 
00171   private: 
00172      OA_ptr<DUGStandard> mDUG;
00173      ProcHandle mProc; 
00174      std::set<ProcHandle> mProcsOfInterest;
00175      OA_ptr<DUGIRInterface> mIR;
00176 };
00177 
00178 
00179 
00180   } // end of DUG namespace
00181 } // end of OA namespace
00182 
00183 #endif