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_LOCATION_H
00039 #define CBZ_LOCATION_H
00040
00041 #include "allocation.h"
00042 #include "dominators.h"
00043 #include "pointeroptions.h"
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
00082
00083 class procLocation;
00084 class basicblockLocation;
00085 class stmtLocation;
00086
00087 class Location : public PerClassHeap< PointersHeap >
00088 {
00089 public:
00090
00093 typedef enum { Statement, BasicBlock, Procedure } LocationKind;
00094
00097
00098 static unsigned int stmt_count;
00099 static unsigned int block_count;
00100 static unsigned int proc_count;
00101 static unsigned int dom_calls;
00102
00104
00105 private:
00106
00107 Location & operator=(const Location & other)
00108 {
00109 cerr << "ERROR: Cannot assign Location objects" << endl;
00110 return *this;
00111 }
00112
00113 protected:
00114
00123 Location * _parent;
00124
00129 unsigned int _kind:2;
00130
00131 #ifdef OLD_DOMINATOR_TEST
00132
00133 unsigned int _depth:9;
00134 unsigned int _dominates_exit:1;
00135 unsigned int _not_basicblock:1;
00136 unsigned int _not_procedure:1;
00137
00138 #endif
00139
00151 unsigned int _subtree_id:16;
00152
00155 static unsigned int current_subtree_id;
00156
00170 unsigned int _num_children:8;
00171
00178 Location * _dominator;
00179
00202
00203 unsigned int _tree_min;
00204 unsigned int _tree_max;
00205
00207
00210 static unsigned int current_tree_number;
00211
00216 static unsigned int next_tree_number()
00217 { current_tree_number++; return current_tree_number; }
00218
00219 public:
00220
00226 Location(Location * parent, LocationKind kind);
00227
00232
00233 inline Location * parent() const { return _parent; }
00234 inline LocationKind kind() const { return (LocationKind)_kind; }
00235
00236 #ifdef OLD_DOMINATOR_TEST
00237
00238 inline unsigned int depth() const { return _depth; }
00239 inline unsigned int dominates_exit() const { return _dominates_exit; }
00240
00241 #endif
00242
00243 inline unsigned int subtree_id() const { return _subtree_id; }
00244
00245 inline Location * dominator() const { return _dominator; }
00246 void set_dominator(Location * d);
00247 void clear_dominator();
00248
00249 inline int num_children() const { return _num_children; }
00250 inline void increment_children() { _num_children++; }
00251 inline void decrement_children() { _num_children--; }
00252
00253 inline unsigned int tree_min() const { return _tree_min; }
00254 inline void set_tree_min(unsigned int m) { _tree_min = m; }
00255
00256 inline unsigned int tree_max() const { return _tree_max; }
00257 inline void set_tree_max(unsigned int m) { _tree_max = m; }
00258
00260
00267 void visit();
00268
00278 void finish();
00279
00282 static bool dominates(const Location * dom, const Location * cur);
00283
00286 static bool strictly_dominates(const Location * dom, const Location * cur);
00287
00288 #ifdef OLD_DOMINATOR_TEST
00289
00292 static bool old_strictly_dominates(const Location * dom, const Location * cur);
00293
00296 static Location * common_parent(Location * one,
00297 Location * two);
00298
00299 #endif
00300
00303 static procLocation * procedure(Location * where);
00304
00307 static bool is_prefix(const Location * prefix, const Location * longer);
00308
00314 virtual void adjust_depth() = 0;
00315
00316
00317
00318 virtual void print(ostream & o) const = 0;
00319 virtual void print_path(ostream & o) const = 0;
00320
00321 friend ostream & operator<<(ostream & o, const Location & loc) {
00322 loc.print_path(o);
00323 return o;
00324 }
00325
00326
00327
00328 virtual ~Location();
00329
00330
00331
00332 static void stats();
00333 };
00334
00335
00336
00337
00338
00339 class stmtLocation : public Location
00340 {
00341 friend class basicblockLocation;
00342 friend class procLocation;
00343
00344 private:
00345
00346 unsigned int _stmt_num;
00347 stmtNode * _stmt;
00348 procLocation * _calls;
00349 map<procNode*,procLocation*> _all_calls;
00350
00351 inline void stmt_num(unsigned int num) { _stmt_num = num; }
00352 inline void stmt(stmtNode * s) { _stmt = s; }
00353
00354 public:
00355
00356 stmtLocation(basicblockLocation * parent);
00357
00364 void setup_cs_call(procNode * proc);
00365
00371 procLocation * remove_call();
00372
00375 inline basicblockLocation * block_location() const
00376 { return (basicblockLocation *) _parent; }
00377
00383 inline unsigned int stmt_num() const { return _stmt_num; }
00384
00387 inline stmtNode * stmt() const { return _stmt; }
00388
00394 inline procLocation * calls() const { return _calls; }
00395
00400 callNode * callnode();
00401
00402
00403
00404 bool is_present(const procNode * proc) const;
00405
00408 virtual void adjust_depth();
00409
00410
00411
00412 virtual void print(ostream & o) const;
00413 virtual void print_path(ostream & o) const;
00414 void print_callsite(ostream & o) const;
00415
00416
00417
00418 virtual ~stmtLocation();
00419 };
00420
00421 typedef vector< stmtLocation > stmt_location_vec;
00422 typedef stmt_location_vec::iterator stmt_location_vec_p;
00423
00424
00425
00426
00427
00428 class basicblockLocation : public Location
00429 {
00430 friend class procLocation;
00431
00432 private:
00433
00434 basicblockNode * const _block;
00435 stmt_location_vec _statements;
00436
00437 public:
00438
00439 basicblockLocation(procLocation * parent,
00440 basicblockNode * block);
00441
00442
00443
00444 inline procLocation * proc_location() const { return (procLocation *) _parent; }
00445 inline basicblockNode * block() const { return _block; }
00446 inline stmt_location_vec & statements() { return _statements; }
00447
00450 stmtLocation * last() { return & _statements.back(); }
00451
00454 virtual void adjust_depth();
00455
00456
00457
00458 virtual void print(ostream & o) const;
00459 virtual void print_path(ostream & o) const;
00460
00461
00462
00463 virtual ~basicblockLocation();
00464 };
00465
00466 #if defined(__MWERKS__) && !defined(CBZ_HEAPLAYERS)
00467 typedef map< basicblockNode *, basicblockLocation * > basicblock_location_map;
00468 #else
00469 typedef map< basicblockNode *, basicblockLocation *,
00470 less< basicblockNode * >, basicblock_alloc > basicblock_location_map;
00471 #endif
00472 typedef basicblock_location_map::iterator basicblock_location_map_p;
00473 typedef basicblock_location_map::const_iterator basicblock_location_map_cp;
00474
00475
00476
00477
00478
00479 class procLocation : public Location
00480 {
00481 private:
00482
00483 procNode * const _proc;
00484 basicblock_location_map _basicblocks;
00485
00486 static procLocation * Main;
00487
00488 public:
00489
00490 procLocation(stmtLocation * parent,
00491 procNode * proc,
00492 bool context_insensitive = false);
00493
00494
00495
00496 inline stmtLocation * stmt_location() const { return (stmtLocation *) _parent; }
00497 inline procNode * proc() const { return _proc; }
00498 basicblockLocation * lookup_block(basicblockNode * block) const;
00499 procLocation * parent_proc() const;
00500
00501 static inline procLocation * main() { return Main; }
00502
00503
00504
00505 stmtLocation * last();
00506
00512 void remove_from_tree();
00513
00516 virtual void adjust_depth();
00517
00518
00519
00520 virtual void print(ostream & o) const;
00521 virtual void print_path(ostream & o) const;
00522
00523
00524
00525 virtual ~procLocation();
00526 };
00527
00528 #endif // CBZ_LOCATION_H