00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _DATAFLOW_H_
00022 #define _DATAFLOW_H_
00023
00024 #include <vector>
00025 #include <map>
00026 #include <set>
00027 #include <stack>
00028
00029 #include "exphelp.h"
00030 #include "managed.h"
00031 #include "boomerang.h"
00032
00033 class Cfg;
00034 class BasicBlock;
00035 class Exp;
00036 class RefExp;
00037 class Statement;
00038 class UserProc;
00039 class PhiAssign;
00040 class Type;
00041
00042 typedef BasicBlock* PBB;
00043
00044 class DataFlow {
00045
00046
00047
00048 std::vector<PBB> BBs;
00049 std::map<PBB, int> indices;
00050
00051
00052
00053
00054
00055 std::vector<int> dfnum;
00056 std::vector<int> semi;
00057 std::vector<int> ancestor;
00058 std::vector<int> idom;
00059 std::vector<int> samedom;
00060 std::vector<int> vertex;
00061 std::vector<int> parent;
00062 std::vector<int> best;
00063 std::vector<std::set<int> > bucket;
00064 int N;
00065 std::vector<std::set<int> > DF;
00066
00067
00068
00069
00070
00071 std::vector<std::set<Exp*, lessExpStar> > A_orig;
00072
00073 std::map<Exp*, std::set<int>, lessExpStar > defsites;
00074
00075 std::set<int> defallsites;
00076
00077 std::map<Exp*, std::set<int>, lessExpStar> A_phi;
00078
00079 std::map<Exp*, Statement*, lessExpStar> defStmts;
00080
00081
00082
00083
00084
00085
00086 std::map<Exp*, std::stack<Statement*>, lessExpStar> Stacks;
00087
00088
00089
00090
00091 bool renameLocalsAndParams;
00092
00093 public:
00094 DataFlow() : renameLocalsAndParams(false) {}
00095
00096
00097
00098 void DFS(int p, int n);
00099 void dominators(Cfg* cfg);
00100 int ancestorWithLowestSemi(int v);
00101 void Link(int p, int n);
00102 void computeDF(int n);
00103
00104 bool placePhiFunctions(UserProc* proc);
00105
00106 bool renameBlockVars(UserProc* proc, int n, bool clearStacks = false);
00107 bool doesDominate(int n, int w);
00108 void setRenameLocalsParams(bool b) {renameLocalsAndParams = b;}
00109 bool canRenameLocalsParams() {return renameLocalsAndParams;}
00110 bool canRename(Exp* e, UserProc* proc);
00111 void convertImplicits(Cfg* cfg);
00112
00113 void findLiveAtDomPhi(int n, LocationSet& usedByDomPhi, LocationSet& usedByDomPhi0,
00114 std::map<Exp*, PhiAssign*, lessExpStar>& defdByPhi);
00115 #if USE_DOMINANCE_NUMS
00116 void setDominanceNums(int n, int& currNum);
00117 #endif
00118 void clearA_phi() {A_phi.clear();}
00119
00120
00121 int pbbToNode(PBB bb) {return indices[bb];}
00122 std::set<int>& getDF(int node) {return DF[node];}
00123 PBB nodeToBB(int node) {return BBs[node];}
00124 int getIdom(int node) {return idom[node];}
00125 int getSemi(int node) {return semi[node];}
00126 std::set<int>& getA_phi(Exp* e) {return A_phi[e];}
00127
00128
00129 void dumpStacks();
00130 void dumpDefsites();
00131 void dumpA_orig();
00132 void dumpA_phi();
00133
00134 };
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 class DefCollector {
00146
00147
00148
00149
00150 bool initialised;
00151
00152
00153
00154 AssignSet defs;
00155 public:
00156
00157
00158
00159 DefCollector() : initialised(false) {}
00160
00161
00162
00163
00164 void makeCloneOf(DefCollector& other);
00165
00166
00167
00168
00169 bool isInitialised() {return initialised;}
00170
00171
00172
00173
00174 void clear() {defs.clear(); initialised = false;}
00175
00176
00177
00178
00179 void insert(Assign* a);
00180
00181
00182
00183 void print(std::ostream& os, bool html = false);
00184
00185
00186
00187
00188 char* prints();
00189 void dump();
00190 Assign* dumpAddrOfFourth();
00191
00192
00193
00194
00195 typedef AssignSet::iterator iterator;
00196 iterator begin() {return defs.begin();}
00197 iterator end() {return defs.end();}
00198 bool existsOnLeft(Exp* e) {return defs.definesLoc(e);}
00199
00200
00201
00202
00203
00204 void updateDefs(std::map<Exp*, std::stack<Statement*>, lessExpStar>& Stacks, UserProc* proc);
00205
00206
00207
00208
00209 Exp* findDefFor(Exp* e);
00210
00211
00212
00213
00214 void searchReplaceAll(Exp* from, Exp* to, bool& change);
00215 };
00216
00217
00218
00219
00220
00221
00222 class UseCollector {
00223
00224
00225
00226
00227 bool initialised;
00228
00229
00230
00231 LocationSet locs;
00232 public:
00233
00234
00235
00236 UseCollector() : initialised(false) {}
00237
00238
00239
00240
00241 void makeCloneOf(UseCollector& other);
00242
00243
00244
00245
00246 bool isInitialised() {return initialised;}
00247
00248
00249
00250
00251 void clear() {locs.clear(); initialised = false;}
00252
00253
00254
00255
00256 void insert(Exp* e) {locs.insert(e);}
00257
00258
00259
00260 void print(std::ostream& os, bool html = false);
00261
00262
00263
00264
00265 char* prints();
00266 void dump();
00267
00268
00269
00270
00271 typedef LocationSet::iterator iterator;
00272 iterator begin() {return locs.begin();}
00273 iterator end() {return locs.end();}
00274 bool exists(Exp* e) {return locs.exists(e);}
00275 LocationSet& getLocSet() {return locs;}
00276 public:
00277
00278
00279
00280 void updateLocs(Statement* u);
00281 void remove(Exp* loc) {
00282 locs.remove(loc);
00283 }
00284 void remove(iterator it) {
00285 locs.remove(it);
00286 }
00287 void fromSSAform(UserProc* proc, Statement* def);
00288 bool operator==(UseCollector& other);
00289 };
00290
00291
00292 #endif // _DATAFLOW_H_
00293