Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

liveness.h

Go to the documentation of this file.
00001 
00002 #ifndef CBZ_LIVENESS_H
00003 #define CBZ_LIVENESS_H
00004 
00005 #include "pointers.h"
00006 
00014 class livenessAnalyzer : public analysisProblem
00015 {
00016 private:
00017 
00018   typedef set< stmtNode * > stmt_liveness_set;
00019   typedef stmt_liveness_set::iterator stmt_liveness_set_p;
00020 
00021   typedef set< stmtLocation * > stmtlocation_liveness_set;
00022   typedef stmtlocation_liveness_set::iterator stmtlocation_liveness_set_p;
00023 
00024   typedef pair< basicblockLocation *, memoryBlock * > mergepoint_pair; 
00025   typedef set< mergepoint_pair > mergepoint_liveness_set;
00026   typedef mergepoint_liveness_set::iterator mergepoint_liveness_set_p;
00027 
00028   typedef list< bool > change_stack;
00029 
00035   stmt_liveness_set _live_stmts;
00036 
00043   stmtlocation_liveness_set _live_stmtlocations;
00044 
00051   mergepoint_liveness_set _live_mergepoints;
00052 
00059   memorydef_set _defs;
00060 
00063   bool _change;
00064 
00070   change_stack _change_stack;
00071 
00074   bool _debug;
00075 
00076 public:
00077 
00080   livenessAnalyzer(bool debug);
00081 
00086   virtual string name() { return string("Liveness"); }
00087 
00092   void clear();
00093 
00098   bool isLive(stmtNode * stmt);
00099 
00100 protected:
00101 
00105   void collectDefs(pointerValue & pointer);
00106 
00109   void addDef(memoryDef * def);
00110 
00116   bool determineLiveness();
00117 
00124   bool isLive(memoryUse * use, memoryBlock * owner);
00125 
00130   void setLive(stmtLocation * where);
00131 
00138   void setLive(basicblockLocation * where, memoryBlock * block);
00139 
00140 public:
00141 
00142   virtual void at_index(stmtLocation * current,
00143                         binaryNode * binary,
00144                         pointerValue & left,
00145                         pointerValue & right,
00146                         pointerValue & result,
00147                         bool result_is_a_use);
00148 
00149   // -- Procedure calls
00150 
00151   virtual void at_call(stmtLocation * current, callNode * call,
00152                        pointerValue & call_target,
00153                        procNode * callee,
00154                        pointervalue_list & arguments,
00155                        pointerValue & return_val);
00156 
00157   virtual void at_heap(stmtLocation * current, callNode * call,
00158                        pointervalue_list & arguments,
00159                        pointerValue & return_val,
00160                        bool is_alloc);
00161 
00162   // -- Assignments
00163 
00164   virtual void at_assignment(stmtLocation * current,
00165                              binaryNode * binary,
00166                              pointerValue & left,
00167                              pointerValue & right,
00168                              pointerValue & result,
00169                              bool result_is_a_use,
00170                              memoryblock_set & changes);
00171 
00172   // -- Statement types
00173 
00174   virtual void at_return(stmtLocation * stmt,
00175                          returnNode * ret,
00176                          pointerValue & result,
00177                          pointerValue & return_val);
00178 
00179   virtual void at_exprstmt(stmtLocation * stmt,
00180                            exprstmtNode * es,
00181                            pointerValue & result);
00182 
00183   virtual void at_if(stmtLocation * stmt,
00184                      ifNode * ifnode,
00185                      pointerValue & result);
00186 
00187   // -- Process a merge point
00188 
00189   virtual void at_merge(basicblockLocation * where,
00190                         memoryBlock * block,
00191                         memoryuse_list & phi_uses,
00192                         pointerValue & result,
00193                         memoryblock_set & changes);
00194 
00195   // -- Control-flow options
00196 
00197   virtual void at_stmt_exit(stmtLocation * stmt,
00198                             pointerValue & result);
00199 
00200   virtual void at_basicblock_entry(basicblockLocation * block,
00201                                    procedureInfo * info,
00202                                    pointerValue & initial);
00203 
00204   // -- Procedure boundaries
00205 
00206   virtual void at_procedure_entry(procLocation * proc,
00207                                   procedureInfo * info,
00208                                   pointerValue & return_val);
00209 
00210   virtual void at_procedure_exit(procLocation * proc,
00211                                  procedureInfo * info,
00212                                  pointerValue & return_val);
00213 };
00214 
00218 class deadcodeChanger : public Changer
00219 {
00220 public:
00221 
00222   static void optimize(unitNode * u,
00223                        livenessAnalyzer * liveness)
00224   {
00225     deadcodeChanger ipcc(liveness);
00226     u->change(ipcc);
00227   }
00228 
00229 private:
00230 
00231   livenessAnalyzer * _liveness;
00232 
00233   deadcodeChanger(livenessAnalyzer * liveness);
00234 
00235 public:
00236 
00237   virtual Node * at_exprstmt(exprstmtNode * the_exprstmt, Order ord);
00238 };
00239 
00240 
00241 #endif // CBZ_LIVENESS_H

Generated on Thu Jan 10 12:06:19 2002 for C-Breeze by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001