C-Breeze
C Compiler Infrastructure

[ Project home page]
Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

liveness.h

Go to the documentation of this file.
00001 // $Id: liveness.h,v 1.11 2003/08/08 15:16:29 toktb 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 & result);
00226 
00227   // -- Process a merge point
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   // -- Memory allocation and deallocation
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   // -- Control-flow options
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   // -- Procedure boundaries
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

Generated on August 27, 2003
Back to the C-Breeze home page