C-Breeze
C Compiler Infrastructure

[ Project home page]

dead.h

Go to the documentation of this file.
00001 // $Id: dead.h,v 1.7 2003/08/07 23:14:13 pnav Exp $
00002 // ----------------------------------------------------------------------
00003 //
00004 //  C-Breeze
00005 //  C Compiler Framework
00006 //
00007 //  Copyright (c) 2000 University of Texas at Austin
00008 //
00009 //  Lipphei Adam
00010 //  Samuel Z. Guyer
00011 //  Daniel A. Jimenez
00012 //  Calvin Lin
00013 //
00014 //  Permission is hereby granted, free of charge, to any person
00015 //  obtaining a copy of this software and associated documentation
00016 //  files (the "Software"), to deal in the Software without
00017 //  restriction, including without limitation the rights to use, copy,
00018 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00019 //  of the Software, and to permit persons to whom the Software is
00020 //  furnished to do so, subject to the following conditions:
00021 //
00022 //  The above copyright notice and this permission notice shall be
00023 //  included in all copies or substantial portions of the Software.
00024 //
00025 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00026 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00027 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00028 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00029 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00030 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00031 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00032 //  THE SOFTWARE.
00033 //
00034 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00035 //  Computer Science for inspiring parts of the C-Breeze design.
00036 //
00037 // ----------------------------------------------------------------------
00038 
00039 #ifndef CBZ_DEAD_H
00040 #define CBZ_DEAD_H
00041 
00045 class deadCodeEliminationChanger : public Changer {
00046 private:
00047   LivenessWalker * _lw;
00048 
00049 public:
00050   deadCodeEliminationChanger ();
00051   virtual Node * at_proc (procNode * proc, Order ord);
00052   virtual Node * at_threeAddr (threeAddrNode * node, Order ord);
00053 };
00054 
00055 
00059 class has_struct_walker : public Walker {
00060 public:
00061   bool has_struct;
00062 
00063   has_struct_walker (void) :
00064     Walker(Preorder, Subtree), has_struct(false) { }
00065 
00066   void at_decl (declNode * d, Order) {
00067     has_struct = d->storage_class() == declNode::TYPEDEF;
00068   }
00069 
00070   void at_sue (sueNode * s, Order) {
00071     has_struct = true;
00072   }
00073 
00074   void at_func (funcNode * f, Order) {
00075     has_struct = true;
00076   }
00077 };
00078 
00079 
00083 class UnusedDeclarationCleanupChanger : public Changer {
00084 private:
00085   map <declNode *, bool> used;
00086 
00087 public:
00088   UnusedDeclarationCleanupChanger (void) : 
00089     Changer(Both, Subtree, false) { }
00090 
00091   Node * at_proc (procNode * p, Order ord) {
00092     if (ord == Preorder)
00093       used.clear();
00094     else {
00095       blockNode * b = p->body();
00096       decl_list_p i;
00097       for (i = b->decls().begin() ; i != b->decls().end(); ) {
00098         has_struct_walker w;
00099         (*i)->walk (w);
00100         if (w.has_struct || used[*i])
00101           i++;
00102         else {
00103           int count = b->decls().size();
00104           i = b->decls().erase (i);
00105           assert(count == b->decls().size() + 1);
00106         }
00107       }
00108     }
00109     return p;
00110   }
00111 
00112   Node * at_id (idNode * id, Order ord) {
00113     used[id->decl()] = true;
00114     return id;
00115   }
00116 };
00117 
00118 #endif
00119 

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