MPICFGIRInterface.hpp

Go to the documentation of this file.
00001 
00022 #ifndef MPICFGIRInterface_h
00023 #define MPICFGIRInterface_h
00024 
00025 //-----------------------------------------------------------------------------
00026 // This file contains the abstract base classes for the IR interface.
00027 //
00028 // See the top level README for a description of the IRInterface and
00029 // how to use it.
00030 //-----------------------------------------------------------------------------
00031 
00032 #include <iostream>
00033 #include <map>
00034 #include <list>
00035 
00036 #include <OpenAnalysis/Utils/OA_ptr.hpp>
00037 #include <OpenAnalysis/IRInterface/IRHandles.hpp>
00038 #include <OpenAnalysis/IRInterface/ConstValBasicInterface.hpp>
00039 #include <OpenAnalysis/IRInterface/ConstValIntInterface.hpp>
00040 #include <OpenAnalysis/IRInterface/EvalToConstVisitorIRInterface.hpp>
00041 #include <OpenAnalysis/ExprTree/ExprTree.hpp>
00042 
00043 // FIXME: this needs to go away at some point
00044 #include "CFGIRInterface.hpp"
00045 
00046 namespace OA {
00047   namespace MPICFG {
00048 
00051 //
00052 //  The Open64IRInterface in UseNewOA has a mapping of strings to IRProcType
00053 //  so if we add more recognizable types here, we should add them there, too
00054 //  Also, there is a mapping of IRProcType and IRParamType to param position
00055 //  (int) there also.  Update that structure when a new IRProcType is added.
00056 enum IRProcType {
00057   MPI_NONE,                   // Any non-MPI call
00058   MPI_OTHER,                  // Any MPI call not covered below
00059   MPI_INIT,                   // MPI_Init - called before any other MPI call
00060   MPI_COMM_RANK,              // MPI_Comm_Rank - get own process id in group 
00061   MPI_COMM_SIZE,              // MPI_Comm_Size - # processors in group
00062   MPI_COMM_DUP,               // MPI_Comm_Dup - duplicates oldcomm to comm 
00063   MPI_COMM_SPLIT,             // MPI_Comm_Split - partition comm to subcomm
00064   MPI_SEND,                   // MPI_Send
00065   MPI_RECV,                   // MPI_Recv
00066   MPI_BCAST,                  // MPI_Bcast
00067   MPI_REDUCE,                 // MPI_Reduce
00068   MPI_FINALIZE                // MPI_Finalize
00069 };
00070 
00072 //  The Open64IRInterface in UseNewOA has a mapping of IRProcType and
00073 //  IRParamType to parameter position.  So when a new IRProcType is added
00074 //  that has a parameter type not in IRParamType, update here.
00075 enum IRParamType {
00076   BUF,
00077   COLOR,
00078   COMM,
00079   COUNT,
00080   DATATYPE,
00081   DEST,
00082   GROUP,
00083   IERROR,
00084   KEY,
00085   NEWCOMM,
00086   OP,
00087   RANK,
00088   RECVBUF,
00089   ROOT,
00090   SENDBUF,
00091   SIZE,
00092   SOURCE,
00093   STATUS,
00094   TAG
00095 };
00096 
00097 //    typedef pair<IRProcType,IRParamType> ProcParamPair;
00098 
00099 // return type for examining a parameter expression tree
00100 // first() is true if second() has a useful const value from the parameter
00101 typedef std::pair<bool,OA_ptr<ConstValBasicInterface> > MaybeConstValue;
00102 
00103 //------------------------------------
00104 // for use in MPICFGIdRankVar
00105 
00106 enum IRRankVarStmtType { 
00107   RANK_NO_STMT,    // not a statement, error situation
00108   RANK_ANY_STMT,   // Any statement not covered below
00109   RANK_DEF_STMT    // A statement with a call to MPI_COMM_RANK
00110 };
00111 
00112 enum IRCopyStmtType {
00113   COPY_NO_STMT,    // not a statement, error situation
00114   COPY_ANY_STMT,   // Any statement not covered below
00115   COPY_STMT        // A statement involving only (target = use) pairs
00116 };
00117 
00118 //typedef std::pair<MemRefHandle,MemRefHandle> CopyStmtPair;
00119 class CopyStmtPairIterator {
00120   public:
00121     CopyStmtPairIterator() {}
00122     virtual ~CopyStmtPairIterator() {}
00123 
00124     virtual MemRefHandle currentSource() const = 0;
00125     virtual MemRefHandle currentTarget() const = 0;
00126 
00127     virtual bool isValid() const = 0;
00128                     
00129     virtual void operator++() = 0;
00130     void operator++(int) { ++*this; }
00131 };
00132 
00133 //typedef std::list<CopyStmtPair> CopyStmtPairList;
00134 
00135 //-----------------------------
00136 // for use in MPICFGIdRankVar and MPICFGUpdateLabels
00137 
00138 enum LatticeType {TOP, VALUE, BOTTOM};
00139 
00140 //-----------------------------
00141 // for use in MPICFGUpdateLabels
00142 //----------------
00143 // We want to eventually get here
00144 enum RelOp {GREATER,LESSER,EQUAL,GREATER_EQUAL,LESSER_EQUAL,NOT_EQUAL};
00145 //enum BoolOp {AND, OR, NOT};
00146 //enum RelOp {EQUAL, NOT_EQUAL};
00147 enum BoolOp {AND, OR};
00148 // RankExprTree has toString functions for RelOp, BoolOp, and LatticeType
00149 
00150 
00151 
00157 class MPICFGIRInterface : public virtual IRHandlesIRInterface,
00158                       public virtual EvalToConstVisitorIRInterface 
00159 {
00160  public:
00161   MPICFGIRInterface() { }
00162   virtual ~MPICFGIRInterface() { } 
00163   
00164   //--------------------------------------------------------
00165   // Iterators
00166   //--------------------------------------------------------
00167 
00170   virtual OA_ptr<IRStmtIterator> getStmtIterator(ProcHandle h) = 0; 
00171 
00173   virtual OA_ptr<IRCallsiteIterator> getCallsites(StmtHandle h) = 0;
00174 
00175   // Get IRCallsiteParamIterator for a callsite. 
00176   virtual OA_ptr<IRCallsiteParamIterator> getCallsiteParams(ExprHandle h) = 0;
00177  
00178   //--------------------------------------------------------
00179   // Symbol Handles
00180   //--------------------------------------------------------
00181 
00183   virtual SymHandle getSymHandle(ExprHandle expr) = 0;
00184   
00186   virtual SymHandle getProcSymHandle(ProcHandle h) = 0;
00187  
00188   //--------------------------------------------------------
00189   // Utilities
00190   //--------------------------------------------------------
00191 
00193   virtual std::string toString(const SymHandle h) = 0;
00194 
00196   virtual std::string toString(const ExprHandle h) = 0;
00197 
00199   virtual OA_ptr<ExprTree> getExprTree(ExprHandle h) = 0;
00200 
00201   //--------------------------------------------------------
00202   // MPI-specific functionalities
00203   //--------------------------------------------------------
00204 
00207   virtual IRProcType getMPICFGProcType(SymHandle h) = 0; 
00208 
00212   virtual bool isMPICFGAnyTag(ConstValHandle h) = 0;
00213 
00217   virtual bool isMPICFGAnyTag(ConstSymHandle h) = 0;
00218 
00222   virtual bool isMPICFGAnyTag(OA_ptr<ConstValBasicInterface> c) = 0;
00223 
00227   virtual bool isMPICFGAnySource(ConstValHandle h) = 0;
00228 
00232   virtual bool isMPICFGAnySource(ConstSymHandle h) = 0;
00233 
00237   virtual bool isMPICFGAnySource(OA_ptr<ConstValBasicInterface> c) = 0;
00238 
00239   // The following routines return expression handles to the 
00240   // requested parameter of the MPI call of the given callsite
00241   // represented by an expression handle.  The algorithms
00242   // behind these routines will be dependent upon the MPI interface
00243   // in the source language of the application program.  Currently,
00244   // only implemented for Fortran90.
00245 
00247   // the MPI call within the given expression handle callsite
00248   virtual ExprHandle getMPICFGCommParam(OA::ExprHandle h) = 0;
00249 
00251   // the MPI call within the given expression handle callsite
00252   virtual ExprHandle getMPICFGDataTypeParam(OA::ExprHandle h) = 0;
00253 
00255   // the MPI call within the given expression handle callsite
00256   virtual ExprHandle getMPICFGDestParam(OA::ExprHandle h) = 0;
00257 
00259   // the MPI call within the given expression handle callsite
00260   virtual ExprHandle getMPICFGGroupParam(OA::ExprHandle h) = 0;
00261 
00263   // the MPI call within the given expression handle callsite
00264   virtual ExprHandle getMPICFGOpParam(OA::ExprHandle h) = 0;
00265 
00267   // the MPI call within the given expression handle callsite
00268   virtual ExprHandle getMPICFGRankParam(OA::ExprHandle h) = 0;
00269 
00271   // the MPI call within the given expression handle callsite
00272   virtual ExprHandle getMPICFGRootParam(OA::ExprHandle h) = 0;
00273 
00275   // the MPI call within the given expression handle callsite
00276   virtual ExprHandle getMPICFGSizeParam(OA::ExprHandle h) = 0;
00277 
00279   // the MPI call within the given expression handle callsite
00280   virtual ExprHandle getMPICFGSourceParam(OA::ExprHandle h) = 0;
00281 
00283   // the MPI call within the given expression handle callsite
00284   virtual ExprHandle getMPICFGTagParam(OA::ExprHandle h) = 0;
00285 
00286   //--------------------------------------------------------
00287   // DEBUGGING
00288   //--------------------------------------------------------
00289 
00290   // !Given an expression handle to a parameter, 
00291   // pretty-print it to the output stream os.
00292   virtual void dumpMPICFGparam(ExprHandle h, std::ostream& os) = 0;
00293 
00295   // should be removed after testing
00296   virtual int returnOpEnumValInt(OA::OpHandle op) = 0;
00297 
00300   virtual void dump(StmtHandle stmt, std::ostream& os) 
00301     { os << "Override CFGIRInterfaceDefault::dump(StmtHandle,os)"; }
00302 
00304   // given a ConstValBasicInterface, print out value if any
00305   virtual std::string toString(OA_ptr<OA::ConstValBasicInterface> cvPtr) = 0;
00306 
00307   //--------------------------------------------------------
00308   // Following are extra for ManagerMPICFGIdRankVars
00309   //--------------------------------------------------------
00310 
00312   // But defined above class MPICFGIRInterface
00313   //enum IRRankVarStmtType { RANK_NO_STMT, RANK_ANY_STMT, RANK_DEF_STMT };
00314 
00316   virtual IRRankVarStmtType getMPICFGRankVarStmtType(OA::StmtHandle h) = 0;
00317 
00321   virtual MemRefHandle getMPICFGRankDefMemRef(OA::StmtHandle h) = 0;
00322   
00324   virtual StmtHandle getStmtFromMemRef(OA::MemRefHandle h) = 0;
00325   
00329   virtual OA_ptr<MemRefHandleIterator> getAllMemRefs(StmtHandle stmt) = 0;
00330   
00334   virtual OA_ptr<MemRefHandleIterator> getDefMemRefs(StmtHandle stmt) = 0;
00335 
00339   virtual OA_ptr<MemRefHandleIterator> getUseMemRefs(StmtHandle stmt) = 0;
00340   
00342   virtual std::string toString(const StmtHandle h) = 0;
00343 
00345   virtual std::string toString(const MemRefHandle h) = 0;
00346 
00349   virtual OA_ptr<ConstValBasicInterface> getConstValBasic(ConstSymHandle c) = 0;
00350   
00353   virtual OA_ptr<ConstValBasicInterface> getConstValBasic(ConstValHandle c) = 0;
00354 
00356   virtual IRCopyStmtType getCopyStmtType(OA::StmtHandle h) = 0;; 
00357   
00361   virtual OA_ptr<CopyStmtPairIterator> 
00362       getCopyStmtPairIterator(OA::StmtHandle h) = 0;
00363 
00364   //--------------------------------------------------------
00365   // Following are extra for ManagerMPICFGUpdateLabels
00366   //--------------------------------------------------------
00367 
00371   virtual bool isaRelOp(OA::OpHandle h) = 0;
00372   virtual OA::MPICFG::RelOp getRelOp(OA::OpHandle h) = 0;
00373 
00376   virtual OA_ptr<ConstValIntInterface> 
00377       getConstValInt(OA_ptr<ConstValBasicInterface> c) =0;
00378 
00380   virtual ExprHandle getLoopCondition(OA::StmtHandle h) =0;
00381   virtual ExprHandle getCondition(OA::StmtHandle h) =0;
00382   virtual ExprHandle getSMultiCondition (OA::StmtHandle h, int bodyIndex) =0;
00383   virtual ExprHandle getSMultiTest(OA::StmtHandle h) =0;
00384   virtual ExprHandle getUMultiCondition(OA::StmtHandle h, int targetIndex) =0;
00385   virtual ExprHandle getUMultiTest(OA::StmtHandle h) =0;
00386 
00387   // get number of cases or targets for use in get*MultiCondition above
00388   virtual int numMultiCases(OA::StmtHandle h)=0;
00389   virtual int numUMultiTargets(OA::StmtHandle h)=0;
00390 
00392   virtual CFG::IRStmtType getCFGStmtType(StmtHandle h) = 0; 
00393 
00396   virtual OA_ptr<OA::ConstValBasicInterface>
00397     getConstFromSwitchCase(OA::ExprHandle h) = 0;
00398 
00399   //--------------------------------------------------------
00400   // Following are extra for ManagerInterMPICFGUpBound
00401   //--------------------------------------------------------
00402 
00404   //  virtual OA_ptr<IRProcIterator> getProcIterator(PU_Info* puForest) = 0;
00405   // wish the above existed!  Am passing the iterator directly into 
00406   // the performAnalysis routine from the test program
00407 
00408 };
00409 
00410 
00411   } // end of namespace MPICFG
00412 } // end of namespace OA
00413 
00414 #endif // MPICFGIRInterface_h