CSFSActivity/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 
00045         //    typedef std::pair<IRSymHandle,ProcHandle> GlobalNode;
00046         class GlobalNode {
00047         public:
00048             GlobalNode(IRSymHandle i, ProcHandle p, CallHandle c, ProcHandle useP)
00049                 : mIRnSym(i), mProc(p), mCall(c), mUseProc(useP) {};
00050             GlobalNode(const GlobalNode& gn)
00051                 : mIRnSym(gn.mIRnSym), mProc(gn.mProc), mCall(gn.mCall), 
00052                   mUseProc(gn.mUseProc) {};
00053             ~GlobalNode(){};
00054 
00055             bool operator==(const GlobalNode& other) const
00056                 {
00057                     if (mIRnSym == other.mIRnSym && mProc == other.mProc &&
00058                         mCall == other.mCall && mUseProc == other.mUseProc) 
00059                         return true;
00060                     return false;
00061                 }
00062 
00063             bool operator<(const GlobalNode& other) const
00064                 {
00065                     if (mIRnSym < other.mIRnSym) return true;
00066                     if (mIRnSym != other.mIRnSym) return false;
00067                     if (mProc < other.mProc) return true;
00068                     if (mProc != other.mProc) return false;
00069                     if (mCall < other.mCall) return true;
00070                     if (mCall != other.mCall) return false;
00071                     if (mUseProc < other.mUseProc) return true;
00072                     return false;
00073                 }
00074 
00075             IRSymHandle mIRnSym;
00076             ProcHandle  mProc;
00077             CallHandle  mCall;
00078             // procedure of the statement where this global is used. This procedure
00079             // can be different when this global is used as an actual parameter. 
00080             // In this case, mProc is the callee procedure.
00081             ProcHandle  mUseProc;
00082         };
00083 
00084 
00085 
00091 class ManagerDUGStandard { 
00092 public:
00093   ManagerDUGStandard(OA_ptr<DUGIRInterface> _ir, 
00094                      OA_ptr<Activity::ActivityIRInterface> _air,
00095                      std::map<ProcHandle,OA_ptr<UDDUChains::UDDUChainsStandard> >&);
00096  ~ManagerDUGStandard () {}
00097 
00098   OA_ptr<DUGStandard> performAnalysis( OA_ptr<IRProcIterator>,
00099                                        OA_ptr<DataFlow::ParamBindings>,
00100                                        OA_ptr<OA::CallGraph::CallGraphInterface>);
00101 
00102   void transitiveClosureDepMatrix(OA_ptr<OA::CallGraph::CallGraphInterface>);
00103   void connectGlobals();
00104   void printIRSymHandle(IRSymHandle, ostream&, OA_ptr<DUGIRInterface>);
00105   void printEdge(IRSymHandle, IRSymHandle, EdgeType);
00106     void printEdgeDot(IRSymHandle, ProcHandle, IRSymHandle, ProcHandle);
00107 
00108 private: // helper functions
00109 
00110   bool stmt_has_call(StmtHandle stmt);
00111   bool isGlobal(SymHandle sym){ 
00112     return mGlobals.find(sym) != mGlobals.end();
00113   }
00114   bool isFormal(SymHandle sym, ProcHandle proc){ 
00115     return mProcToFormalSet[proc].find(sym) != mProcToFormalSet[proc].end();
00116   }
00117 
00118   SymHandle getModSymFromMRE(OA_ptr<OA::MemRefExpr>);
00119   SymHandle getSymFromMRE(OA_ptr<OA::MemRefExpr>);
00120   void collectDefsUsesInStmt(StmtHandle, ProcHandle);
00121   std::set<SymHandle>& getUses(StmtHandle, ProcHandle);
00122   std::set<SymHandle>& getDefs(StmtHandle, ProcHandle);
00123   std::set<SymHandle>& getCallDefs(StmtHandle, ProcHandle);
00124 
00125   void downwardExposedDefs(SymHandle, StmtHandle, ProcHandle, OA_ptr<UDDUChains::UDDUChainsStandard>);
00126   void upwardExposedUses(SymHandle, StmtHandle, ProcHandle, OA_ptr<UDDUChains::UDDUChainsStandard>);
00127   void insertEdge(IRSymHandle, IRSymHandle, EdgeType, CallHandle, ProcHandle, 
00128                   ProcHandle, ProcHandle);
00129   void labelCallRetEdges(StmtHandle, ProcHandle);
00130   void labelUseDefEdges(StmtHandle, ProcHandle);
00131   void collectIndependentSyms( ProcHandle);
00132   void collectDependentSyms( ProcHandle);
00133   void collectFormalParameters(ProcHandle);
00134   void getCallInfo(StmtHandle, ProcHandle);
00135 
00136   void setDepMatrix(ProcHandle, IRSymHandle, IRSymHandle);
00137   void transitiveClosure(ProcHandle proc);
00138   void edgesBetweenFormals(ProcHandle proc);
00139 
00140   void setDepMatrix4Globals(IRSymHandle, IRSymHandle, ProcHandle);
00141   bool isPathThruOtherProcs(IRSymHandle, IRSymHandle, ProcHandle);
00142   bool isOutgoingToOtherProcs(IRSymHandle, ProcHandle);
00143   bool isIncomingFromOtherProcs(IRSymHandle, ProcHandle);
00144   void findOutgoingNodes(IRSymHandle, ProcHandle, std::set<IRSymHandle>&);
00145   void findIncomingNodes(IRSymHandle, ProcHandle, std::set<IRSymHandle>&);
00146     bool hasEdgesToOtherProc(IRSymHandle ish, ProcHandle proc);
00147     bool hasEdgesFromOtherProc(IRSymHandle ish, ProcHandle proc);
00148 
00149 private: // member variables
00150 
00151   OA_ptr<DUGIRInterface> mIR;
00152   OA_ptr<Activity::ActivityIRInterface> mActIR;
00153   OA_ptr<DUGStandard> mDUG;     
00154   OA_ptr<DataFlow::ParamBindings> mParamBind;
00155   std::map<ProcHandle,OA_ptr<UDDUChains::UDDUChainsStandard> >& mProcToUDDUChainsMap;
00156 
00157   // dependence matrix
00158   std::map<ProcHandle,std::map<IRSymHandle, std::map<IRSymHandle, bool> > > 
00159     mProcToMatrix;
00160   std::map<ProcHandle, std::set<IRSymHandle> > mProcToIRSymSet;
00161   // just to prevent duplicate edges between the same nodes
00162   std::map<EdgeType,std::map<IRSymHandle,std::map<IRSymHandle,bool> > > 
00163     mMatrix;
00164 
00165   // for making edges between actual parameters
00166   // proc -> call sites that call 'proc'
00167   std::map<ProcHandle, std::set<CallHandle> > mProcToCallsiteSet;
00168   // proc -> formal parameters of proc
00169   std::map<ProcHandle, std::set<SymHandle> > mProcToFormalSet;
00170   // call site -> (formal -> set of actuals)
00171   std::map<CallHandle, std::map<IRSymHandle, std::set<IRSymHandle> > > 
00172     mFormalToActualMap;
00173   // call site -> proc containing the call site, i.e. the caller
00174   std::map<CallHandle, ProcHandle> mCallsiteToProc;
00175   // call -> formal -> set of actuals
00176   std::map<CallHandle, std::map<SymHandle, std::set<SymHandle> > > mParamMap;
00177   // call -> set of actuals called by reference
00178   std::map<StmtHandle, std::set<SymHandle> > mCallByRefActuals;
00179   std::set<StmtHandle> mCallInfoReady;
00180 
00181   // procedures to be processed. 
00182   // all procedures reachable from the ones with DEP and INDEP vars
00183   std::set<ProcHandle> mProcsOfInterest;
00184 
00185   // statements for which the uses are collected
00186   std::set<StmtHandle> mDefsUsesCollected;
00187   // statement -> used symbols
00188   std::map<StmtHandle, std::set<SymHandle> > mStmtToUsedSyms;
00189   // statement -> defined symbols
00190   std::map<StmtHandle, std::set<SymHandle> > mStmtToDefdSyms;
00191   // statement -> symbols defined by call-by-reference function calls
00192   std::map<StmtHandle, std::set<SymHandle> > mStmtToCallDefdSyms;
00193   // global variables
00194   std::set<SymHandle> mGlobals;
00195   // For connecting global variable nodes
00196   // symbol -> set of IRSymHandle
00197   std::map<SymHandle, std::set<GlobalNode> > mGlobalUpUses;
00198   std::map<SymHandle, std::set<GlobalNode> > mGlobalDnDefs;
00199 };
00200 
00202 
00203 class IndepLocVisitor : public virtual LocationVisitor {
00204   public:
00205       
00206     IndepLocVisitor(OA_ptr<DUGStandard> dug, 
00207                     ProcHandle proc, 
00208                     std::set<ProcHandle> ProcsOfInterest,
00209                     OA_ptr<DUGIRInterface> ir
00210                     ) 
00211                   : mDUG(dug), mProc(proc), mProcsOfInterest(ProcsOfInterest), mIR(ir) 
00212     { }
00213     ~IndepLocVisitor() { }
00214 
00215     void visitNamedLoc(NamedLoc& loc);
00216     void visitUnnamedLoc(UnnamedLoc& loc);
00217     void visitInvisibleLoc(InvisibleLoc& loc);
00218     void visitUnknownLoc(UnknownLoc& loc);
00219     void visitLocSubSet(LocSubSet& loc);
00220     
00221     std::set<ProcHandle> getmProcsOfInterest() 
00222     {
00223         return mProcsOfInterest;
00224     }
00225   private:
00226     OA_ptr<DUGStandard> mDUG;
00227     ProcHandle mProc;
00228     std::set<ProcHandle> mProcsOfInterest;
00229     OA_ptr<DUGIRInterface> mIR;
00230 
00231 };
00232 
00233 class depLocVisitor : public virtual LocationVisitor {
00234   public:
00235     depLocVisitor(OA_ptr<DUGStandard> dug, 
00236                   ProcHandle proc,
00237                   std::set<ProcHandle> ProcsOfInterest ,
00238                   OA_ptr<DUGIRInterface> ir
00239                   )
00240                  : mDUG(dug), mProc(proc), mProcsOfInterest(ProcsOfInterest), mIR(ir)
00241     { }
00242     ~depLocVisitor() {}
00243 
00244     void visitNamedLoc(NamedLoc& loc);
00245     void visitUnnamedLoc(UnnamedLoc& loc);
00246     void visitInvisibleLoc(InvisibleLoc& loc);
00247     void visitUnknownLoc(UnknownLoc& loc);
00248     void visitLocSubSet(LocSubSet& loc);
00249     std::set<ProcHandle> getmProcsOfInterest()
00250     {
00251         return mProcsOfInterest;
00252     }
00253 
00254   private: 
00255      OA_ptr<DUGStandard> mDUG;
00256      ProcHandle mProc; 
00257      std::set<ProcHandle> mProcsOfInterest;
00258      OA_ptr<DUGIRInterface> mIR;
00259 };
00260 
00261 
00262 
00263   } // end of DUG namespace
00264 } // end of OA namespace
00265 
00266 #endif