CFGIRInterface.hpp

Go to the documentation of this file.
00001 
00022 #ifndef CFGIRInterface_h
00023 #define CFGIRInterface_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 "IRHandles.hpp"
00034 #include <OpenAnalysis/Utils/OA_ptr.hpp>
00035 
00036 namespace OA {
00037   namespace CFG {
00038 
00040 enum IRStmtType {
00041   SIMPLE,                       // Anything not covered below.
00042   COMPOUND,                     // A block of statements. 
00043   LOOP,                         // Any type of top-tested, structured loop.
00044   END_TESTED_LOOP,              // Any type of end-tested, structured loop.
00045   STRUCT_TWOWAY_CONDITIONAL,    // Structured if-then-else.
00046   STRUCT_MULTIWAY_CONDITIONAL,  // Structured switch statement.
00047   USTRUCT_TWOWAY_CONDITIONAL_T, // Unstructured branch (on true).
00048   USTRUCT_TWOWAY_CONDITIONAL_F, // Unstructured branch (on false).
00049   USTRUCT_MULTIWAY_CONDITIONAL, // Unstructured multiway branch
00050                                 //  (e.g., computed goto in Fortran or 
00051                                 //  jump tables in low-level/assembly
00052                                 //  languages).
00053   RETURN,                       // Return statement.
00054   BREAK,                        // Break statement.
00055   LOOP_CONTINUE,                // Loop continuation statement.
00056   ALTERNATE_PROC_ENTRY,         // Alternate entry point (e.g., Fortran)
00057   UNCONDITIONAL_JUMP,           // GOTO in HLL, or unconditional direct
00058                                 //   jump in low-level/assembly languages.
00059   UNCONDITIONAL_JUMP_I,         // Assigned GOTO in HLL, or unconditional
00060                                 //   indirect jump in low-level/assembly
00061                                 //   languages.
00062   NONE
00063 };
00064 
00065 
00066 //class EdgeInfo;
00067 
00068 //-----------------------------------------------------------------------------
00069 //
00070 //-----------------------------------------------------------------------------
00071 
00077 class CFGIRInterface : public virtual IRHandlesIRInterface {
00078  public:
00079   CFGIRInterface() { }
00080   //virtual ~CFGIRInterface() = 0 ;
00081   virtual ~CFGIRInterface() {} // changed to get rid of in-charge with whirl, 4/12
00082 
00085   virtual OA_ptr<IRRegionStmtIterator> procBody(ProcHandle h) = 0;
00086   
00087   //--------------------------------------------------------
00088   // Statements: General
00089   //--------------------------------------------------------
00090 
00092   virtual bool returnStatementsAllowed() = 0;
00093 
00095   virtual IRStmtType getCFGStmtType(StmtHandle h) = 0; 
00096 
00099   virtual StmtLabel getLabel(StmtHandle h) = 0; 
00100 
00104   virtual OA_ptr<IRRegionStmtIterator> getFirstInCompound(StmtHandle h) = 0;  
00105   
00106   //--------------------------------------------------------
00107   // Loops
00108   //--------------------------------------------------------
00109 
00112   virtual OA_ptr<IRRegionStmtIterator> loopBody(StmtHandle h) = 0; 
00113 
00116   virtual StmtHandle loopHeader(StmtHandle h) = 0; 
00117 
00119   virtual StmtHandle getLoopIncrement(StmtHandle h) = 0; 
00120 
00135   virtual bool loopIterationsDefinedAtEntry(StmtHandle h) = 0; 
00136 
00137   // deprecated
00138   //OA::ExprHandle getLoopCondition(OA::StmtHandle h); 
00139 
00140 
00141   //--------------------------------------------------------
00142   // Invariant: a two-way conditional or a multi-way conditional MUST provide
00143   // provide either a target, or a target label
00144   //--------------------------------------------------------
00145 
00146   //--------------------------------------------------------
00147   // Structured two-way conditionals
00148   //
00149   // Note: An important pre-condition for structured conditionals is
00150   // that chains of else-ifs must be represented as nested elses.  For
00151   // example, this Matlab statement:
00152   //   if (c1)
00153   //     s1;
00154   //   elseif (c2)
00155   //     s2;
00156   //   else
00157   //     s3;
00158   //   end;
00159   //
00160   // would need be represented by the underlying IR as:
00161   //   if (c1)
00162   //     s1;
00163   //   else
00164   //     if (c2)
00165   //       s2;
00166   //     else
00167   //       s3;
00168   //     end;
00169   //   end; 
00170   //--------------------------------------------------------
00171 
00175   virtual OA_ptr<IRRegionStmtIterator> trueBody(StmtHandle h) = 0; 
00176 
00180   virtual OA_ptr<IRRegionStmtIterator> elseBody(StmtHandle h) = 0; 
00181   
00182   //--------------------------------------------------------
00183   // Structured multiway conditionals
00184   //--------------------------------------------------------
00185 
00188   virtual int numMultiCases(StmtHandle h) = 0; 
00189 
00193   virtual OA_ptr<IRRegionStmtIterator> 
00194       multiBody(StmtHandle h, int bodyIndex) = 0; 
00195 
00202   virtual bool isBreakImplied(StmtHandle multicond) = 0; 
00203 
00206   virtual bool isCatchAll(StmtHandle h, int bodyIndex) = 0;
00207 
00210   virtual OA_ptr<IRRegionStmtIterator> getMultiCatchall (StmtHandle h) = 0;
00211   
00215   virtual ExprHandle getSMultiCondition(StmtHandle h, int bodyIndex) = 0; 
00216 
00217   //--------------------------------------------------------
00218   // Unstructured two-way conditionals: 
00219   //--------------------------------------------------------
00220 
00223   virtual StmtLabel  getTargetLabel(StmtHandle h, int n) = 0; 
00224 
00225   //--------------------------------------------------------
00226   // Unstructured multi-way conditionals
00227   // FIXME: Review all of the multi-way stuff.
00228   //--------------------------------------------------------
00229 
00232   virtual int numUMultiTargets(StmtHandle h) = 0; 
00233 
00236   virtual StmtLabel getUMultiTargetLabel(StmtHandle h, int targetIndex) = 0; 
00237 
00241   virtual StmtLabel getUMultiCatchallLabel(StmtHandle h) = 0; 
00242 
00243   // Given an unstructured multi-way branch, return the condition
00244   // expression corresponding to target 'targetIndex'. The n targets
00245   // are indexed [0..n-1].
00246   // multiway target condition 
00247   virtual ExprHandle getUMultiCondition(StmtHandle h, int targetIndex) = 0; 
00248 
00249   //--------------------------------------------------------
00250   // Special, for assembly-language level instructions only.
00251   // These are necessary because there are some intricacies involved
00252   // in building a CFG for an instruction set which has delayed branches,
00253   // and in particular, allows branches within branch delay slots. 
00254   //--------------------------------------------------------
00255 
00261   virtual bool parallelWithSuccessor(StmtHandle h) = 0;
00262 
00268   virtual int numberOfDelaySlots(StmtHandle h) = 0;
00269 
00270 
00271   //--------------------------------------------------------
00272   // Symbol Handles
00273   //--------------------------------------------------------
00274 
00275   // Currently never used. This might be deprecated in the future.
00276   // virtual SymHandle getProcSymHandle(ProcHandle h) = 0;
00277   
00278 };
00279 
00280 
00281   } // end of namespace CFG
00282 } // end of namespace OA
00283 
00284 #endif // CFGIRInterface_h