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

defuse.h

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