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_LOCATION_H
00038 #define CBZ_LOCATION_H
00039
00040 #include "allocation.h"
00041 #include "dominators.h"
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 class procLocation;
00082 class basicblockLocation;
00083 class stmtLocation;
00084
00085 class Location : public PerClassHeap< PointersHeap >
00086 {
00087 public:
00088
00089 typedef enum { Statement, BasicBlock, Procedure } LocationKind;
00090
00091 static unsigned int stmt_count;
00092 static unsigned int block_count;
00093 static unsigned int proc_count;
00094 static unsigned int dom_calls;
00095
00096 private:
00097
00098 Location & operator=(const Location & other)
00099 {
00100 cerr << "ERROR: Cannot assign Location objects" << endl;
00101 return *this;
00102 }
00103
00104 protected:
00105
00106 Location * _parent;
00107
00108 int _depth:16;
00109 int _kind:4;
00110 int _dominates_exit:1;
00111 int _not_basicblock:1;
00112 int _not_procedure:1;
00113
00114 public:
00115
00116 Location(Location * parent, LocationKind kind);
00117
00118
00119
00120 inline int depth() const { return _depth; }
00121 inline LocationKind kind() const { return (LocationKind)_kind; }
00122 inline Location * parent() const { return _parent; }
00123
00124 inline int dominates_exit() const { return _dominates_exit; }
00125
00128 static bool dominates(const Location * dom, const Location * cur);
00129
00132 static bool strictly_dominates(const Location * dom, const Location * cur);
00133
00136 static Location * common_parent(Location * one,
00137 Location * two);
00138
00141 static procLocation * procedure(Location * where);
00142
00145 static bool is_prefix(const Location * prefix, const Location * longer);
00146
00152 virtual void adjust_depth() = 0;
00153
00154
00155
00156 virtual void print(ostream & o) const = 0;
00157 virtual void print_path(ostream & o) const = 0;
00158
00159 friend ostream & operator<<(ostream & o, const Location & loc) {
00160 loc.print_path(o);
00161 return o;
00162 }
00163
00164
00165
00166 virtual ~Location();
00167
00168
00169
00170 static void stats();
00171 };
00172
00173
00174
00175
00176
00177 class stmtLocation : public Location
00178 {
00179 friend class basicblockLocation;
00180 friend class procLocation;
00181
00182 private:
00183
00184 int _stmt_num;
00185 stmtNode * _stmt;
00186 procLocation * _calls;
00187
00188 inline void stmt_num(int num) { _stmt_num = num; }
00189 inline void stmt(stmtNode * s) { _stmt = s; }
00190
00191 public:
00192
00193 stmtLocation(basicblockLocation * parent);
00194
00201 void setup_call(procNode * proc, bool is_context_insensitive);
00202
00208 procLocation * remove_call();
00209
00210
00211
00212 inline basicblockLocation * block_location() const
00213 { return (basicblockLocation *) _parent; }
00214
00215 inline int stmt_num() const { return _stmt_num; }
00216
00217 inline stmtNode * stmt() const { return _stmt; }
00218
00219 inline procLocation * calls() const { return _calls; }
00220
00221
00222
00223 bool is_present(const procNode * proc) const;
00224
00227 virtual void adjust_depth();
00228
00229
00230
00231 virtual void print(ostream & o) const;
00232 virtual void print_path(ostream & o) const;
00233
00234
00235
00236 virtual ~stmtLocation();
00237 };
00238
00239 typedef vector< stmtLocation > stmt_location_vec;
00240 typedef stmt_location_vec::iterator stmt_location_vec_p;
00241
00242
00243
00244
00245
00246 class basicblockLocation : public Location
00247 {
00248 friend class procLocation;
00249
00250 private:
00251
00252 basicblockNode * const _block;
00253 stmt_location_vec _statements;
00254
00255 public:
00256
00257 basicblockLocation(procLocation * parent,
00258 basicblockNode * block);
00259
00260
00261
00262 inline procLocation * proc_location() const { return (procLocation *) _parent; }
00263 inline basicblockNode * block() const { return _block; }
00264 inline stmt_location_vec & statements() { return _statements; }
00265
00268 stmtLocation * last() { return & _statements.back(); }
00269
00272 virtual void adjust_depth();
00273
00274
00275
00276 virtual void print(ostream & o) const;
00277 virtual void print_path(ostream & o) const;
00278
00279
00280
00281 virtual ~basicblockLocation();
00282 };
00283
00284 typedef map< basicblockNode *, basicblockLocation *,
00285 less< basicblockNode * >, basicblock_alloc > basicblock_location_map;
00286 typedef basicblock_location_map::iterator basicblock_location_map_p;
00287 typedef basicblock_location_map::const_iterator basicblock_location_map_cp;
00288
00289
00290
00291
00292
00293 class procLocation : public Location
00294 {
00295 private:
00296
00297 procNode * const _proc;
00298 basicblock_location_map _basicblocks;
00299
00300 static procLocation * Main;
00301
00302 public:
00303
00304 procLocation(stmtLocation * parent,
00305 procNode * proc,
00306 bool is_context_insensitive = false);
00307
00308
00309
00310 inline stmtLocation * stmt_location() const { return (stmtLocation *) _parent; }
00311 inline procNode * proc() const { return _proc; }
00312 basicblockLocation * lookup_block(basicblockNode * block) const;
00313 procLocation * parent_proc() const;
00314
00315 static inline procLocation * main() { return Main; }
00316
00317
00318
00319 stmtLocation * last();
00320
00326 void remove_from_tree();
00327
00330 virtual void adjust_depth();
00331
00332
00333
00334 virtual void print(ostream & o) const;
00335 virtual void print_path(ostream & o) const;
00336
00337
00338
00339 virtual ~procLocation();
00340 };
00341
00342 #endif // CBZ_LOCATION_H