Go to the documentation of this file.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
00112 #ifdef _KEEP_RCS_ID
00113 #endif
00114
00115 #include "wn.h"
00116 #include "cxx_memory.h"
00117 #include "cxx_template.h"
00118 #include "cxx_hash.h"
00119
00120 class GOTO_DESCRIPTOR {
00121 public:
00122 WN *Goto_Wn;
00123 WN *Label_Wn;
00124 INT Goto_Offset;
00125 INT Label_Offset;
00126 BOOL Is_Dismantled;
00127 BOOL Is_Compgoto;
00128 GOTO_DESCRIPTOR(WN *goto_wn,WN *label_wn,INT goto_offset, INT label_offset,
00129 BOOL is_compgoto) {
00130 Goto_Wn = goto_wn;
00131 Label_Wn = label_wn;
00132 Goto_Offset = goto_offset;
00133 Label_Offset = label_offset;
00134 Is_Dismantled = FALSE;
00135 Is_Compgoto = is_compgoto;
00136 }
00137 };
00138
00139 class LABEL_DESCRIPTOR {
00140 public:
00141 WN *Label_Wn;
00142 INT Offset;
00143 LABEL_DESCRIPTOR(WN *label_wn,INT offset) {
00144 Label_Wn = label_wn;
00145 Offset = offset;
00146 }
00147 };
00148
00149 typedef STACK<GOTO_DESCRIPTOR> GOTO_DESCRIPTOR_STACK;
00150 typedef STACK<LABEL_DESCRIPTOR> LABEL_DESCRIPTOR_STACK;
00151 typedef STACK<WN *> GOTO_TABLE_WN_STACK;
00152
00153 class GOTO_TABLE {
00154 GOTO_DESCRIPTOR_STACK _gd;
00155 GOTO_TABLE_WN_STACK _altentry;
00156 LABEL_DESCRIPTOR_STACK _bad_label;
00157 MEM_POOL *_pool;
00158 WN *_func_nd;
00159 HASH_TABLE<INT,LABEL_DESCRIPTOR *> *_label_table;
00160 WN_MAP _parent_map;
00161 INT _offset;
00162 BOOL _contains_altentry;
00163 public:
00164 GOTO_TABLE(WN *func_nd, MEM_POOL *pool) : _gd(pool), _bad_label(pool),
00165 _altentry(pool), _pool(pool) {
00166 _offset = 0;
00167 _func_nd = func_nd;
00168 _contains_altentry=FALSE;
00169 Build();
00170 }
00171 void Remove_Gotos();
00172 void Print(FILE *fp);
00173 ~GOTO_TABLE() {
00174 WN_MAP_Delete(_parent_map);
00175 CXX_DELETE(_label_table,_pool);
00176 }
00177 private:
00178 WN *Get_Parent(WN *wn) const { return (WN *) WN_MAP_Get(_parent_map,wn); }
00179 void Set_Parent(WN *wn, WN *p) { WN_MAP_Set(_parent_map, wn, (void *)p); };
00180 void Build();
00181 void Build_Rec(WN *wn, WN *parent, BOOL inside_compgoto);
00182 void Fixup_Parents(WN *wn, WN *parent);
00183 void Backpatch();
00184 BOOL Ancestor_Through_If(GOTO_DESCRIPTOR *gd);
00185 BOOL Sibling(GOTO_DESCRIPTOR *gd);
00186 void Move_Goto_Out(GOTO_DESCRIPTOR *gd);
00187 void Replace_Goto_With_If(GOTO_DESCRIPTOR *gd);
00188 void Replace_Goto_With_While(GOTO_DESCRIPTOR *gd);
00189 void Move_Into_Else(GOTO_DESCRIPTOR *gd);
00190 BOOL Can_Move_Into_Else(GOTO_DESCRIPTOR *gd);
00191 BOOL Goto_Is_Noop(GOTO_DESCRIPTOR *gd) const;
00192 INT Find_Level(WN *wn);
00193 WN *Find_Common_Ancestor(WN *wn1, WN *wn2);
00194 void Dismantle(WN *bad, WN *parent);
00195 enum {MAX_GOTO_EXPANDING_TRANSFORMATIONS = 20 };
00196 };
00197
00198 class GOTO_WN_PARENT {
00199 public:
00200 WN *wn;
00201 WN *parent;
00202 GOTO_WN_PARENT(WN *w, WN *p) { wn = w; parent = p;}
00203 };
00204
00205 #endif // opt_goto_INCLUDED
00206
00207