00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 #ifndef opt_goto_INCLUDED
00110 #define opt_goto_INCLUDED "opt_goto.h"
00111
00118 #ifdef _KEEP_RCS_ID
00119 static char *opt_goto_rcs_id = opt_goto_INCLUDED" $Revision: 1.2 $";
00120 #endif
00121
00122 #include "wn.h"
00123 #include "cxx_memory.h"
00124 #include "cxx_template.h"
00125 #include "cxx_hash.h"
00126
00127 class GOTO_DESCRIPTOR {
00128 public:
00129 WN *Goto_Wn;
00130 WN *Label_Wn;
00131 INT Goto_Offset;
00132 INT Label_Offset;
00133 BOOL Is_Dismantled;
00134 BOOL Is_Compgoto;
00135 GOTO_DESCRIPTOR(WN *goto_wn,WN *label_wn,INT goto_offset, INT label_offset,
00136 BOOL is_compgoto) {
00137 Goto_Wn = goto_wn;
00138 Label_Wn = label_wn;
00139 Goto_Offset = goto_offset;
00140 Label_Offset = label_offset;
00141 Is_Dismantled = FALSE;
00142 Is_Compgoto = is_compgoto;
00143 }
00144 };
00145
00146 class LABEL_DESCRIPTOR {
00147 public:
00148 WN *Label_Wn;
00149 INT Offset;
00150 LABEL_DESCRIPTOR(WN *label_wn,INT offset) {
00151 Label_Wn = label_wn;
00152 Offset = offset;
00153 }
00154 };
00155
00156 typedef STACK<GOTO_DESCRIPTOR> GOTO_DESCRIPTOR_STACK;
00157 typedef STACK<LABEL_DESCRIPTOR> LABEL_DESCRIPTOR_STACK;
00158 typedef STACK<WN *> GOTO_TABLE_WN_STACK;
00159
00160 class GOTO_TABLE {
00161 GOTO_DESCRIPTOR_STACK _gd;
00162 GOTO_TABLE_WN_STACK _altentry;
00163 LABEL_DESCRIPTOR_STACK _bad_label;
00164 MEM_POOL *_pool;
00165 WN *_func_nd;
00166 HASH_TABLE<INT,LABEL_DESCRIPTOR *> *_label_table;
00167 WN_MAP _parent_map;
00168 INT _offset;
00169 BOOL _contains_altentry;
00170 public:
00171 GOTO_TABLE(WN *func_nd, MEM_POOL *pool) : _gd(pool), _bad_label(pool),
00172 _altentry(pool), _pool(pool) {
00173 _offset = 0;
00174 _func_nd = func_nd;
00175 _contains_altentry=FALSE;
00176 Build();
00177 }
00178 void Remove_Gotos();
00179 void Print(FILE *fp);
00180 ~GOTO_TABLE() {
00181 WN_MAP_Delete(_parent_map);
00182 CXX_DELETE(_label_table,_pool);
00183 }
00184 private:
00185 WN *Get_Parent(WN *wn) const { return (WN *) WN_MAP_Get(_parent_map,wn); }
00186 void Set_Parent(WN *wn, WN *p) { WN_MAP_Set(_parent_map, wn, (void *)p); };
00187 void Build();
00188 void Build_Rec(WN *wn, WN *parent, BOOL inside_compgoto);
00189 void Fixup_Parents(WN *wn, WN *parent);
00190 void Backpatch();
00191 BOOL Ancestor_Through_If(GOTO_DESCRIPTOR *gd);
00192 BOOL Parent_Through_If(GOTO_DESCRIPTOR *gd);
00193 BOOL Sibling(GOTO_DESCRIPTOR *gd);
00194 void Move_Goto_Out(GOTO_DESCRIPTOR *gd);
00195 void Replace_Goto_With_If(GOTO_DESCRIPTOR *gd);
00196 void Replace_Goto_With_While(GOTO_DESCRIPTOR *gd);
00197 void Move_Into_Else(GOTO_DESCRIPTOR *gd);
00198 void Create_Truebr(GOTO_DESCRIPTOR *gd);
00199 void Promote_Do_While(WN *wn);
00200 WN *Func_Nd() { return _func_nd;};
00201 BOOL Can_Move_Into_Else(GOTO_DESCRIPTOR *gd);
00202 BOOL Is_Truebr(GOTO_DESCRIPTOR *gd);
00203 BOOL Goto_Is_Noop(GOTO_DESCRIPTOR *gd) const;
00204 INT Find_Level(WN *wn);
00205 WN *Find_Common_Ancestor(WN *wn1, WN *wn2);
00206 void Dismantle(WN *bad, WN *parent);
00207 enum {MAX_GOTO_EXPANDING_TRANSFORMATIONS = 20 };
00208 };
00209
00210 class GOTO_WN_PARENT {
00211 public:
00212 WN *wn;
00213 WN *parent;
00214 GOTO_WN_PARENT(WN *w, WN *p) { wn = w; parent = p;}
00215 };
00216
00217 #endif // opt_goto_INCLUDED
00218
00219