OpenADFortTk (including Open64 and OpenAnalysis references)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CFGIRInterface.hpp
Go to the documentation of this file.
1 
22 #ifndef CFGIRInterface_h
23 #define CFGIRInterface_h
24 
25 //-----------------------------------------------------------------------------
26 // This file contains the abstract base classes for the IR interface.
27 //
28 // See the top level README for a description of the IRInterface and
29 // how to use it.
30 //-----------------------------------------------------------------------------
31 
32 #include <iostream>
33 #include "IRHandles.hpp"
35 
36 namespace OA {
37  namespace CFG {
38 
40 enum IRStmtType {
41  SIMPLE, // Anything not covered below.
42  COMPOUND, // A block of statements.
43  LOOP, // Any type of top-tested, structured loop.
44  END_TESTED_LOOP, // Any type of end-tested, structured loop.
45  STRUCT_TWOWAY_CONDITIONAL, // Structured if-then-else.
46  STRUCT_MULTIWAY_CONDITIONAL, // Structured switch statement.
47  USTRUCT_TWOWAY_CONDITIONAL_T, // Unstructured branch (on true).
48  USTRUCT_TWOWAY_CONDITIONAL_F, // Unstructured branch (on false).
49  USTRUCT_MULTIWAY_CONDITIONAL, // Unstructured multiway branch
50  // (e.g., computed goto in Fortran or
51  // jump tables in low-level/assembly
52  // languages).
53  RETURN, // Return statement.
54  BREAK, // Break statement.
55  LOOP_CONTINUE, // Loop continuation statement.
56  ALTERNATE_PROC_ENTRY, // Alternate entry point (e.g., Fortran)
57  UNCONDITIONAL_JUMP, // GOTO in HLL, or unconditional direct
58  // jump in low-level/assembly languages.
59  UNCONDITIONAL_JUMP_I, // Assigned GOTO in HLL, or unconditional
60  // indirect jump in low-level/assembly
61  // languages.
63 };
64 
65 
66 //class EdgeInfo;
67 
68 //-----------------------------------------------------------------------------
69 //
70 //-----------------------------------------------------------------------------
71 
77 class CFGIRInterface : public virtual IRHandlesIRInterface {
78  public:
80  //virtual ~CFGIRInterface() = 0 ;
81  virtual ~CFGIRInterface() {} // changed to get rid of in-charge with whirl, 4/12
82 
86 
87  //--------------------------------------------------------
88  // Statements: General
89  //--------------------------------------------------------
90 
92  virtual bool returnStatementsAllowed() = 0;
93 
95  virtual IRStmtType getCFGStmtType(StmtHandle h) = 0;
96 
99  virtual StmtLabel getLabel(StmtHandle h) = 0;
100 
105 
106  //--------------------------------------------------------
107  // Loops
108  //--------------------------------------------------------
109 
113 
116  virtual StmtHandle loopHeader(StmtHandle h) = 0;
117 
119  virtual StmtHandle getLoopIncrement(StmtHandle h) = 0;
120 
135  virtual bool loopIterationsDefinedAtEntry(StmtHandle h) = 0;
136 
137  // deprecated
138  //OA::ExprHandle getLoopCondition(OA::StmtHandle h);
139 
140 
141  //--------------------------------------------------------
142  // Invariant: a two-way conditional or a multi-way conditional MUST provide
143  // provide either a target, or a target label
144  //--------------------------------------------------------
145 
146  //--------------------------------------------------------
147  // Structured two-way conditionals
148  //
149  // Note: An important pre-condition for structured conditionals is
150  // that chains of else-ifs must be represented as nested elses. For
151  // example, this Matlab statement:
152  // if (c1)
153  // s1;
154  // elseif (c2)
155  // s2;
156  // else
157  // s3;
158  // end;
159  //
160  // would need be represented by the underlying IR as:
161  // if (c1)
162  // s1;
163  // else
164  // if (c2)
165  // s2;
166  // else
167  // s3;
168  // end;
169  // end;
170  //--------------------------------------------------------
171 
176 
181 
182  //--------------------------------------------------------
183  // Structured multiway conditionals
184  //--------------------------------------------------------
185 
188  virtual int numMultiCases(StmtHandle h) = 0;
189 
194  multiBody(StmtHandle h, int bodyIndex) = 0;
195 
202  virtual bool isBreakImplied(StmtHandle multicond) = 0;
203 
206  virtual bool isCatchAll(StmtHandle h, int bodyIndex) = 0;
207 
211 
215  virtual ExprHandle getSMultiCondition(StmtHandle h, int bodyIndex) = 0;
216 
217  //--------------------------------------------------------
218  // Unstructured two-way conditionals:
219  //--------------------------------------------------------
220 
223  virtual StmtLabel getTargetLabel(StmtHandle h, int n) = 0;
224 
225  //--------------------------------------------------------
226  // Unstructured multi-way conditionals
227  // FIXME: Review all of the multi-way stuff.
228  //--------------------------------------------------------
229 
232  virtual int numUMultiTargets(StmtHandle h) = 0;
233 
236  virtual StmtLabel getUMultiTargetLabel(StmtHandle h, int targetIndex) = 0;
237 
242 
243  // Given an unstructured multi-way branch, return the condition
244  // expression corresponding to target 'targetIndex'. The n targets
245  // are indexed [0..n-1].
246  // multiway target condition
247  virtual ExprHandle getUMultiCondition(StmtHandle h, int targetIndex) = 0;
248 
249  //--------------------------------------------------------
250  // Special, for assembly-language level instructions only.
251  // These are necessary because there are some intricacies involved
252  // in building a CFG for an instruction set which has delayed branches,
253  // and in particular, allows branches within branch delay slots.
254  //--------------------------------------------------------
255 
261  virtual bool parallelWithSuccessor(StmtHandle h) = 0;
262 
268  virtual int numberOfDelaySlots(StmtHandle h) = 0;
269 
270 
271  //--------------------------------------------------------
272  // Symbol Handles
273  //--------------------------------------------------------
274 
275  // Currently never used. This might be deprecated in the future.
276  // virtual SymHandle getProcSymHandle(ProcHandle h) = 0;
277 
278 };
279 
280 
281  } // end of namespace CFG
282 } // end of namespace OA
283 
284 #endif // CFGIRInterface_h