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 #ifndef CBZ_DEFUSE_H
00038 #define CBZ_DEFUSE_H
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #define def kill
00050 #define use gen
00051
00052 typedef string var_id;
00053
00054
00055
00056
00057
00058
00059
00060
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
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