00001 #ifndef _DD_GRAPH_H
00002 #define _DD_GRAPH_H
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 #define _DDG_TEST
00030
00031 #ifdef _DDG_TEST
00032 class DDgraphTester;
00033 #endif
00034
00035 #ifdef POLARIS_GNU_PRAGMAS
00036 #pragma interface
00037 #endif
00038
00039 #include <assert.h>
00040
00041 #include "Symbol/Symbol.h"
00042 #include "Statement/Statement.h"
00043 #include "StmtList.h"
00044 #include "Collection/List.h"
00045 #include "Collection/RefList.h"
00046 #include "Collection/Iterator.h"
00047 #include "Collection/Mutator.h"
00048 #include "Expression/Expression.h"
00049 #include "Expression/ArrayRefExpr.h"
00050 #include "Expression/IDExpr.h"
00051 #include "macros.h"
00052
00053 #include "ArcSpec.h"
00054
00055
00056 class Program;
00057 class DDgraph;
00058 class DDiterator;
00059
00060 typedef signed char Binary_flag;
00061
00062
00063
00064 enum DDtests_Seq {
00065
00066
00067
00068 _None,
00069 _GCD_Only,
00070 _Banerjee_Only,
00071 _Omega_Only,
00072 _GCD_Banerjee,
00073 _Banerjee_Omega,
00074 _GCD_Omega,
00075 _All
00076 };
00077
00078
00079 enum DDI_INIT_TYPE {
00080
00081
00082 _STMTS,
00083 _EXPR
00084 };
00085
00086 enum In_Out_refs {
00087
00088 _IN_REFS,
00089 _OUT_REFS
00090 };
00091
00092 enum First_Last {
00093
00094 _FIRST,
00095 _LAST
00096 };
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 class ElementDV : public Listable {
00107 private:
00108 DIREC_TYPE _direction;
00109 DDIST_TYPE _min_distance;
00110 DDIST_TYPE _max_distance;
00111 Boolean _distance_valid;
00112
00113
00114 public:
00115 inline ElementDV(DIREC_TYPE direc);
00116
00117 inline ElementDV(const ElementDV & other);
00118
00119 inline ElementDV(DIREC_TYPE direc, DDIST_TYPE const_distance);
00120
00121 inline ElementDV(DIREC_TYPE direc, DDIST_TYPE min, DDIST_TYPE max);
00122
00123 ~ElementDV();
00124
00125 inline DIREC_TYPE direction() const;
00126 inline void direction(DIREC_TYPE new_direc);
00127
00128
00129
00130 inline Boolean is_distance_valid ();
00131 inline void make_distance_valid ();
00132 inline Boolean is_distance_constant ();
00133
00134
00135 inline DDIST_TYPE distance ();
00136 inline void distance(DDIST_TYPE new_distance);
00137
00138 inline DDIST_TYPE min_distance ();
00139 inline void min_distance (DDIST_TYPE new_min_distance);
00140
00141 inline DDIST_TYPE max_distance ();
00142 inline void max_distance (DDIST_TYPE new_max_distance);
00143
00144 virtual Listable *listable_clone() const;
00145
00146
00147 virtual void print(ostream & o) const;
00148 };
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 class DVfield : public Listable {
00159 private:
00160 #ifdef _DDG_TEST
00161 friend class DDgraphTester;
00162 #endif
00163 friend class DDgraph;
00164
00165 int _references;
00166
00167
00168 Binary_flag _valid;
00169
00170
00171
00172 DEP_DECISION _dep_decided;
00173 DEP_TYPE _dep_type;
00174
00175 const Expression & _from_expr;
00176 const Expression & _to_expr;
00177
00178
00179 const Statement & _from_stmt;
00180 const Statement & _to_stmt;
00181
00182
00183 Expression *_label;
00184
00185 List<ElementDV>_dv;
00186
00187
00188 inline int references_inc();
00189 inline int references_dec();
00190
00191
00192
00193 inline void valid_on();
00194 inline void valid_off();
00195
00196
00197 public:
00198 inline DVfield(DEP_DECISION dep_decided, DEP_TYPE dep_type,
00199 const Statement & from_stmt, const Expression & from_expr,
00200 const Statement & to_stmt, const Expression & to_expr);
00201
00202 inline DVfield(const DVfield & other);
00203
00204 ~DVfield();
00205
00206 inline DEP_DECISION dep_decided();
00207 inline void dep_decided(DEP_DECISION new_ddecided);
00208
00209
00210 inline DEP_TYPE dep_type();
00211 inline void dep_type(DEP_TYPE new_dtype);
00212
00213
00214 inline const Expression & from_expr();
00215 inline const Expression & to_expr();
00216 inline const Statement & from_stmt();
00217 inline const Statement & to_stmt();
00218
00219
00220
00221
00222
00223
00224
00225 inline List<ElementDV>&dv();
00226
00227
00228
00229
00230
00231 inline void dv(List<ElementDV>&new_dv);
00232
00233
00234
00235
00236 Expression *label() { return _label; }
00237 void setLabel(Expression *label) { _label = label; }
00238
00239 virtual Listable *listable_clone() const;
00240
00241
00242 virtual void print(ostream & o) const ;
00243
00244 };
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 class ActiveArc : public Listable {
00260 private:
00261 #ifdef _DDG_TEST
00262 friend class DDgraphTester;
00263 #endif
00264 friend class DDgraph;
00265
00266 int _references;
00267
00268
00269
00270 Arc_type *_this_arc;
00271 Arc_type *_prev_arc;
00272 Arc_type *_next_arc;
00273
00274
00275
00276
00277 const Expression & _source_expr;
00278 const Expression & _target_expr;
00279
00280
00281
00282
00283
00284
00285
00286 const Statement & _source_stmt;
00287 const Statement & _target_stmt;
00288
00289
00290
00291 List<DVfield>*_original_dv_fields;
00292
00293
00294 List<DVfield>_working_dv_fields;
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 Expression *_label;
00306
00307
00308
00309
00310 public:
00311
00312
00313
00314
00315 inline ActiveArc(DDgraph & ddg, Arc_type * original_arc,
00316 Arc_type * prev_of_origin, Arc_type * next_of_origin,
00317 const Statement & src_stmt, const Expression & src_expr);
00318
00319 inline ActiveArc(const ActiveArc & other);
00320
00321 ~ActiveArc();
00322
00323 virtual void print(ostream & o) const;
00324
00325 virtual Listable *listable_clone() const;
00326
00327
00328
00329 Expression *label() { return _label; }
00330 void setLabel(Expression *label) { _label = label; }
00331
00332
00333
00334 };
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 class DDgraph {
00345 private:
00346 #ifdef _DDG_TEST
00347 friend class DDgraphTester;
00348 #endif
00349 friend class ActiveArc;
00350 friend class DDiterator;
00351
00352
00353 const int _ptr_size;
00354
00355 const int _tgt_expr_offset;
00356 const int _label_offset;
00357 const int _next_arc_offset;
00358 const int _data_field_offset;
00359
00360
00361 StmtList & _stmts;
00362
00363
00364 inline Arc_type *arcs_ptr(const Expression & src_expr);
00365
00366
00367
00368 List<ActiveArc>_active_arcs;
00369
00370
00371 inline void _clear_arc(Arc_type * arc, int bytes);
00372
00373 inline Binary_flag is_active(Arc_type * arc);
00374 inline void activate(Arc_type * arc);
00375 inline void deactivate(Arc_type * arc);
00376
00377
00378
00379
00380 inline Statement *target_stmt(Arc_type * arc) const;
00381 inline Expression *target_expr(Arc_type * arc) const;
00382 inline Expression *label_expr(Arc_type * arc) const;
00383 inline Arc_type *next_arc(Arc_type * arc) const;
00384 inline Arc_type *data_field(Arc_type * arc) const;
00385
00386
00387 inline void store_target_stmt(Arc_type * arc, const Statement & stmt);
00388 inline void store_target_expr(Arc_type * arc, const Expression & expr);
00389 inline void store_label_expr(Arc_type * arc, const Expression & expr);
00390 inline void store_next_arc(Arc_type * arc, Arc_type * next);
00391
00392
00393 Binary_flag is_new_dvfield(Arc_type * &arc_field, int &position);
00394 DEP_DECISION dep_decision(Arc_type * &arc_field, int &position);
00395 DEP_DIREC dep_direction(Arc_type * &arc_field, int &position);
00396 DEP_TYPE dep_type(Arc_type * &arc_field, int &position);
00397 DIREC_TYPE direction(Arc_type * &arc_field, int &position);
00398 DDIST_TYPE min_distance(Arc_type * &arc_field, int &position);
00399 DDIST_TYPE max_distance(Arc_type * &arc_field, int &position);
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415 inline DEP_DIREC test_dep_direction(Arc_type * arc_field, int offset);
00416
00417
00418
00419
00420 void mark_new_dvfield(Arc_type * &arc_field, int &position);
00421 void mark_arc_end(Arc_type * &arc_field, int &position);
00422 void store_dep_decision(Arc_type * &arc_field, int &position,
00423 DEP_DECISION ddeci);
00424 void store_dep_direction(Arc_type * &arc_field, int &position,
00425 DEP_DIREC ddirec);
00426 void store_dep_type(Arc_type * &arc_field, int &position,
00427 DEP_TYPE deptype);
00428 void store_direction(Arc_type * &arc_field, int &position,
00429 DIREC_TYPE direct);
00430 void store_min_distance(Arc_type * &arc_field, int &position,
00431 DDIST_TYPE min_dist);
00432 void store_max_distance(Arc_type * &arc_field, int &position,
00433 DDIST_TYPE min_dist);
00434 void store_const_distance(Arc_type * &arc_field, int &position,
00435 DDIST_TYPE const_dist);
00436
00437
00438
00439
00440
00441
00442 inline Arc_type _test_1bit_field(Arc_type * arc_field, int offset);
00443
00444
00445
00446
00447
00448
00449 inline void _skip_this_dvfield(Arc_type * &arc_field, int &position);
00450
00451
00452
00453
00454
00455
00456
00457 inline int _count_this_dvfield(Arc_type * &arc_field, int &position);
00458
00459
00460
00461
00462 void search_active_arcs_for(DVfield * &dvf, ActiveArc * &active_arc,
00463 First_Last fl, DEP_DIREC ddirec,
00464 const Expression & from_expr,
00465 const Expression & to_expr);
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477 void update_links_between(Arc_type * new_this, ActiveArc * active_arc);
00478
00479
00480 void write_back_arc(ActiveArc * active_arc);
00481
00482
00483
00484
00485
00486 void compute_dvf_n_arc(DVfield * &dvf, ActiveArc * &active_arc,
00487 First_Last fl,
00488 const Statement & from_stmt,
00489 const Expression & from_expr,
00490 const Statement & to_stmt,
00491 const Expression & to_expr);
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507 DVfield *prev(DVfield * dvf, ActiveArc * active_arc);
00508 DVfield *next(DVfield * dvf, ActiveArc * active_arc);
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 inline void exit(DVfield * dvf, ActiveArc * active_arc);
00520
00521
00522
00523
00524
00525
00526
00527
00528 void release(DVfield * dvf, ActiveArc * &active_arc);
00529 inline void hold(DVfield * dvf);
00530
00531
00532
00533
00534
00535
00536 inline void mark_dead(DVfield * dvf);
00537
00538
00539 inline Binary_flag is_alive(DVfield * dvf);
00540
00541
00542 inline Binary_flag is_shared(DVfield * dvf);
00543
00544
00545 inline DVfield *detach(DVfield * dvf, ActiveArc * active_arc);
00546
00547
00548 inline List<DVfield>*dvfield_list(ActiveArc * active_arc);
00549
00550
00551 void initialize_this_active_arc(ActiveArc * aarc, Arc_type * arc);
00552
00553
00554 public:
00555 inline DDgraph(StmtList & stmts);
00556
00557 inline ~DDgraph();
00558
00559 void add(List<DVfield>&dv_fields);
00560
00561
00562
00563
00564
00565
00566
00567 };
00568
00569 inline
00570 DDgraph::DDgraph(StmtList & stmts)
00571 : _ptr_size(sizeof(char *) * A_BYTE),
00572 _tgt_expr_offset(sizeof(char *)),
00573 _label_offset(sizeof(char *) * 2),
00574 _next_arc_offset(sizeof(char *) * 3),
00575 _data_field_offset(sizeof(char *) * 4),
00576 _stmts(stmts)
00577 {
00578 assert(sizeof(Arc_type) == 1 && sizeof(Binary_flag) == 1);
00579
00580 }
00581
00582 inline
00583 DDgraph::~DDgraph()
00584 {
00585
00586 }
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598 class DDiterator {
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608 private:
00609 #ifdef _DDG_TEST
00610 friend class DDgraphTester;
00611 #endif
00612 DDI_INIT_TYPE _init_from;
00613 DDI_INIT_TYPE _init_to;
00614
00615
00616
00617
00618
00619
00620 In_Out_refs _from_refs;
00621 In_Out_refs _to_refs;
00622
00623
00624 RefList<Statement> * _from_stmts;
00625 RefList<Statement> * _to_stmts;
00626
00627
00628
00629 Iterator<Statement>*_iter_from_stmts;
00630 Iterator<Statement>*_iter_to_stmts;
00631
00632
00633 Iterator<Expression>*_iter_from_exprs;
00634 Iterator<Expression>*_iter_to_exprs;
00635
00636
00637
00638 const Statement * _from_stmt;
00639 const Expression * _from_expr;
00640 const Statement * _to_stmt;
00641 const Expression * _to_expr;
00642
00643
00644 DVfield *_current_dvf;
00645
00646
00647
00648
00649 ActiveArc *_active_arc;
00650
00651
00652 DDgraph & _ddgraph;
00653
00654
00655
00656
00657
00658 void _next_in_STMTS_n_STMTS();
00659 void _next_in_STMTS_n_EXPR();
00660 void _next_in_EXPR_n_STMTS();
00661 void _prev_in_STMTS_n_STMTS();
00662 void _prev_in_STMTS_n_EXPR();
00663 void _prev_in_EXPR_n_STMTS();
00664
00665
00666
00667
00668
00669 public:
00670 DDiterator(RefList<Statement> * from_stmts, RefList<Statement> * to_stmts,
00671 DDgraph & ddgraph);
00672
00673
00674
00675
00676
00677 inline DDiterator(const Statement & from_stmt, const Expression & from_expr,
00678 const Statement & to_stmt, const Expression & to_expr,
00679 DDgraph & ddgraph);
00680
00681 DDiterator(RefList<Statement> * from_stmts,
00682 const Statement & to_stmt, const Expression & to_expr,
00683 DDgraph & ddgraph);
00684
00685 DDiterator(const Statement & from_stmt, const Expression & from_expr,
00686 RefList<Statement> * to_stmts, DDgraph & ddgraph);
00687
00688 DDiterator(const DDiterator & other);
00689
00690
00691
00692
00693 inline ~DDiterator();
00694
00695
00696 inline Boolean valid();
00697 inline Boolean end();
00698
00699
00700
00701
00702 inline DVfield & current();
00703
00704
00705
00706
00707
00708
00709 ActiveArc *current_arc() { return _active_arc; }
00710
00711
00712 inline Boolean current_valid();
00713 inline Boolean current_invalid();
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723 inline DVfield *grab();
00724
00725
00726
00727 inline void modify(DVfield * other);
00728
00729
00730
00731 inline void del();
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741 void reset();
00742 void set_to_last();
00743
00744
00745
00746
00747
00748
00749 void operator-- ();
00750
00751
00752
00753 void operator++ ();
00754
00755
00756 };
00757
00758
00759
00760
00761
00762
00763
00764 inline
00765 ElementDV::ElementDV(DIREC_TYPE direc)
00766 {
00767 _direction = direc;
00768 _distance_valid = False;
00769 _min_distance = INV_DDIST;
00770 _max_distance = INV_DDIST;
00771 }
00772
00773 inline
00774 ElementDV::ElementDV(DIREC_TYPE direc, DDIST_TYPE const_distance)
00775 {
00776 _direction = direc;
00777 _min_distance = const_distance;
00778 _max_distance = const_distance;
00779 _distance_valid = True;
00780 }
00781
00782 inline
00783 ElementDV::ElementDV(DIREC_TYPE direc, DDIST_TYPE min, DDIST_TYPE max)
00784 {
00785 _direction = direc;
00786 _min_distance = min;
00787 _max_distance = max;
00788 _distance_valid = True;
00789 }
00790
00791 inline
00792 ElementDV::ElementDV(const ElementDV & other)
00793 {
00794 _direction = other._direction;
00795 _min_distance = other._min_distance;
00796 _max_distance = other._max_distance;
00797 _distance_valid = other._distance_valid;
00798 }
00799
00800 inline DIREC_TYPE
00801 ElementDV::direction() const
00802 {
00803 return _direction;
00804 }
00805
00806 inline void
00807 ElementDV::direction(DIREC_TYPE new_direc)
00808 {
00809 _direction = new_direc;
00810 }
00811
00812 inline Boolean
00813 ElementDV::is_distance_valid ()
00814 {
00815
00816 return (_min_distance != INV_DDIST && _max_distance != INV_DDIST);
00817 }
00818
00819 inline void
00820 ElementDV::make_distance_valid ()
00821 {
00822 _distance_valid = True;
00823 }
00824
00825 inline Boolean
00826 ElementDV::is_distance_constant ()
00827 {
00828 return (_min_distance == _max_distance);
00829 }
00830
00831 inline DDIST_TYPE
00832 ElementDV::distance ()
00833 {
00834
00835 return(_min_distance);
00836 }
00837
00838 inline void
00839 ElementDV::distance(DDIST_TYPE new_distance)
00840 {
00841 _min_distance = new_distance;
00842 _max_distance = new_distance;
00843 _distance_valid = True;
00844 }
00845
00846 inline DDIST_TYPE
00847 ElementDV::min_distance ()
00848 {
00849 return(_min_distance);
00850 }
00851
00852 inline void
00853 ElementDV::min_distance (DDIST_TYPE new_min_distance)
00854 {
00855 _min_distance = new_min_distance;
00856 _distance_valid = True;
00857 }
00858
00859 inline DDIST_TYPE
00860 ElementDV::max_distance ()
00861 {
00862 return(_max_distance);
00863 }
00864
00865 inline void
00866 ElementDV::max_distance (DDIST_TYPE new_max_distance)
00867 {
00868 _max_distance = new_max_distance;
00869 _distance_valid = True;
00870 }
00871
00872 inline
00873 DVfield::DVfield(DEP_DECISION dep_decided, DEP_TYPE dep_type,
00874 const Statement & from_stmt, const Expression & from_expr,
00875 const Statement & to_stmt, const Expression & to_expr)
00876 : _from_expr(from_expr), _to_expr(to_expr),
00877 _from_stmt(from_stmt), _to_stmt(to_stmt), _label(NULL)
00878 {
00879 _dep_decided = dep_decided;
00880 _dep_type = dep_type;
00881 _valid = 1;
00882 _references = 0;
00883 }
00884
00885 inline
00886 DVfield::DVfield(const DVfield & other)
00887 : _from_expr(other._from_expr), _to_expr(other._to_expr),
00888 _from_stmt(other._from_stmt), _to_stmt(other._to_stmt)
00889 {
00890 _dep_decided = other._dep_decided;
00891 _dep_type = other._dep_type;
00892 _valid = other._valid;
00893 _references = other._references;
00894 if(other._label != NULL) _label = other._label->clone();
00895 else _label = NULL;
00896 }
00897
00898 inline int
00899 DVfield::references_inc()
00900 {
00901 return ++_references;
00902 }
00903
00904
00905 inline int
00906 DVfield::references_dec()
00907 {
00908 return --_references;
00909 }
00910
00911 inline void
00912 DVfield::valid_on()
00913 {
00914 _valid = 1;
00915 }
00916
00917 inline void
00918 DVfield::valid_off()
00919 {
00920 _valid = 0;
00921 }
00922
00923 inline DEP_DECISION
00924 DVfield::dep_decided()
00925 {
00926 return _dep_decided;
00927 }
00928
00929 inline void
00930 DVfield::dep_decided(DEP_DECISION new_ddecided)
00931 {
00932 _dep_decided = new_ddecided;
00933 }
00934
00935 inline DEP_TYPE
00936 DVfield::dep_type()
00937 {
00938 return _dep_type;
00939 }
00940
00941 inline void
00942 DVfield::dep_type(DEP_TYPE new_dtype)
00943 {
00944 _dep_type = new_dtype;
00945 }
00946
00947 inline const Expression &
00948 DVfield::from_expr()
00949 {
00950 return _from_expr;
00951 }
00952
00953 inline const Expression &
00954 DVfield::to_expr()
00955 {
00956 return _to_expr;
00957 }
00958
00959 inline const Statement &
00960 DVfield::from_stmt()
00961 {
00962 return _from_stmt;
00963 }
00964
00965 inline const Statement &
00966 DVfield::to_stmt()
00967 {
00968 return _to_stmt;
00969 }
00970
00971 inline List<ElementDV> &
00972 DVfield::dv()
00973 {
00974 return _dv;
00975 }
00976
00977 inline void
00978 DVfield::dv(List<ElementDV>&new_dv)
00979 {
00980 Iterator<ElementDV> iter = new_dv;
00981
00982 for (; iter.valid(); ++iter)
00983 _dv.ins_last(new ElementDV(iter.current()));
00984 }
00985
00986
00987
00988 inline
00989 ActiveArc::ActiveArc(DDgraph & ddg, Arc_type * arc,
00990 Arc_type * prev, Arc_type * next,
00991 const Statement & src_stmt, const Expression & src_expr)
00992 : _this_arc(arc), _prev_arc(prev), _next_arc(next),
00993 _source_expr(src_expr), _target_expr(*ddg.target_expr(arc)),
00994 _source_stmt(src_stmt), _target_stmt(*ddg.target_stmt(arc))
00995 {
00996 ddg.initialize_this_active_arc(this, arc);
00997
00998 _label = ddg.label_expr(arc);
00999
01000 }
01001
01002 inline
01003 ActiveArc::ActiveArc(const ActiveArc & other)
01004 : _source_expr(other._source_expr), _target_expr(other._target_expr),
01005 _source_stmt(other._source_stmt), _target_stmt(other._target_stmt)
01006 {
01007 _this_arc = other._this_arc;
01008 _prev_arc = other._prev_arc;
01009 _next_arc = other._next_arc;
01010
01011 _label = (other._label != NULL) ? other._label->clone() : NULL;
01012
01013 }
01014
01015
01016
01017 inline Arc_type *
01018 DDgraph::arcs_ptr(const Expression & src_expr)
01019 {
01020 switch (src_expr.op()) {
01021 case ID_OP:
01022 return ((IDExpr &) src_expr)._arcs;
01023
01024 case ARRAY_REF_OP:
01025 return ((ArrayRefExpr &) src_expr)._arcs;
01026
01027 default:
01028 return NULL;
01029 }
01030 }
01031
01032 inline void
01033 DDgraph::_clear_arc(Arc_type * arc, int bytes)
01034 {
01035 while (bytes-- > 0)
01036 arc[bytes] = '\0';
01037 }
01038
01039 inline Binary_flag
01040 DDgraph::is_active(Arc_type * arc)
01041 {
01042 return (Binary_flag) (*(arc + _data_field_offset) & ARC_ACTIVE);
01043 }
01044
01045 inline void
01046 DDgraph::activate(Arc_type * arc)
01047 {
01048 *(arc + _data_field_offset) |= ARC_ACTIVE;
01049 }
01050
01051 inline void
01052 DDgraph::deactivate(Arc_type * arc)
01053 {
01054 *(arc + _data_field_offset) &= ~ARC_ACTIVE;
01055 }
01056
01057 inline Statement *
01058 DDgraph::target_stmt(Arc_type * arc) const
01059 {
01060 return *(Statement **) arc;
01061 }
01062
01063 inline Expression *
01064 DDgraph::target_expr(Arc_type * arc) const
01065 {
01066 return *(Expression **) (arc + _tgt_expr_offset);
01067 }
01068
01069 inline Expression *
01070 DDgraph::label_expr(Arc_type * arc) const
01071 {
01072 return *(Expression **) (arc + _label_offset);
01073 }
01074
01075 inline Arc_type *
01076 DDgraph::next_arc(Arc_type * arc) const
01077 {
01078 return *(Arc_type **) (arc + _next_arc_offset);
01079 }
01080
01081 inline Arc_type *
01082 DDgraph::data_field(Arc_type * arc) const
01083 {
01084 return arc + _data_field_offset;
01085 }
01086
01087 inline void
01088 DDgraph::store_target_stmt(Arc_type * arc, const Statement & stmt)
01089 {
01090 *(Statement **) arc = (Statement *) &stmt;
01091 }
01092
01093 inline void
01094 DDgraph::store_target_expr(Arc_type * arc, const Expression & expr)
01095 {
01096 *(Expression **) (arc + _tgt_expr_offset) = (Expression *) &expr;
01097 }
01098
01099 inline void
01100 DDgraph::store_label_expr(Arc_type * arc, const Expression & expr)
01101 {
01102 *(Expression **) (arc + _label_offset) = (Expression *) &expr;
01103 }
01104
01105 inline void
01106 DDgraph::store_next_arc(Arc_type * arc, Arc_type * next)
01107 {
01108 *(Arc_type **) (arc + _next_arc_offset) = next;
01109 }
01110
01111 inline DEP_DIREC
01112 DDgraph::test_dep_direction(Arc_type * arc_field, int offset)
01113 {
01114 return (DEP_DIREC) _test_1bit_field(arc_field, offset);
01115 }
01116
01117 inline Arc_type
01118 DDgraph::_test_1bit_field(Arc_type * arc_field, int offset)
01119 {
01120 if (offset >= A_BYTE)
01121 return arc_field[offset / A_BYTE] << offset % A_BYTE & ARC_1_BIT;
01122
01123 return *arc_field << offset & ARC_1_BIT;
01124 }
01125
01126 inline void
01127 DDgraph::_skip_this_dvfield(Arc_type * &arc_field, int &position)
01128 {
01129 if ((position += DVF_DIREC) >= A_BYTE) {
01130 position -= A_BYTE;
01131 ++arc_field;
01132 }
01133
01134 while (_DELIM != direction(arc_field, position)) {
01135 DDIST_TYPE t = min_distance(arc_field, position);
01136 t = max_distance(arc_field, position);
01137
01138 }
01139 }
01140
01141 inline int
01142 DDgraph::_count_this_dvfield(Arc_type * &arc_field, int &position)
01143 {
01144 int bits = CONST_BITS;
01145
01146 if ((position += DVF_DIREC) >= A_BYTE) {
01147 position -= A_BYTE;
01148 ++arc_field;
01149 }
01150
01151 while (_DELIM != direction(arc_field, position)) {
01152 bits += (THREE_BIT + EIGHT_BIT + EIGHT_BIT);
01153 DDIST_TYPE t = min_distance(arc_field, position);
01154 t = max_distance(arc_field, position);
01155 }
01156
01157 return bits;
01158 }
01159
01160
01161 inline void
01162 DDgraph::exit(DVfield * dvf, ActiveArc * active_arc)
01163 {
01164 release(dvf, active_arc);
01165
01166
01167
01168 if (active_arc && !--active_arc->_references) {
01169
01170 write_back_arc(active_arc);
01171 }
01172 }
01173
01174 inline void
01175 DDgraph::hold(DVfield * dvf)
01176 {
01177 dvf->references_inc();
01178 }
01179
01180 inline void
01181 DDgraph::mark_dead(DVfield * dvf)
01182 {
01183 dvf->valid_off();
01184 }
01185
01186 inline Binary_flag
01187 DDgraph::is_alive(DVfield * dvf)
01188 {
01189 return dvf->_valid;
01190 }
01191
01192 inline Binary_flag
01193 DDgraph::is_shared(DVfield * dvf)
01194 {
01195 return (dvf->_references>1);
01196 }
01197
01198 inline DVfield *
01199 DDgraph::detach(DVfield * dvf, ActiveArc * active_arc)
01200 {
01201 return active_arc->_working_dv_fields.grab(*dvf);
01202 }
01203
01204 inline List<DVfield> *
01205 DDgraph::dvfield_list(ActiveArc * active_arc)
01206 {
01207 return &active_arc->_working_dv_fields;
01208 }
01209
01210
01211
01212 inline
01213 DDiterator::DDiterator(const Statement & from_stmt,
01214 const Expression & from_expr,
01215 const Statement & to_stmt, const Expression & to_expr,
01216 DDgraph & ddgraph)
01217 : _ddgraph(ddgraph)
01218 {
01219 _from_stmt = &from_stmt;
01220 _to_stmt = &to_stmt;
01221 _from_expr = &from_expr;
01222 _to_expr = &to_expr;
01223 _init_from = _init_to = _EXPR;
01224
01225 _ddgraph.compute_dvf_n_arc(_current_dvf, _active_arc, _FIRST,
01226 from_stmt, from_expr, to_stmt, to_expr);
01227 }
01228
01229 inline
01230 DDiterator::~DDiterator()
01231 {
01232 if (_current_dvf && _active_arc)
01233 _ddgraph.exit(_current_dvf, _active_arc);
01234
01235 if (_init_from == _STMTS) {
01236 delete _iter_from_stmts;
01237 delete _iter_from_exprs;
01238 delete _from_stmts;
01239 }
01240
01241 if (_init_to == _STMTS) {
01242 delete _iter_to_stmts;
01243 delete _iter_to_exprs;
01244 delete _to_stmts;
01245 }
01246 }
01247
01248 inline Boolean
01249 DDiterator::valid()
01250 {
01251 return (_current_dvf ? True : False);
01252 }
01253
01254 inline Boolean
01255 DDiterator::end()
01256 {
01257 return !valid();
01258 }
01259
01260 inline DVfield &
01261 DDiterator::current()
01262 {
01263 p_assert(current_valid(), "Try to access a dead object");
01264
01265 return *_current_dvf;
01266 }
01267
01268 inline Boolean
01269 DDiterator::current_valid()
01270 {
01271 return ((_current_dvf && _ddgraph.is_alive(_current_dvf) ) ? True : False);
01272 }
01273
01274 inline Boolean
01275 DDiterator::current_invalid()
01276 {
01277 return !current_valid();
01278 }
01279
01280 inline DVfield *
01281 DDiterator::grab()
01282 {
01283 p_assert(current_valid(), "Try to grab a dead object");
01284
01285 _ddgraph.mark_dead(_current_dvf);
01286
01287 DVfield * dvf = (DVfield *) _current_dvf->listable_clone();
01288
01289
01290
01291
01292
01293
01294
01295
01296 Iterator<ElementDV> iter = _current_dvf->dv();
01297 for (; iter.valid(); ++iter)
01298 dvf->dv().ins_last(new ElementDV(iter.current()));
01299
01300 return dvf;
01301 }
01302
01303
01304 inline void
01305 DDiterator::del()
01306 {
01307 p_assert(current_valid(), "Try to delete a dead object");
01308
01309 _ddgraph.mark_dead(_current_dvf);
01310 }
01311
01312 inline void
01313 DDiterator::modify(DVfield * other)
01314 {
01315 p_assert(current_valid(), "Try to modify a dead object");
01316
01317 _ddgraph.mark_dead(_current_dvf);
01318 _ddgraph.dvfield_list(_active_arc)->ins_after(other, _current_dvf);
01319 _ddgraph.release(_current_dvf, _active_arc);
01320 _ddgraph.hold(other);
01321 _current_dvf = other;
01322 }
01323
01324
01325
01326
01327
01328 struct DVcapsule {
01329 DVfield * dvf;
01330 DVcapsule * next;
01331 Binary_flag alive;
01332
01333 DVcapsule(DVfield * dvf_ptr) {
01334 dvf = dvf_ptr;
01335 next = 0;
01336 alive = 1;
01337 }
01338
01339 Binary_flag is_alive() {
01340 return alive;
01341 }
01342
01343 void mark_dead() {
01344 alive = 0;
01345 }
01346 };
01347
01348
01349
01350
01351
01352
01353 void merge_DVs(List<DVfield> & dvfs);
01354
01355
01356
01357
01358 void _dispose_capsules(DVcapsule *& dvc);
01359
01360
01361
01362
01363
01364 void _remove_all_subdirections(DVcapsule ** Slots, int levels);
01365
01366
01367
01368
01369
01370
01371 DVcapsule * _create_parent(DVcapsule *& Slot,DVcapsule * dvc,DVcapsule * list);
01372
01373
01374
01375
01376
01377 Binary_flag _is_parent_for(Iterator<ElementDV> & citer,
01378 Iterator<ElementDV> & piter);
01379
01380 inline Binary_flag _is_same(Iterator<ElementDV> & iter1,
01381 Iterator<ElementDV> & iter2);
01382
01383 Binary_flag _is_subdirecion(Iterator<ElementDV> & iter1,
01384 Iterator<ElementDV> & iter2);
01385
01386
01387 inline Binary_flag _is_same(Iterator<ElementDV> & iter1,
01388 Iterator<ElementDV> & iter2)
01389 {
01390 iter1.reset();
01391 iter2.reset();
01392
01393 for (; iter1.valid() && iter2.valid(); ++iter1, ++iter2)
01394 if (iter1.current().direction() != iter2.current().direction())
01395 return 0;
01396
01397 if (iter1.end() && iter2.end())
01398 return 1;
01399 else
01400 return 0;
01401 }
01402
01403 void
01404 ddtests_main(Program&, DDtests_Seq, Binary_flag);
01405
01406 #endif