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  

defuse.h

Go to the documentation of this file.
00001 // $Id: defuse.h,v 1.5 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 //  Samuel Z. Guyer
00010 //  Daniel A. Jimenez
00011 //  Calvin Lin
00012 // 
00013 //  Permission is hereby granted, free of charge, to any person
00014 //  obtaining a copy of this software and associated documentation
00015 //  files (the "Software"), to deal in the Software without
00016 //  restriction, including without limitation the rights to use, copy,
00017 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00018 //  of the Software, and to permit persons to whom the Software is
00019 //  furnished to do so, subject to the following conditions:
00020 //  
00021 //  The above copyright notice and this permission notice shall be
00022 //  included in all copies or substantial portions of the Software.
00023 //  
00024 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00028 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00029 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00030 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00031 //  THE SOFTWARE.
00032 //
00033 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00034 //  Computer Science for inspiring parts of the C-Breeze design.
00035 //
00036 // ----------------------------------------------------------------------
00037 
00038 #ifndef CBZ_DEFUSE_H
00039 #define CBZ_DEFUSE_H
00040 
00041 //
00042 // defuse.h
00043 //
00044 // For each node, gen() will contain the set of variables used in that
00045 // node (unless they are defined first in that node).
00046 // kill() will contain the set of variables defined in that node
00047 // (unless they are used first in that node).
00048 //
00049 
00050 #define def kill
00051 #define use gen
00052 
00053 typedef string var_id;
00054 
00063 class declSetFlowVal : public FlowVal {
00064 
00065 private:
00066         int     size;
00067         Bits    *bits;
00068         map <var_id, int> *name2num;
00069         declNode **decls;
00070 
00071 public:
00072 
00073         virtual void meet (const FlowVal *v) {
00074                 Union (v);
00075         }
00076 
00077         void to_top (void) {
00078                 bits->reset_all ();
00079         }
00080 
00081         FlowVal * clone (void) const {
00082                 declSetFlowVal *other = new declSetFlowVal (size, name2num, decls);
00083                 other->bits = bits->clone();
00084                 return other;
00085         }
00086 
00087         bool diff (FlowVal *other) const {
00088                 declSetFlowVal *that = (declSetFlowVal *) other;
00089                 for (int i=1; i<=size; i++)
00090                         if (that->bits->value(i) != bits->value(i)) 
00091                                 return true;
00092                 return false;
00093         }
00094 
00095         declSetFlowVal (int n, map<var_id, int> *m, declNode **d) {
00096                 size = n;
00097                 name2num = m;
00098                 decls = d;
00099                 bits = new Bits (n + 1);
00100                 to_top ();
00101         }
00102 
00103         ~declSetFlowVal (void) {
00104                 delete bits;
00105         }
00106 
00107         bool in (var_id id) {
00108                 return bits->value((*name2num)[id]);
00109         }
00110 
00111         bool in (int i) {
00112                 return bits->value (i);
00113         }
00114 
00115         void insert (var_id id) {
00116                 bits->set ((*name2num)[id]);
00117         }
00118 
00119         void insert (int i) {
00120                 bits->set (i);
00121         }
00122 
00123         void copy (FlowVal *other) {
00124                 bits->copy (((declSetFlowVal *)other)->bits);
00125         }
00126 
00127         void Union (const FlowVal *v) {
00128                 declSetFlowVal *w = (declSetFlowVal *) v;
00129                 bits->Or (w->bits);
00130         }
00131 
00132         // this -= that
00133 
00134         void Difference (FlowVal *other) {
00135                 declSetFlowVal *that = (declSetFlowVal *) other;
00136                 Bits comp(size+1);
00137                 comp.copy (that->bits);
00138                 comp.Not ();
00139                 bits->And (&comp);
00140         }
00141 };
00142 
00146 class DefUseWalker: public Walker {
00147         private:
00148         declSetFlowVal  *defs;
00149         declSetFlowVal  *uses;
00150         map<var_id, int> *name2num;
00151         declNode        **decls;
00152         int flowsize;
00153 
00154         void get_uses (Node *);
00155         void get_def (Node *);
00156 
00157         public:
00158 
00159         DefUseWalker (int n, map<var_id, int> *m, declNode **d) :
00160                 Walker (Both, Subtree),
00161                 name2num(m),
00162                 decls(d),
00163                 flowsize(n) { }
00164 
00165         void at_basicblock (basicblockNode *, Order);
00166         void at_proc (procNode *, Order);
00167 };
00168 
00169 #endif // CBZ_DEFUSE_H

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