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 #ifndef CBZ_LIVENESS_H
00041 #define CBZ_LIVENESS_H
00042
00043 #include "pointers.h"
00044
00045 typedef set< procNode * > procedure_set;
00046 typedef procedure_set::iterator procedure_set_p;
00047 typedef procedure_set::const_iterator procedure_set_cp;
00048
00056 class livenessAnalyzer : public analysisProblem
00057 {
00058 private:
00059
00060 typedef set< stmtNode * > stmt_liveness_set;
00061 typedef stmt_liveness_set::iterator stmt_liveness_set_p;
00062
00063 typedef set< stmtLocation * > stmtlocation_liveness_set;
00064 typedef stmtlocation_liveness_set::iterator stmtlocation_liveness_set_p;
00065
00066 typedef pair< Location *, memoryBlock * > mergepoint_pair;
00067 typedef set< mergepoint_pair > mergepoint_liveness_set;
00068 typedef mergepoint_liveness_set::iterator mergepoint_liveness_set_p;
00069
00070 typedef list< bool > change_stack;
00071 typedef change_stack::iterator change_stack_p;
00072
00078 stmt_liveness_set _live_stmts;
00079
00086 stmtlocation_liveness_set _live_stmtlocations;
00087
00094 mergepoint_liveness_set _live_mergepoints;
00095
00102 memorydef_set _defs;
00103
00106 bool _change;
00107
00113 change_stack _change_stack;
00114
00120 procedure_set _visited_procedures;
00121
00122 public:
00123
00126 livenessAnalyzer();
00127
00132 virtual string name() { return string("Liveness"); }
00133
00138 void clear();
00139
00144 bool isLive(stmtNode * stmt);
00145
00146 protected:
00147
00151 void collectDefs(pointerValue & pointer);
00152
00155 void addDef(memoryDef * def);
00156
00162 bool determineLiveness();
00163
00170 bool isLive(memoryUse * use, memoryBlock * owner);
00171
00176 void setLive(stmtLocation * where);
00177
00184 void setLive(Location * where, memoryBlock * block);
00185
00186 public:
00187
00188 inline const procedure_set & visited_procedures() const { return _visited_procedures; }
00189
00190 virtual void at_index(stmtLocation * current,
00191 operandNode * operand,
00192 pointerValue & left,
00193 pointerValue & right,
00194 pointerValue & result);
00195
00196
00197
00198 virtual void at_call(stmtLocation * current, operandNode * call,
00199 pointerValue & call_target,
00200 procNode * callee,
00201 pointervalue_list & arguments,
00202 pointerValue & return_val);
00203
00204
00205
00206 virtual void at_assignment(stmtLocation * current,
00207 pointerValue & left,
00208 pointerValue & right,
00209 pointerValue & result,
00210 memoryblock_set & changes);
00211
00212
00213
00214 virtual void at_return(stmtLocation * stmt,
00215 returnNode * ret,
00216 pointerValue & result,
00217 pointerValue & return_val);
00218
00219 virtual void at_threeAddr(stmtLocation * stmt,
00220 threeAddrNode * threeaddr,
00221 pointerValue & result);
00222
00223 virtual void at_conditiongoto(stmtLocation * stmt,
00224 conditiongotoNode *c,
00225 pointerValue & result);
00226
00227
00228
00229 virtual void at_merge(Location * where,
00230 memoryBlock * block,
00231 memoryuse_list & phi_uses,
00232 pointerValue & result,
00233 memoryblock_set & changes);
00234
00235
00236
00237 virtual void at_allocation(stmtLocation * stmt,
00238 pointervalue_list & arguments,
00239 memoryBlock * block,
00240 memoryblock_set & changes);
00241
00242 virtual void at_deallocation(stmtLocation * stmt,
00243 pointerValue & to_deallocate,
00244 memoryblock_set & changes);
00245
00246
00247
00248 virtual void at_stmt_exit(stmtLocation * stmt,
00249 pointerValue & result);
00250
00251 virtual void at_basicblock_entry(basicblockLocation * block,
00252 procedureInfo * info,
00253 pointerValue & initial);
00254
00255
00256
00257 virtual void at_procedure_entry(procLocation * proc,
00258 procedureInfo * info,
00259 pointerValue & return_val);
00260
00261 virtual void at_procedure_exit(procLocation * proc,
00262 procedureInfo * info,
00263 pointerValue & return_val);
00264 };
00265
00269 class deadcodeChanger : public Changer
00270 {
00271 public:
00272
00273 static void optimize(unitNode * u,
00274 livenessAnalyzer * liveness);
00275 private:
00276
00277 livenessAnalyzer * _liveness;
00278
00279 deadcodeChanger(livenessAnalyzer * liveness);
00280
00281 public:
00282
00283 virtual Node * at_threeAddr(threeAddrNode * stmt, Order ord);
00284 };
00285
00286
00287 #endif // CBZ_LIVENESS_H