C-Breeze
C Compiler Infrastructure

[ Project home page]

liveness.h

Go to the documentation of this file.
00001 // $Id: liveness.h,v 1.12 2005/06/03 02:00:48 akkartik Exp $
00002 // ----------------------------------------------------------------------
00003 //
00004 //  C-Breeze
00005 //  C Compiler Framework
00006 // 
00007 //  Copyright (c) 2003 University of Texas at Austin
00008 // 
00009 //  Samuel Z. Guyer
00010 //  Adam Brown
00011 //  Teck Bok Tok
00012 //  Paul Arthur Navratil
00013 //  Calvin Lin
00014 // 
00015 //  Permission is hereby granted, free of charge, to any person
00016 //  obtaining a copy of this software and associated documentation
00017 //  files (the "Software"), to deal in the Software without
00018 //  restriction, including without limitation the rights to use, copy,
00019 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00020 //  of the Software, and to permit persons to whom the Software is
00021 //  furnished to do so, subject to the following conditions:
00022 //  
00023 //  The above copyright notice and this permission notice shall be
00024 //  included in all copies or substantial portions of the Software.
00025 //  
00026 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00030 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00031 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00032 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00033 //  THE SOFTWARE.
00034 //
00035 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00036 //  Computer Science for inspiring parts of the C-Breeze design.
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   // -- Procedure calls
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   // -- Assignments
00205 
00206   virtual void at_assignment(stmtLocation * current,
00207                              pointerValue & left,
00208                              pointerValue & right,
00209                              pointerValue & result,
00210                              memoryblock_set & changes);
00211 
00212   // -- Statement types
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 & left,
00226                         pointerValue & right,
00227                                 pointerValue & result);
00228 
00229   // -- Process a merge point
00230 
00231   virtual void at_merge(Location * where,
00232                         memoryBlock * block,
00233                         memoryuse_list & phi_uses,
00234                         pointerValue & result,
00235                         memoryblock_set & changes);
00236 
00237   // -- Memory allocation and deallocation
00238 
00239   virtual void at_allocation(stmtLocation * stmt,
00240                              pointervalue_list & arguments,
00241                              memoryBlock * block,
00242                              memoryblock_set & changes);
00243 
00244   virtual void at_deallocation(stmtLocation * stmt,
00245                                pointerValue & to_deallocate,
00246                                memoryblock_set & changes);
00247 
00248   // -- Control-flow options
00249 
00250   virtual void at_stmt_exit(stmtLocation * stmt,
00251                             pointerValue & result);
00252 
00253   virtual void at_basicblock_entry(basicblockLocation * block,
00254                                    procedureInfo * info,
00255                                    pointerValue & initial);
00256 
00257   // -- Procedure boundaries
00258 
00259   virtual void at_procedure_entry(procLocation * proc,
00260                                   procedureInfo * info,
00261                                   pointerValue & return_val);
00262 
00263   virtual void at_procedure_exit(procLocation * proc,
00264                                  procedureInfo * info,
00265                                  pointerValue & return_val);
00266 };
00267 
00271 class deadcodeChanger : public Changer
00272 {
00273 public:
00274 
00275   static void optimize(unitNode * u,
00276                        livenessAnalyzer * liveness);
00277 private:
00278 
00279   livenessAnalyzer * _liveness;
00280 
00281   deadcodeChanger(livenessAnalyzer * liveness);
00282 
00283 public:
00284 
00285   virtual Node * at_threeAddr(threeAddrNode * stmt, Order ord);
00286 };
00287 
00288 
00289 #endif // CBZ_LIVENESS_H

Generated on February 1, 2006
Back to the C-Breeze home page