00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef CBZ_DEFUSE_H
00039 #define CBZ_DEFUSE_H
00040
00041
00042
00043
00044
00045
00046
00047
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
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