00001 #include "define.h"
00002
00003 #ifdef POLARIS_GNU_PRAGMAS
00004 #pragma implementation
00005 #endif
00006
00007 #include "DDgraph.h"
00008
00009 template class TypedCollection<ActiveArc>;
00010 template class List<ActiveArc>;
00011 template ostream & operator << (ostream &, const List<ActiveArc> &);
00012 template class Iterator<ActiveArc>;
00013 template class Assign<ActiveArc>;
00014
00015 template class TypedCollection<DVfield>;
00016 template class List<DVfield>;
00017 template ostream & operator << (ostream &, const List<DVfield> &);
00018 template class Iterator<DVfield>;
00019 template class Mutator<DVfield>;
00020 template class Assign<DVfield>;
00021
00022 template class TypedCollection<ElementDV>;
00023 template class List<ElementDV>;
00024 template ostream & operator << (ostream &, const List<ElementDV> &);
00025 template class Iterator<ElementDV>;
00026 template class Assign<ElementDV>;
00027
00028 template class TypedCollection<List<ElementDV> >;
00029 template class List<List<ElementDV> >;
00030 template ostream & operator << (ostream &, const List<List<ElementDV> > &);
00031 template class Assign<List<ElementDV> >;
00032 template class Iterator<List<ElementDV> >;
00033 template class Mutator<List<ElementDV> >;
00034
00035 template class TypedCollection< List<DVfield> >;
00036 template class List< List<DVfield> >;
00037 template ostream & operator << (ostream &, const List< List<DVfield> > &);
00038 template class Iterator< List<DVfield> >;
00039 template class Mutator< List<DVfield> >;
00040 template class Assign< List<DVfield> >;
00041
00042 #define _SLOT(stars, combos) 2 * stars + combos
00043
00044
00045
00046
00047 void
00048 merge_DVs(List<DVfield> & dvfs)
00049 {
00050 List<DVfield> original_dvfs;
00051 List<DVfield> work_dvfs;
00052
00053 Mutator<DVfield> copy_iter = dvfs;
00054
00055 for (; copy_iter.valid(); ++copy_iter)
00056 original_dvfs.ins_last(copy_iter.grab());
00057
00058
00059
00060 Mutator<DVfield> iter = original_dvfs;
00061
00062 for(; iter.valid(); iter.reset()) {
00063
00064 DVfield * dvf = iter.grab();
00065
00066 work_dvfs.ins_first(dvf);
00067 for (++iter; iter.valid(); ++iter)
00068 if (dvf->dv().entries() == iter.current().dv().entries() &&
00069 dvf->dep_decided() == iter.current().dep_decided() &&
00070 dvf->dep_type() == iter.current().dep_type() &&
00071 &dvf->from_expr() == &iter.current().from_expr() &&
00072 &dvf->to_expr() == &iter.current().to_expr())
00073 work_dvfs.ins_last(iter.grab());
00074
00075
00076
00077
00078 int levels = dvf->dv().entries() * 2;
00079 DVcapsule **Slots = new DVcapsule* [levels + 1];
00080
00081
00082 int i;
00083 for (i = 0; i <= levels; i++)
00084 Slots[i] = 0;
00085
00086 Mutator<DVfield> diter = work_dvfs;
00087
00088
00089
00090
00091 for (; diter.valid(); ++diter) {
00092
00093 Iterator<ElementDV> eiter = diter.current().dv();
00094 int num_of_stars = 0;
00095 int num_of_combos = 0;
00096
00097 for (; eiter.valid(); ++eiter)
00098 switch (eiter.current().direction()) {
00099 case _STAR:
00100 num_of_stars++;
00101 break;
00102 case _LE:
00103 case _GE:
00104 case _NEQ:
00105 num_of_combos++;
00106 default: break;
00107 }
00108
00109 int slot = _SLOT(num_of_stars, num_of_combos);
00110 DVcapsule * dvc = Slots[slot];
00111 Slots[slot] = new DVcapsule(diter.grab());
00112 Slots[slot]->next = dvc;
00113 }
00114
00115 if (Slots[levels]) {
00116
00117 dvfs.ins_last(Slots[levels]->dvf);
00118 Slots[levels]->dvf = 0;
00119
00120 for (; levels >= 0; levels--)
00121 _dispose_capsules(Slots[levels]);
00122 continue;
00123 }
00124
00125
00126
00127 _remove_all_subdirections(Slots, levels);
00128
00129
00130
00131
00132 DVcapsule * dvc;
00133
00134 for (i = 0; i < levels; ++i) {
00135 for ( dvc = Slots[i]; dvc; dvc = dvc->next) {
00136
00137 DVcapsule * compensatory =
00138 _create_parent(Slots[i + 1], dvc, dvc->next);
00139
00140 if (compensatory && dvc->is_alive())
00141 dvc->mark_dead();
00142
00143 while (compensatory) {
00144 compensatory->mark_dead();
00145 compensatory =
00146 _create_parent(Slots[i + 1], dvc, compensatory->next);
00147 }
00148 }
00149
00150
00151
00152 DVcapsule * prev = 0;
00153 dvc = Slots[i];
00154
00155 while (dvc)
00156 if (dvc->is_alive()) {
00157 prev = dvc;
00158 dvc = dvc->next;
00159 }
00160 else {
00161 delete dvc->dvf;
00162 if (prev) {
00163 prev->next = dvc->next;
00164 delete dvc;
00165 dvc = prev->next;
00166 }
00167 else {
00168 Slots[i] = dvc->next;
00169 delete dvc;
00170 dvc = Slots[i];
00171 }
00172 }
00173 }
00174
00175
00176
00177 for (i = 1; i < levels; i++) {
00178 for ( dvc = Slots[i]; dvc; dvc = dvc->next) {
00179
00180 DVcapsule * compensatory =
00181 _create_parent(Slots[i + 1], dvc, Slots[i - 1]);
00182
00183 if (compensatory && dvc->is_alive())
00184 dvc->mark_dead();
00185
00186 while (compensatory) {
00187 compensatory->mark_dead();
00188 compensatory =
00189 _create_parent(Slots[i + 1], dvc, compensatory->next);
00190 }
00191 }
00192
00193
00194
00195 DVcapsule * prev = 0;
00196 dvc = Slots[i];
00197
00198 while (dvc)
00199 if (dvc->is_alive()) {
00200 prev = dvc;
00201 dvc = dvc->next;
00202 }
00203 else {
00204 delete dvc->dvf;
00205 if (prev) {
00206 prev->next = dvc->next;
00207 delete dvc;
00208 dvc = prev->next;
00209 }
00210 else {
00211 Slots[i] = dvc->next;
00212 delete dvc;
00213 dvc = Slots[i];
00214 }
00215 }
00216 }
00217
00218
00219
00220 _remove_all_subdirections(Slots, levels);
00221
00222
00223
00224 for (i = 0; i < levels; i++)
00225 for (dvc = Slots[i]; dvc; dvc = dvc->next) {
00226 dvfs.ins_last(dvc->dvf);
00227 dvc->dvf = 0;
00228 }
00229
00230
00231
00232
00233 for (i = 0; i < levels; i++)
00234 _dispose_capsules(Slots[i]);
00235 delete[] Slots;
00236 }
00237 }
00238
00239
00240 void
00241 _dispose_capsules(DVcapsule *& dvc)
00242 {
00243 if (dvc) {
00244 _dispose_capsules(dvc->next);
00245 delete dvc->dvf;
00246 delete dvc;
00247 dvc = 0;
00248 }
00249 }
00250
00251
00252 DVcapsule *
00253 _create_parent(DVcapsule *& Slot, DVcapsule * dvc, DVcapsule * list)
00254 {
00255 Iterator<ElementDV> iter = dvc->dvf->dv();
00256 ElementDV * new_dir = 0;
00257
00258 for (; list; iter.reset(), list = list->next) {
00259
00260 Iterator<ElementDV> riter = list->dvf->dv();
00261 Binary_flag all_the_same = 1;
00262 int loc_count = 0;
00263
00264 for (; riter.valid() && iter.valid(); ++iter, ++riter) {
00265
00266 if (iter.current().direction() != riter.current().direction()) {
00267
00268 if (all_the_same)
00269 all_the_same = 0;
00270 else
00271 break;
00272
00273 switch (iter.current().direction()) {
00274 case _LT:
00275 if (riter.current().direction() == _GT)
00276 new_dir = new ElementDV(_NEQ);
00277 else if (riter.current().direction() == _EQ)
00278 new_dir = new ElementDV(_LE);
00279 break;
00280 case _GT:
00281 if (riter.current().direction() == _LT)
00282 new_dir = new ElementDV(_NEQ);
00283 else if (riter.current().direction() == _EQ)
00284 new_dir = new ElementDV(_GE);
00285 break;
00286 case _EQ:
00287 if (riter.current().direction() == _GT)
00288 new_dir = new ElementDV(_GE);
00289 else if (riter.current().direction() == _LT)
00290 new_dir = new ElementDV(_LE);
00291 break;
00292 case _LE:
00293 if (riter.current().direction() == _GE ||
00294 riter.current().direction() == _NEQ ||
00295 riter.current().direction() == _GT)
00296 new_dir = new ElementDV(_STAR);
00297 break;
00298 case _GE:
00299 if (riter.current().direction() == _LE ||
00300 riter.current().direction() == _NEQ ||
00301 riter.current().direction() == _LT)
00302 new_dir = new ElementDV(_STAR);
00303 break;
00304 case _NEQ:
00305 if (riter.current().direction() == _GE ||
00306 riter.current().direction() == _LE ||
00307 riter.current().direction() == _EQ)
00308 new_dir = new ElementDV(_STAR);
00309 default: break;
00310 }
00311
00312 if (!new_dir)
00313 break;
00314 }
00315
00316 if (all_the_same)
00317 loc_count++;
00318 }
00319
00320 if (new_dir && riter.end() && iter.end()) {
00321
00322
00323
00324 DVfield * dvf = (DVfield *) dvc->dvf->listable_clone();
00325
00326
00327
00328
00329
00330
00331 List<ElementDV> & dv = dvf->dv();
00332
00333 int i = 0;
00334 for (iter.reset(); iter.valid(); ++iter, ++i)
00335 if (i == loc_count)
00336 dv.ins_last(new_dir);
00337 else
00338 dv.ins_last(new ElementDV(iter.current().direction()));
00339
00340
00341
00342 Iterator<ElementDV> new_iter = dv;
00343
00344 DVcapsule * search;
00345
00346 for ( search = Slot; search; search = search->next) {
00347
00348 Iterator<ElementDV> siter = search->dvf->dv();
00349
00350 for (; new_iter.valid() && siter.valid(); ++new_iter, ++siter)
00351 if (new_iter.current().direction() != siter.current().direction())
00352 break;
00353
00354 if (new_iter.end() && siter.end())
00355 break;
00356
00357 new_iter.reset();
00358 }
00359
00360 if (search)
00361 delete dvf;
00362 else {
00363 DVcapsule * temp = Slot;
00364 Slot = new DVcapsule(dvf);
00365 Slot->next = temp;
00366 }
00367
00368 return list;
00369 }
00370 }
00371
00372 return 0;
00373 }
00374
00375
00376 Binary_flag
00377 _is_subdirecion(Iterator<ElementDV> & iter1, Iterator<ElementDV> & iter2)
00378 {
00379 iter1.reset();
00380 iter2.reset();
00381
00382 for (; iter1.valid() && iter2.valid(); ++iter1, ++iter2)
00383 switch (iter2.current().direction()) {
00384 case _LT:
00385 if (iter1.current().direction() != _LT)
00386 return 0;
00387 break;
00388 case _GT:
00389 if (iter1.current().direction() != _GT)
00390 return 0;
00391 break;
00392 case _EQ:
00393 if (iter1.current().direction() != _EQ)
00394 return 0;
00395 break;
00396 case _LE:
00397 if (iter1.current().direction() != _LT &&
00398 iter1.current().direction() != _EQ &&
00399 iter1.current().direction() != _LE)
00400 return 0;
00401 break;
00402 case _GE:
00403 if (iter1.current().direction() != _GT &&
00404 iter1.current().direction() != _EQ &&
00405 iter1.current().direction() != _GE)
00406 return 0;
00407 break;
00408 case _NEQ:
00409 if (iter1.current().direction() != _GT &&
00410 iter1.current().direction() != _LT &&
00411 iter1.current().direction() != _NEQ)
00412 return 0;
00413 default: break;
00414 }
00415
00416 if (iter1.end() && iter2.end())
00417 return 1;
00418 else
00419 return 0;
00420 }
00421
00422
00423 Binary_flag
00424 _is_parent_for(Iterator<ElementDV> & citer, Iterator<ElementDV> & piter)
00425 {
00426 int how_many_cover = 0;
00427
00428 citer.reset();
00429 piter.reset();
00430
00431 for (; citer.valid() && piter.valid(); ++citer, ++piter)
00432 switch (piter.current().direction()) {
00433 case _LT:
00434 if (citer.current().direction() != _LT)
00435 return 0;
00436 break;
00437 case _GT:
00438 if (citer.current().direction() != _GT)
00439 return 0;
00440 break;
00441 case _EQ:
00442 if (citer.current().direction() != _EQ)
00443 return 0;
00444 break;
00445 case _LE:
00446 if (citer.current().direction() != _LT &&
00447 citer.current().direction() != _EQ)
00448 return 0;
00449 how_many_cover++;
00450 break;
00451 case _GE:
00452 if (citer.current().direction() != _GT &&
00453 citer.current().direction() != _EQ)
00454 return 0;
00455 how_many_cover++;
00456 break;
00457 case _NEQ:
00458 if (citer.current().direction() != _LT &&
00459 citer.current().direction() != _GT)
00460 return 0;
00461 how_many_cover++;
00462 break;
00463 default:
00464 if (citer.current().direction() != _STAR)
00465 how_many_cover++;
00466 }
00467
00468 if (citer.end() && piter.end() && how_many_cover == 1)
00469 return 1;
00470 else
00471 return 0;
00472 }
00473
00474
00475 void
00476 _remove_all_subdirections(DVcapsule ** Slots, int levels)
00477 {
00478 for (int i = levels - 1; i >= 0; i--)
00479 for (DVcapsule * dvc = Slots[i]; dvc; dvc = dvc->next) {
00480
00481
00482
00483 Iterator<ElementDV> eiter = dvc->dvf->dv();
00484 DVcapsule * prev = dvc;
00485 DVcapsule * c = dvc->next;
00486
00487 while (c) {
00488
00489 Iterator<ElementDV> citer = c->dvf->dv();
00490
00491 if (_is_same(citer, eiter)) {
00492 prev->next = c->next;
00493 delete c->dvf;
00494 delete c;
00495 c = prev->next;
00496 }
00497 else {
00498 prev = c;
00499 c = c->next;
00500 }
00501 }
00502
00503 for (int j = i - 1; j >= 0; j--) {
00504
00505 prev = 0;
00506 c = Slots[j];
00507
00508 while (c) {
00509
00510 Iterator<ElementDV> citer = c->dvf->dv();
00511
00512 if (_is_subdirecion(citer, eiter)) {
00513 delete c->dvf;
00514 if (prev) {
00515 prev->next = c->next;
00516 delete c;
00517 c = prev->next;
00518 }
00519 else {
00520 Slots[j] = c->next;
00521 delete c;
00522 c = Slots[j];
00523 }
00524 }
00525 else {
00526 prev = c;
00527 c = c->next;
00528 }
00529 }
00530 }
00531 }
00532 }
00533
00534
00535 #define _MY_DDG_DEBUG
00536
00537 ElementDV::~ElementDV()
00538 {
00539
00540 }
00541
00542 Listable *
00543 ElementDV::listable_clone() const
00544 {
00545 return new ElementDV(*this);
00546 }
00547
00548 void
00549 ElementDV::print(ostream & o) const {
00550
00551 char *dir = NULL;
00552
00553 #ifdef _MY_DDG_DEBUG
00554 switch (_direction) {
00555 case _STAR: dir = "* "; break;
00556 case _LT: dir = "< "; break;
00557 case _GT: dir = "> "; break;
00558 case _LE: dir = "<="; break;
00559 case _GE: dir = ">="; break;
00560 case _NEQ: dir = "<>"; break;
00561 case _EQ: dir = "= ";
00562 default: break;
00563 }
00564
00565 o << ' ' << dir ;
00566 #endif
00567 Boolean dist_valid = _distance_valid;
00568 if ((_min_distance == INV_DDIST) && (_max_distance == INV_DDIST))
00569 dist_valid = False;
00570
00571 if (dist_valid) {
00572 int min, max;
00573
00574 min = (int) _min_distance;
00575 max = (int) _max_distance;
00576
00577 if (_min_distance == _max_distance) {
00578 o << "D=" << min;
00579 }
00580 else {
00581 o << "D=[";
00582 if (_min_distance == INV_DDIST) o << "invalid";
00583 else o << min;
00584 o << ",";
00585 if (_max_distance == INV_DDIST) o << "invalid";
00586 else o << max;
00587 o << "] ";
00588 }
00589 }
00590 else o << " D=[invalid]";
00591 }
00592
00593 DVfield::~DVfield()
00594 {
00595
00596 if(_label) delete _label; _label = NULL;
00597 }
00598
00599 Listable *
00600 DVfield::listable_clone() const
00601 {
00602 return new DVfield(*this);
00603 }
00604
00605 void
00606 DVfield::print(ostream & o) const {
00607
00608 #ifdef _MY_DDG_DEBUG
00609 o << " /// ... DVF ref(" << _references << ")v(" << (int) _valid;
00610 switch (_dep_decided) {
00611 case _ASSUMED: o << ")as,"; break;
00612 case _PROVED: o << ")pv,";
00613 default: break;
00614 }
00615
00616 switch (_dep_type) {
00617 case _FLOW: o << "f,"; break;
00618 case _ANTI: o << "a,"; break;
00619 case _INPUT: o << "i,"; break;
00620 case _OUTPUT: o << "o,"; break;
00621 case _UNKNOWN: o << "u,";
00622 }
00623
00624 o << "f_e:";
00625 _from_expr.print(o);
00626 o << "t_e:";
00627 _to_expr.print(o);
00628
00629 for (Iterator<ElementDV> iter = _dv; iter.valid(); ++iter)
00630 iter.current().print(o);
00631 o << " /// ... ";
00632 #endif
00633 if(_label) {
00634 o << "label: ";
00635 _label->print(o);
00636 o << endl;
00637 }
00638 else
00639 o << endl;
00640 }
00641
00642 ActiveArc::~ActiveArc()
00643 {
00644 delete _original_dv_fields;
00645
00646 }
00647
00648 Listable *
00649 ActiveArc::listable_clone() const
00650 {
00651 return new ActiveArc(*this);
00652 }
00653
00654 void
00655 ActiveArc::print(ostream & o) const {
00656
00657 #ifdef _MY_DDG_DEBUG
00658 o << " { AArefs=" << _references << " p_arc=" << _prev_arc;
00659 o << " n_arc=" << _next_arc << " arc=" << _this_arc << endl;
00660
00661 o << " source_e:";
00662 _source_expr.print(o);
00663 o << " target_e:";
00664 _target_expr.print(o);
00665 o << endl;
00666
00667 Iterator<DVfield> iter = _working_dv_fields;
00668 for ( ; iter.valid(); ++iter)
00669 iter.current().print(o);
00670
00671 o << "(label: ";
00672
00673 if ( _label == NULL ) {
00674 o << "NULL";
00675 } else {
00676 _label->print( o );
00677 }
00678 o << ")";
00679 o << " }\n";
00680
00681 #endif
00682 }
00683
00684
00685
00686
00687 Binary_flag
00688 DDgraph::is_new_dvfield(Arc_type * &arc_field, int &position)
00689 {
00690 Binary_flag temp = (Binary_flag) (*arc_field << position & ARC_1_BIT);
00691
00692 if ((position += ONE_BIT) == A_BYTE) {
00693 position = 0;
00694 arc_field++;
00695 }
00696
00697 return temp;
00698 }
00699
00700
00701 DEP_DECISION
00702 DDgraph::dep_decision(Arc_type * &arc_field, int &position)
00703 {
00704 DEP_DECISION temp = (DEP_DECISION) (*arc_field << position & ARC_1_BIT);
00705
00706 if ((position += ONE_BIT) == A_BYTE) {
00707 position = 0;
00708 arc_field++;
00709 }
00710
00711 return temp;
00712 }
00713
00714 DEP_DIREC
00715 DDgraph::dep_direction(Arc_type * &arc_field, int &position)
00716 {
00717 DEP_DIREC temp = (DEP_DIREC) (*arc_field << position & ARC_1_BIT);
00718
00719 if ((position += ONE_BIT) == A_BYTE) {
00720 position = 0;
00721 arc_field++;
00722 }
00723
00724 return temp;
00725 }
00726
00727 DEP_TYPE
00728 DDgraph::dep_type(Arc_type * &arc_field, int &position)
00729 {
00730 Arc_type temp = *arc_field << position & ARC_2_BIT;
00731
00732 if ((position += TWO_BIT) >= A_BYTE) {
00733 position -= A_BYTE;
00734 arc_field++;
00735 temp |= *arc_field >> position & ARC_2_BIT;
00736 }
00737
00738 return (DEP_TYPE) temp;
00739 }
00740
00741 DIREC_TYPE
00742 DDgraph::direction(Arc_type * &arc_field, int &position)
00743 {
00744 Arc_type temp = *arc_field << position & ARC_3_BIT;
00745
00746 if ((position += THREE_BIT) >= A_BYTE) {
00747 position -= A_BYTE;
00748 arc_field++;
00749 temp |= *arc_field >> (THREE_BIT - position) & ARC_3_BIT;
00750 }
00751
00752 return (DIREC_TYPE) temp;
00753 }
00754
00755 DDIST_TYPE
00756 DDgraph::min_distance(Arc_type * &arc_field, int &position)
00757 {
00758 Arc_type temp = *arc_field << position & ARC_8_BIT;
00759 arc_field++;
00760 temp |= *arc_field >> (EIGHT_BIT - position) & ARC_8_BIT;
00761
00762 return (DDIST_TYPE) temp;
00763 }
00764
00765 DDIST_TYPE
00766 DDgraph::max_distance(Arc_type * &arc_field, int &position)
00767 {
00768 Arc_type temp = *arc_field << position & ARC_8_BIT;
00769 arc_field++;
00770 temp |= *arc_field >> (EIGHT_BIT - position) & ARC_8_BIT;
00771
00772 return (DDIST_TYPE) temp;
00773 }
00774
00775 void
00776 DDgraph::mark_new_dvfield(Arc_type * &arc_field, int &position)
00777 {
00778 *arc_field |= ARC_1_BIT >> position;
00779
00780 if ((position += ONE_BIT) == A_BYTE) {
00781 position = 0;
00782 arc_field++;
00783 }
00784 }
00785
00786 void
00787 DDgraph::mark_arc_end(Arc_type * &arc_field, int &position)
00788 {
00789 *arc_field &= ~(ARC_1_BIT >> position);
00790
00791 if ((position += ONE_BIT) == A_BYTE) {
00792 position = 0;
00793 arc_field++;
00794 }
00795 }
00796
00797 void
00798 DDgraph::store_dep_decision(Arc_type * &arc_field, int &position,
00799 DEP_DECISION ddeci)
00800 {
00801
00802 *arc_field |= (Arc_type) ddeci >> position;
00803
00804 if ((position += ONE_BIT) == A_BYTE) {
00805 position = 0;
00806 arc_field++;
00807 }
00808 }
00809
00810 void
00811 DDgraph::store_dep_direction(Arc_type * &arc_field, int &position,
00812 DEP_DIREC ddirec)
00813 {
00814 *arc_field |= (Arc_type) ddirec >> position;
00815
00816 if ((position += ONE_BIT) == A_BYTE) {
00817 position = 0;
00818 arc_field++;
00819 }
00820 }
00821
00822 void
00823 DDgraph::store_dep_type(Arc_type * &arc_field, int &position, DEP_TYPE deptype)
00824 {
00825 *arc_field |= (Arc_type) deptype >> position;
00826
00827 if ((position += TWO_BIT) >= A_BYTE) {
00828 position -= A_BYTE;
00829 arc_field++;
00830
00831 if (position)
00832 *arc_field |= (Arc_type) deptype << position;
00833
00834
00835 }
00836 }
00837
00838 void
00839 DDgraph::store_direction(Arc_type * &arc_field, int &position,
00840 DIREC_TYPE direct)
00841 {
00842 *arc_field |= (Arc_type) direct >> position;
00843
00844 if ((position += THREE_BIT) >= A_BYTE) {
00845 position -= A_BYTE;
00846 arc_field++;
00847 if (position)
00848 *arc_field |= (Arc_type) direct << (THREE_BIT - position);
00849 }
00850 }
00851
00852 void
00853 DDgraph::store_min_distance(Arc_type * &arc_field, int &position,
00854 DDIST_TYPE min_dist)
00855 {
00856 *arc_field |= (Arc_type) min_dist >> position;
00857 arc_field++;
00858 if (position)
00859 *arc_field |= (Arc_type) min_dist << (EIGHT_BIT - position);
00860 }
00861
00862 void
00863 DDgraph::store_max_distance(Arc_type * &arc_field, int &position,
00864 DDIST_TYPE max_dist)
00865 {
00866 *arc_field |= (Arc_type) max_dist >> position;
00867 arc_field++;
00868 if (position)
00869 *arc_field |= (Arc_type) max_dist << (EIGHT_BIT - position);
00870 }
00871
00872 void
00873 DDgraph::store_const_distance(Arc_type * &arc_field, int &position,
00874 DDIST_TYPE const_dist)
00875 {
00876 *arc_field |= (Arc_type) const_dist >> position;
00877 arc_field++;
00878 if (position)
00879 *arc_field |= (Arc_type) const_dist << (EIGHT_BIT - position);
00880 }
00881
00882
00883
00884 void
00885 DDgraph::initialize_this_active_arc(ActiveArc * aarc, Arc_type * arc) {
00886
00887 int pos = 1;
00888
00889
00890 activate(arc);
00891
00892 aarc->_references = 1;
00893
00894
00895
00896
00897 arc = data_field(arc);
00898
00899 while (is_new_dvfield(arc, pos)) {
00900
00901 DVfield *dvf;
00902
00903 DEP_DECISION ddeci = dep_decision(arc, pos);
00904
00905 if (_NORMAL == dep_direction(arc, pos)) {
00906 dvf = new DVfield(ddeci, dep_type(arc, pos), aarc->_source_stmt,
00907 aarc->_source_expr, aarc->_target_stmt,
00908 aarc->_target_expr);
00909 }
00910 else {
00911
00912 dvf = new DVfield(ddeci, dep_type(arc, pos), aarc->_target_stmt,
00913 aarc->_target_expr, aarc->_source_stmt,
00914 aarc->_source_expr);
00915 }
00916
00917
00918
00919 DIREC_TYPE dir;
00920 DDIST_TYPE min_dist;
00921 DDIST_TYPE max_dist;
00922
00923 while ((dir = direction(arc, pos)) != _DELIM) {
00924 min_dist = min_distance(arc, pos);
00925 max_dist = max_distance(arc, pos);
00926 if ( (min_dist == INV_DDIST) || (max_dist == INV_DDIST) )
00927 dvf->dv().ins_last(new ElementDV(dir));
00928 else
00929 dvf->dv().ins_last(new ElementDV(dir, min_dist, max_dist));
00930 }
00931
00932 if (!dvf->dv().entries()) {
00933
00934
00935 dvf->dep_type(_UNKNOWN);
00936 }
00937
00938 aarc->_working_dv_fields.ins_last(dvf);
00939
00940 }
00941
00942
00943
00944
00945
00946
00947 aarc->_original_dv_fields = new List<DVfield>;
00948 Iterator<DVfield> witer = aarc->_working_dv_fields;
00949
00950 for (; witer.valid(); ++witer) {
00951
00952 DVfield & d = witer.current();
00953 DVfield * new_dvf = (DVfield *) d.listable_clone();
00954
00955
00956
00957
00958 aarc->_original_dv_fields->ins_last(new_dvf);
00959
00960 Iterator<ElementDV> eiter = d.dv();
00961 for (; eiter.valid(); ++eiter)
00962 new_dvf->dv().ins_last(new ElementDV(eiter.current()));
00963
00964 }
00965
00966 }
00967
00968
00969 void
00970 DDgraph::search_active_arcs_for(DVfield * &dvf, ActiveArc * &active_arc,
00971 First_Last fl, DEP_DIREC ddirec,
00972 const Expression & from_expr,
00973 const Expression & to_expr)
00974 {
00975
00976 Iterator<ActiveArc> iter = _active_arcs;
00977
00978 if (ddirec == _NORMAL) {
00979
00980 while (&iter.current()._source_expr != &from_expr ||
00981 &iter.current()._target_expr != &to_expr)
00982 ++iter;
00983 }
00984 else {
00985 while (&iter.current()._source_expr != &to_expr ||
00986 &iter.current()._target_expr != &from_expr)
00987 ++iter;
00988 }
00989
00990
00991
00992 Iterator<DVfield> dv_iter = iter.current()._working_dv_fields;
00993
00994 dvf = NULL;
00995
00996 if (fl == _FIRST) {
00997 for (; dv_iter.valid(); ++dv_iter) {
00998 if (&dv_iter.current()._to_expr == &to_expr
00999 && dv_iter.current()._valid) {
01000
01001 active_arc = &iter.current();
01002 dvf = &dv_iter.current();
01003 active_arc->_references++;
01004 dvf->references_inc();
01005 break;
01006 }
01007 }
01008 }
01009 else {
01010
01011 for (dv_iter.set_to_last(); dv_iter.valid(); --dv_iter) {
01012 if (&dv_iter.current()._to_expr == &to_expr
01013 && dv_iter.current()._valid) {
01014
01015 active_arc = &iter.current();
01016 dvf = &dv_iter.current();
01017 active_arc->_references++;
01018 dvf->references_inc();
01019 break;
01020 }
01021 }
01022 }
01023 }
01024
01025 void
01026 DDgraph::update_links_between(Arc_type * new_this, ActiveArc * active_arc)
01027 {
01028 Arc_type *prev = active_arc->_prev_arc;
01029 Arc_type *next = active_arc->_next_arc;
01030
01031
01032
01033 if (prev) {
01034 if (is_active(prev)) {
01035 Iterator<ActiveArc> aa_iter = _active_arcs;
01036
01037 for (; aa_iter.valid(); ++aa_iter) {
01038 if (aa_iter.current()._this_arc == prev) {
01039 aa_iter.current()._next_arc = new_this;
01040 break;
01041 }
01042 }
01043 }
01044 else {
01045
01046 store_next_arc(prev, new_this);
01047 }
01048 }
01049 else {
01050
01051 if (active_arc->_source_expr.op() == ARRAY_REF_OP)
01052 ((ArrayRefExpr &) active_arc->_source_expr)._arcs = new_this;
01053 else {
01054
01055 ((IDExpr &) active_arc->_source_expr)._arcs = new_this;
01056 }
01057 }
01058
01059
01060
01061 if (next && is_active(next)) {
01062
01063
01064 Iterator<ActiveArc> aa_iter = _active_arcs;
01065
01066 for (; aa_iter.valid(); ++aa_iter) {
01067 if (aa_iter.current()._this_arc == next) {
01068 aa_iter.current()._prev_arc = new_this;
01069 break;
01070 }
01071 }
01072 }
01073 }
01074
01075
01076 void
01077 DDgraph::write_back_arc(ActiveArc * active_arc)
01078 {
01079 Iterator<DVfield> iter = active_arc->_working_dv_fields;
01080 Mutator<DVfield> o_iter = *active_arc->_original_dv_fields;
01081
01082 int w_bits, o_bits;
01083
01084
01085
01086 Arc_type *arc;
01087
01088 o_bits = w_bits = _ptr_size * NUM_OF_PTRS + 1;
01089
01090
01091
01092 for (; iter.valid(); ++iter) {
01093
01094
01095 w_bits += CONST_BITS + iter.current()._dv.entries() *
01096 (THREE_BIT + EIGHT_BIT + EIGHT_BIT);
01097 }
01098
01099 for (; o_iter.valid(); ++o_iter) {
01100
01101
01102 o_bits += CONST_BITS + o_iter.current()._dv.entries() *
01103 (THREE_BIT+ EIGHT_BIT + EIGHT_BIT);
01104 }
01105
01106 if (w_bits == o_bits) {
01107
01108
01109 for (iter.reset(); iter.valid(); ++iter) {
01110 for (o_iter.reset(); o_iter.valid(); ++o_iter) {
01111 if (&iter.current()._from_expr == &o_iter.current()._from_expr
01112 && &iter.current()._to_expr == &o_iter.current()._to_expr
01113 && iter.current()._dep_decided == o_iter.current()._dep_decided
01114 && iter.current()._dep_type == o_iter.current()._dep_type) {
01115
01116 Iterator<ElementDV> wdv_iter = iter.current()._dv;
01117 Iterator<ElementDV> odv_iter = o_iter.current()._dv;
01118
01119 for (; wdv_iter.valid() && odv_iter.valid(); ++wdv_iter, ++odv_iter) {
01120 if ( (wdv_iter.current().direction() !=
01121 odv_iter.current().direction()) ||
01122 (wdv_iter.current().min_distance() !=
01123 odv_iter.current().min_distance()) ||
01124 (wdv_iter.current().max_distance() !=
01125 odv_iter.current().max_distance())
01126 ) break;
01127 }
01128
01129 if (wdv_iter.end() && odv_iter.end()) {
01130
01131 o_iter.del();
01132 break;
01133 }
01134 }
01135 }
01136
01137 if (o_iter.end()) {
01138
01139
01140 break;
01141 }
01142 }
01143
01144 if (iter.valid()) {
01145
01146 arc = active_arc->_this_arc;
01147 store_next_arc(arc, active_arc->_next_arc);
01148 }
01149 else {
01150
01151 deactivate(active_arc->_this_arc);
01152 arc = 0;
01153 }
01154 }
01155 else if (Bytes(w_bits) == Bytes(o_bits)) {
01156
01157 arc = active_arc->_this_arc;
01158 store_next_arc(arc, active_arc->_next_arc);
01159 }
01160 else {
01161
01162
01163 arc = new Arc_type[Bytes(w_bits)];
01164
01165
01166
01167
01168 for (int i = 0; i<_next_arc_offset; ++i)
01169 arc[i] = *(active_arc->_this_arc + i);
01170
01171 store_next_arc(arc, active_arc->_next_arc);
01172
01173
01174
01175 update_links_between(arc, active_arc);
01176
01177 if(arcs_ptr(active_arc->_source_expr) == active_arc->_this_arc)
01178 {
01179 if (active_arc->_source_expr.op() == ID_OP)
01180 ((IDExpr &) active_arc->_source_expr)._arcs = 0;
01181 else if (active_arc->_source_expr.op() == ARRAY_REF_OP)
01182 ((ArrayRefExpr &) active_arc->_source_expr)._arcs = 0;
01183 }
01184 delete active_arc->_this_arc;
01185 active_arc->_this_arc = 0;
01186 }
01187
01188 if (arc) {
01189
01190
01191 int pos = 1;
01192
01193
01194
01195 arc = data_field(arc);
01196 _clear_arc(arc, Bytes(w_bits) - _data_field_offset);
01197
01198
01199
01200 for (iter.reset(); iter.valid(); ++iter) {
01201
01202 mark_new_dvfield(arc, pos);
01203 store_dep_decision(arc, pos, iter.current()._dep_decided);
01204
01205 if (&active_arc->_source_expr == &iter.current()._from_expr)
01206 store_dep_direction(arc, pos, _NORMAL);
01207 else
01208 store_dep_direction(arc, pos, _REVERSE);
01209
01210 store_dep_type(arc, pos, iter.current()._dep_type);
01211
01212 Iterator<ElementDV> dv_iter = iter.current()._dv;
01213
01214 for (; dv_iter.valid(); ++dv_iter) {
01215 store_direction(arc, pos, dv_iter.current().direction());
01216 store_min_distance(arc, pos, dv_iter.current().min_distance());
01217 store_max_distance(arc, pos, dv_iter.current().max_distance());
01218 }
01219
01220 store_direction(arc, pos, _DELIM);
01221 }
01222 mark_arc_end(arc, pos);
01223 }
01224 _active_arcs.del(*active_arc);
01225 }
01226
01227 void
01228 DDgraph::compute_dvf_n_arc(DVfield * &dvf, ActiveArc * &active_arc,
01229 First_Last fl,
01230 const Statement & from_stmt,
01231 const Expression & from_expr,
01232 const Statement & to_stmt,
01233 const Expression & to_expr)
01234 {
01235 Arc_type *prev_arc, *arc;
01236
01237
01238 dvf = NULL;
01239
01240
01241
01242 prev_arc = NULL;
01243
01244 for (arc = arcs_ptr(from_expr); arc; arc = next_arc(arc)) {
01245 if (&to_expr != target_expr(arc))
01246 prev_arc = arc;
01247 else if (is_active(arc)) {
01248
01249 search_active_arcs_for(dvf, active_arc, fl,
01250 _NORMAL, from_expr, to_expr);
01251 }
01252 else {
01253
01254
01255 int pos = 1;
01256 Arc_type *traverse = data_field(arc);
01257
01258
01259
01260
01261 while (is_new_dvfield(traverse, pos)) {
01262
01263 if (_NORMAL == test_dep_direction(traverse, pos + DVF_DDIREC)) {
01264
01265
01266 active_arc = new ActiveArc(*this, arc,
01267 prev_arc, next_arc(arc),
01268 from_stmt, from_expr);
01269
01270
01271 _active_arcs.ins_last(active_arc);
01272
01273
01274 Iterator<DVfield> iter = active_arc->_working_dv_fields;
01275
01276 if (fl == _FIRST) {
01277 while (&to_expr != &iter.current()._to_expr)
01278 ++iter;
01279 }
01280 else {
01281
01282 iter.set_to_last();
01283 while (&to_expr != &iter.current()._to_expr)
01284 --iter;
01285 }
01286 dvf = &iter.current();
01287 if(active_arc->label())
01288 dvf->setLabel(active_arc->label()->clone());
01289 dvf->references_inc();
01290 break;
01291 }
01292 _skip_this_dvfield(traverse, pos);
01293 }
01294 return;
01295 }
01296 }
01297
01298
01299
01300
01301 prev_arc = NULL;
01302
01303 for (arc = arcs_ptr(to_expr); arc; arc = next_arc(arc)) {
01304 if (&from_expr != target_expr(arc))
01305 prev_arc = arc;
01306 else if (is_active(arc)) {
01307
01308 search_active_arcs_for(dvf, active_arc, fl,
01309 _REVERSE, from_expr, to_expr);
01310 }
01311 else {
01312
01313 int pos = 1;
01314
01315 Arc_type *traverse = data_field(arc);
01316
01317
01318
01319
01320 while (is_new_dvfield(traverse, pos)) {
01321 if (_REVERSE == test_dep_direction(traverse, pos+DVF_DDIREC)) {
01322
01323 active_arc = new ActiveArc(*this, arc,
01324 prev_arc, next_arc(arc),
01325 to_stmt, to_expr);
01326
01327
01328 _active_arcs.ins_last(active_arc);
01329
01330
01331 Iterator<DVfield> iter = active_arc->_working_dv_fields;
01332
01333 if (fl == _FIRST) {
01334 while (&to_expr != &iter.current()._to_expr)
01335 ++iter;
01336 }
01337 else {
01338
01339 iter.set_to_last();
01340 while (&to_expr != &iter.current()._to_expr)
01341 --iter;
01342 }
01343 dvf = &iter.current();
01344 dvf->references_inc();
01345 break;
01346 }
01347 _skip_this_dvfield(traverse, pos);
01348 }
01349 return;
01350 }
01351 }
01352 }
01353
01354
01355 DVfield *
01356 DDgraph::prev(DVfield * dvf, ActiveArc * active_arc)
01357 {
01358 Iterator<DVfield> iter = active_arc->_working_dv_fields;
01359
01360 for ( ; iter.valid(); ++iter) {
01361 if (&iter.current() == dvf) {
01362
01363 break;
01364 }
01365 }
01366
01367
01368
01369 for (--iter; iter.valid(); --iter) {
01370 if (&iter.current()._from_expr == &dvf->_from_expr
01371 && iter.current()._valid) {
01372 iter.current().references_inc();
01373 break;
01374 }
01375 }
01376
01377 release(dvf, active_arc);
01378
01379 if (iter.valid()) {
01380
01381 return &iter.current();
01382 }
01383
01384 if (active_arc && !--active_arc->_references)
01385 write_back_arc(active_arc);
01386
01387 return NULL;
01388 }
01389
01390
01391 DVfield *
01392 DDgraph::next(DVfield * dvf, ActiveArc * active_arc)
01393 {
01394 Iterator<DVfield> iter = active_arc->_working_dv_fields;
01395
01396 for (; iter.valid(); ++iter) {
01397 if (&iter.current() == dvf) {
01398
01399 break;
01400 }
01401 }
01402
01403
01404
01405 for (++iter; iter.valid(); ++iter) {
01406 if (&iter.current()._from_expr == &dvf->_from_expr
01407 && iter.current()._valid) {
01408 iter.current().references_inc();
01409 break;
01410 }
01411 }
01412
01413 release(dvf, active_arc);
01414
01415 if (iter.valid()) {
01416
01417 return &iter.current();
01418 }
01419
01420 if (active_arc && !--active_arc->_references)
01421 write_back_arc(active_arc);
01422
01423 return NULL;
01424 }
01425
01426
01427 void
01428 DDgraph::release(DVfield * dvf, ActiveArc * &active_arc)
01429 {
01430 if (!dvf->references_dec() && !dvf->_valid) {
01431
01432 active_arc->_working_dv_fields.del(*dvf);
01433
01434 if (!active_arc->_working_dv_fields.entries()) {
01435
01436
01437 if (active_arc->_prev_arc && is_active(active_arc->_prev_arc)) {
01438 Iterator<ActiveArc> aa_iter = _active_arcs;
01439
01440 for (; aa_iter.valid(); ++aa_iter) {
01441 if (aa_iter.current()._this_arc == active_arc->_prev_arc) {
01442 aa_iter.current()._next_arc = active_arc->_next_arc;
01443 break;
01444 }
01445 }
01446
01447 if (active_arc->_next_arc)
01448 if (is_active(active_arc->_next_arc)) {
01449
01450 for (aa_iter.reset(); aa_iter.valid(); ++aa_iter) {
01451 if (aa_iter.current()._this_arc ==
01452 active_arc->_next_arc) {
01453 aa_iter.current()._prev_arc = active_arc->_prev_arc;
01454 break;
01455 }
01456 }
01457 }
01458 else {
01459
01460
01461 }
01462 }
01463 else {
01464
01465 if (active_arc->_prev_arc)
01466 store_next_arc(active_arc->_prev_arc,active_arc->_next_arc);
01467 else {
01468 if (active_arc->_source_expr.op() == ARRAY_REF_OP) {
01469 ((ArrayRefExpr &) active_arc->_source_expr)._arcs
01470 = active_arc->_next_arc;
01471 }
01472 else {
01473
01474 ((IDExpr &) active_arc->_source_expr)._arcs
01475 = active_arc->_next_arc;
01476 }
01477 }
01478
01479 if (active_arc->_next_arc)
01480 if (is_active(active_arc->_next_arc)) {
01481
01482 Iterator<ActiveArc> aa_iter = _active_arcs;
01483
01484 for (; aa_iter.valid(); ++aa_iter) {
01485 if (aa_iter.current()._this_arc ==
01486 active_arc->_next_arc) {
01487 aa_iter.current()._prev_arc = active_arc->_prev_arc;
01488 break;
01489 }
01490 }
01491 }
01492 else {
01493
01494
01495 }
01496 }
01497
01498
01499 if(arcs_ptr(active_arc->_source_expr) == active_arc->_this_arc)
01500 {
01501 if (active_arc->_source_expr.op() == ID_OP)
01502 ((IDExpr &) active_arc->_source_expr)._arcs = 0;
01503 else if (active_arc->_source_expr.op() == ARRAY_REF_OP)
01504 ((ArrayRefExpr &) active_arc->_source_expr)._arcs = 0;
01505 }
01506 delete active_arc->_this_arc;
01507 active_arc->_this_arc = 0;
01508 _active_arcs.del(*active_arc);
01509 active_arc = NULL;
01510
01511 return;
01512 }
01513 }
01514 }
01515
01516 void
01517 DDgraph::add(List<DVfield>&dv_fields)
01518 {
01519 Mutator<DVfield> iter = dv_fields;
01520
01521
01522
01523
01524
01525 List<DVfield> list;
01526
01527 for (; iter.valid(); iter.reset()) {
01528
01529
01530 DVfield *dvf = iter.grab();
01531
01532
01533
01534
01535 if (dvf->_from_expr.op() != ARRAY_REF_OP
01536 && dvf->_from_expr.op() != ID_OP)
01537 continue;
01538
01539
01540
01541
01542
01543 list.ins_first(dvf);
01544
01545 for (++iter; iter.valid(); ++iter) {
01546 if ( &iter.current()._from_expr == &dvf->_from_expr
01547 && &iter.current()._to_expr == &dvf->_to_expr
01548 || &iter.current()._from_expr == &dvf->_to_expr
01549 && &iter.current()._to_expr == &dvf->_from_expr)
01550 list.ins_last(iter.grab());
01551 }
01552
01553 Arc_type *prev_arc = 0;
01554 Arc_type *arc = arcs_ptr(dvf->_from_expr);
01555
01556 const Expression *src_expr = NULL, *tgt_expr;
01557
01558 for (; arc; arc = next_arc(arc)) {
01559 if (&dvf->_to_expr == target_expr(arc)) {
01560 src_expr = &dvf->_from_expr;
01561 tgt_expr = &dvf->_to_expr;
01562 break;
01563 }
01564 prev_arc = arc;
01565 }
01566
01567 if (!arc) {
01568
01569 arc = arcs_ptr(dvf->_to_expr);
01570 for (prev_arc = 0; arc; arc = next_arc(arc)) {
01571 if (&dvf->_from_expr == target_expr(arc)) {
01572 src_expr = &dvf->_to_expr;
01573 tgt_expr = &dvf->_from_expr;
01574 break;
01575 }
01576 prev_arc = arc;
01577 }
01578 }
01579
01580 if (arc) {
01581
01582 if (is_active(arc)) {
01583
01584 Iterator<ActiveArc> aa_iter = _active_arcs;
01585
01586
01587 while (aa_iter.current()._this_arc != arc)
01588 ++aa_iter;
01589
01590
01591 while (list.entries())
01592 aa_iter.current()._working_dv_fields.ins_last(list.grab(0));
01593 }
01594 else {
01595
01596 int bits = NUM_OF_PTRS * _ptr_size + 1;
01597
01598
01599 int pos = 1;
01600
01601
01602 Arc_type *temp_arc = data_field(arc);
01603
01604 while (is_new_dvfield(temp_arc, pos))
01605 bits += _count_this_dvfield(temp_arc, pos);
01606
01607 int old_bits = bits;
01608
01609
01610
01611 Iterator<DVfield> l_iter = list;
01612
01613 for (; l_iter.valid(); ++l_iter)
01614 bits += CONST_BITS +
01615 l_iter.current()._dv.entries() *
01616 (THREE_BIT + EIGHT_BIT + EIGHT_BIT);
01617
01618
01619 temp_arc = new Arc_type[Bytes(bits)];
01620
01621
01622
01623 if (next_arc(arc) && is_active(next_arc(arc))) {
01624
01625 Iterator<ActiveArc> aa_iter = _active_arcs;
01626 Expression * eptr = target_expr(next_arc(arc));
01627
01628 while (&aa_iter.current()._source_expr != src_expr ||
01629 &aa_iter.current()._target_expr != eptr) {
01630
01631 ++aa_iter;
01632 }
01633 aa_iter.current()._prev_arc = temp_arc;
01634 }
01635
01636
01637
01638 if (prev_arc)
01639 if (is_active(prev_arc)) {
01640
01641 Iterator<ActiveArc> aa_iter = _active_arcs;
01642 Expression * eptr = target_expr(prev_arc);
01643
01644 while (&aa_iter.current()._source_expr != src_expr ||
01645 &aa_iter.current()._target_expr != eptr) {
01646
01647 ++aa_iter;
01648 }
01649 aa_iter.current()._next_arc = temp_arc;
01650 }
01651 else
01652 store_next_arc(prev_arc, temp_arc);
01653 else
01654
01655 if (ID_OP == src_expr->op())
01656 ((IDExpr *) src_expr)->_arcs = temp_arc;
01657 else
01658 ((ArrayRefExpr *) src_expr)->_arcs = temp_arc;
01659
01660
01661
01662 for (int i = Bytes(old_bits) - 1; i >= 0; --i) {
01663
01664 temp_arc[i] = arc[i];
01665 }
01666
01667 delete arc;
01668 arc = 0;
01669
01670 temp_arc += Bytes(old_bits) - 1;
01671
01672 pos = old_bits % A_BYTE;
01673
01674
01675
01676
01677 switch (pos) {
01678 case 7:
01679 *temp_arc &= '\xfe';
01680 break;
01681 case 6:
01682 *temp_arc &= '\xfc';
01683 break;
01684 case 5:
01685 *temp_arc &= '\xf8';
01686 break;
01687 case 4:
01688 *temp_arc &= '\xf0';
01689 break;
01690 case 3:
01691 *temp_arc &= '\xe0';
01692 break;
01693 case 2:
01694 *temp_arc &= '\xc0';
01695 break;
01696 case 1:
01697 *temp_arc &= '\x80';
01698 break;
01699 case 0:
01700 *temp_arc = '\0';
01701 break;
01702 }
01703
01704 _clear_arc(temp_arc + 1, Bytes(bits) - Bytes(old_bits));
01705
01706
01707
01708 for (l_iter.reset(); l_iter.valid(); ++l_iter) {
01709 mark_new_dvfield(temp_arc, pos);
01710 store_dep_decision(temp_arc,pos,l_iter.current().dep_decided());
01711
01712 if (src_expr == &l_iter.current()._from_expr)
01713 store_dep_direction(temp_arc, pos, _NORMAL);
01714 else
01715 store_dep_direction(temp_arc, pos, _REVERSE);
01716
01717 store_dep_type(temp_arc, pos, l_iter.current().dep_type());
01718
01719 Iterator<ElementDV> dv_iter = l_iter.current()._dv;
01720
01721 for (; dv_iter.valid(); ++dv_iter) {
01722 store_direction(temp_arc,pos,dv_iter.current().direction());
01723 store_min_distance(temp_arc,pos,dv_iter.current().min_distance());
01724 store_max_distance(temp_arc,pos,dv_iter.current().max_distance());
01725 }
01726
01727 store_direction(temp_arc, pos, _DELIM);
01728 }
01729 mark_arc_end(temp_arc, pos);
01730 }
01731 }
01732 else {
01733
01734 int bits = NUM_OF_PTRS * _ptr_size + 1;
01735
01736
01737 Iterator<DVfield> l_iter = list;
01738
01739 for ( ; l_iter.valid(); ++l_iter)
01740 bits += CONST_BITS + l_iter.current()._dv.entries() *
01741 (THREE_BIT + EIGHT_BIT + EIGHT_BIT);
01742
01743 src_expr = &dvf->_from_expr;
01744 tgt_expr = &dvf->_to_expr;
01745 Expression *lbl_expr = dvf->label();
01746 arc = new Arc_type[Bytes(bits)];
01747
01748 store_target_stmt(arc, dvf->_to_stmt);
01749 store_target_expr(arc, *tgt_expr);
01750 if(lbl_expr != NULL) store_label_expr(arc, *lbl_expr->clone());
01751 else store_label_expr(arc, *constant(0));
01752
01753 if (arcs_ptr(*src_expr)) {
01754 store_next_arc(arc, arcs_ptr(*src_expr));
01755
01756 if (is_active(arcs_ptr(*src_expr))) {
01757 Iterator<ActiveArc> aa_iter = _active_arcs;
01758
01759 while (&aa_iter.current()._source_expr != src_expr ||
01760 aa_iter.current()._prev_arc) {
01761
01762 ++aa_iter;
01763 }
01764 aa_iter.current()._prev_arc = arc;
01765 }
01766 }
01767 else {
01768 store_next_arc(arc, NULL);
01769 }
01770
01771 switch (src_expr->op()) {
01772 case ID_OP:
01773 ((IDExpr *) src_expr)->_arcs = arc;
01774 break;
01775 case ARRAY_REF_OP:
01776 ((ArrayRefExpr *) src_expr)->_arcs = arc;
01777 break;
01778 default: break;
01779 }
01780
01781 int pos = 1;
01782
01783 arc = data_field(arc);
01784
01785 _clear_arc(arc, Bytes(bits) - _data_field_offset);
01786
01787
01788
01789 for (l_iter.reset(); l_iter.valid(); ++l_iter) {
01790 mark_new_dvfield(arc, pos);
01791 store_dep_decision(arc, pos, l_iter.current()._dep_decided);
01792
01793 if (src_expr == &l_iter.current()._from_expr)
01794 store_dep_direction(arc, pos, _NORMAL);
01795 else
01796 store_dep_direction(arc, pos, _REVERSE);
01797
01798 store_dep_type(arc, pos, l_iter.current()._dep_type);
01799
01800 Iterator<ElementDV> dv_iter = l_iter.current()._dv;
01801
01802 for (; dv_iter.valid(); ++dv_iter) {
01803 store_direction(arc, pos, dv_iter.current().direction());
01804 store_min_distance(arc, pos, dv_iter.current().min_distance());
01805 store_max_distance(arc, pos, dv_iter.current().max_distance());
01806 }
01807
01808 store_direction(arc, pos, _DELIM);
01809 }
01810 mark_arc_end(arc, pos);
01811 }
01812 list.clear();
01813 }
01814 }
01815
01816
01817 DDiterator::DDiterator(RefList<Statement> * from_stmts,
01818 RefList<Statement> * to_stmts,
01819 DDgraph & ddgraph)
01820 : _ddgraph(ddgraph)
01821 {
01822 _init_from = _init_to = _STMTS;
01823 _from_refs = _to_refs = _IN_REFS;
01824
01825 _from_stmts = from_stmts;
01826
01827 _iter_from_stmts
01828 = new Iterator<Statement>(*from_stmts);
01829
01830 _iter_from_exprs
01831 = new Iterator<Expression>((*from_stmts)[0].in_refs());
01832
01833 _to_stmts = to_stmts;
01834
01835 _iter_to_stmts = new Iterator<Statement>(*to_stmts);
01836 _iter_to_exprs = new Iterator<Expression>((*to_stmts)[0].in_refs());
01837 _current_dvf = NULL;
01838
01839
01840
01841 while (_iter_from_exprs->end()) {
01842 delete _iter_from_exprs;
01843 _iter_from_exprs = 0;
01844
01845 if (_from_refs == _IN_REFS) {
01846 _from_refs = _OUT_REFS;
01847 _iter_from_exprs = new Iterator<Expression>
01848 (_iter_from_stmts->current().out_refs());
01849 }
01850 else {
01851
01852 ++(*_iter_from_stmts);
01853
01854 if (_iter_from_stmts->end()) {
01855
01856 return;
01857 }
01858 _from_refs = _IN_REFS;
01859 _iter_from_exprs = new Iterator<Expression>
01860 (_iter_from_stmts->current().in_refs());
01861 }
01862 }
01863
01864 _next_in_STMTS_n_STMTS();
01865 }
01866
01867 DDiterator::DDiterator(RefList<Statement> * from_stmts,
01868 const Statement & to_stmt, const Expression & to_expr,
01869 DDgraph & ddgraph)
01870 : _ddgraph(ddgraph)
01871 {
01872 _init_from = _STMTS;
01873 _init_to = _EXPR;
01874
01875 _from_stmts = from_stmts;
01876 _to_stmt = &to_stmt;
01877 _to_expr = &to_expr;
01878
01879 _iter_from_stmts
01880 = new Iterator<Statement>(*from_stmts);
01881
01882 _iter_from_exprs
01883 = new Iterator<Expression>((*from_stmts)[0].in_refs());
01884
01885 _current_dvf = NULL;
01886 _next_in_STMTS_n_EXPR();
01887 }
01888
01889 DDiterator::DDiterator(const Statement & from_stmt,
01890 const Expression & from_expr,
01891 RefList<Statement> * to_stmts,
01892 DDgraph & ddgraph)
01893 : _ddgraph(ddgraph)
01894 {
01895 _init_from = _EXPR;
01896 _init_to = _STMTS;
01897
01898 _from_stmt = &from_stmt;
01899 _from_expr = &from_expr;
01900 _to_stmts = to_stmts;
01901
01902 _iter_to_stmts = new Iterator<Statement>(*to_stmts);
01903 _iter_to_exprs = new Iterator<Expression>((*to_stmts)[0].in_refs());
01904
01905 _current_dvf = NULL;
01906 _next_in_EXPR_n_STMTS();
01907 }
01908
01909
01910 DDiterator::DDiterator(const DDiterator & other)
01911 : _ddgraph(other._ddgraph)
01912 {
01913 _current_dvf = other._current_dvf;
01914 _active_arc = other._active_arc;
01915 _init_from = other._init_from;
01916 _init_to = other._init_to;
01917
01918 if (_init_from == _STMTS) {
01919 _from_refs = other._from_refs;
01920 _from_stmts = new RefList<Statement>(*other._from_stmts);
01921 _iter_from_stmts = new Iterator<Statement>(*_from_stmts);
01922 _iter_from_exprs = new Iterator<Expression>(*other._iter_from_exprs);
01923 }
01924 else {
01925 _from_stmt = other._from_stmt;
01926 _from_expr = other._from_expr;
01927 }
01928
01929 if (_init_to == _STMTS) {
01930 _to_refs = other._to_refs;
01931 _to_stmts = new RefList<Statement>(*other._to_stmts);
01932 _iter_to_stmts = new Iterator<Statement>(*_to_stmts);
01933 _iter_to_exprs = new Iterator<Expression>(*other._iter_to_exprs);
01934 }
01935 else {
01936 _to_stmt = other._to_stmt;
01937 _to_expr = other._to_expr;
01938 }
01939 }
01940
01941 void
01942 DDiterator::operator-- ()
01943 {
01944 if (!_current_dvf)
01945 return;
01946
01947 if ((_current_dvf = _ddgraph.prev(_current_dvf, _active_arc)))
01948 return;
01949
01950 if (_init_to == _STMTS) {
01951 --(*_iter_to_exprs);
01952
01953 if (_init_from == _STMTS) {
01954
01955 _prev_in_STMTS_n_STMTS();
01956 }
01957 else {
01958
01959 _prev_in_EXPR_n_STMTS();
01960 }
01961 }
01962 else {
01963 if (_init_from == _STMTS) {
01964
01965 --(*_iter_from_exprs);
01966 _prev_in_STMTS_n_EXPR();
01967 }
01968
01969
01970 }
01971 }
01972
01973 void
01974 DDiterator::operator++ ()
01975 {
01976 if (!_current_dvf)
01977 return;
01978
01979 if ((_current_dvf = _ddgraph.next(_current_dvf, _active_arc)))
01980 return;
01981
01982 if (_init_to == _STMTS) {
01983 ++(*_iter_to_exprs);
01984
01985 if (_init_from == _STMTS) {
01986
01987 _next_in_STMTS_n_STMTS();
01988 }
01989 else {
01990
01991 _next_in_EXPR_n_STMTS();
01992 }
01993 }
01994 else {
01995 if (_init_from == _STMTS) {
01996
01997 ++(*_iter_from_exprs);
01998 _next_in_STMTS_n_EXPR();
01999 }
02000
02001
02002 }
02003 }
02004
02005 void
02006 DDiterator::reset()
02007 {
02008 if (_current_dvf && _active_arc)
02009 _ddgraph.exit(_current_dvf, _active_arc);
02010
02011 if (_init_to == _STMTS) {
02012 _current_dvf = NULL;
02013 _to_refs = _IN_REFS;
02014
02015 delete _iter_to_exprs;
02016 _iter_to_exprs = 0;
02017
02018 _iter_to_stmts->reset();
02019
02020 _iter_to_exprs = new Iterator<Expression>
02021 (_iter_to_stmts->current().in_refs());
02022
02023 if (_init_from == _STMTS) {
02024
02025 _from_refs = _IN_REFS;
02026
02027 delete _iter_from_exprs;
02028 _iter_from_exprs = 0;
02029
02030 _iter_from_stmts->reset();
02031
02032 _iter_from_exprs = new Iterator<Expression>
02033 (_iter_from_stmts->current().in_refs());
02034
02035
02036
02037 while (_iter_from_exprs->end()) {
02038 delete _iter_from_exprs;
02039 _iter_from_exprs = 0;
02040
02041 if (_from_refs == _IN_REFS) {
02042 _from_refs = _OUT_REFS;
02043 _iter_from_exprs = new Iterator<Expression>
02044 (_iter_from_stmts->current().out_refs());
02045 }
02046 else {
02047
02048 ++(*_iter_from_stmts);
02049
02050 if (_iter_from_stmts->end()) {
02051
02052 return;
02053 }
02054 _from_refs = _IN_REFS;
02055 _iter_from_exprs = new Iterator<Expression>
02056 (_iter_from_stmts->current().in_refs());
02057 }
02058 }
02059
02060 _next_in_STMTS_n_STMTS();
02061 }
02062 else {
02063
02064 _next_in_EXPR_n_STMTS();
02065 }
02066 }
02067 else if (_init_from == _STMTS) {
02068
02069
02070 _current_dvf = NULL;
02071 _from_refs = _IN_REFS;
02072
02073 delete _iter_from_exprs;
02074 _iter_from_exprs = 0;
02075
02076 _iter_from_stmts->reset();
02077
02078 _iter_from_exprs = new Iterator<Expression>
02079 (_iter_from_stmts->current().in_refs());
02080
02081 _next_in_STMTS_n_EXPR();
02082 }
02083 else {
02084
02085 _ddgraph.compute_dvf_n_arc(_current_dvf, _active_arc, _FIRST,
02086 *_from_stmt, *_from_expr, *_to_stmt, *_to_expr);
02087 }
02088 }
02089
02090 void
02091 DDiterator::set_to_last()
02092 {
02093 if (_current_dvf && _active_arc)
02094 _ddgraph.exit(_current_dvf, _active_arc);
02095
02096 if (_init_to == _STMTS) {
02097 _current_dvf = NULL;
02098 _to_refs = _IN_REFS;
02099
02100 delete _iter_to_exprs;
02101 _iter_to_exprs = 0;
02102
02103 _iter_to_stmts->set_to_last();
02104
02105 _iter_to_exprs = new Iterator<Expression>
02106 (_iter_to_stmts->current().in_refs());
02107
02108 _iter_to_exprs->set_to_last();
02109
02110 if (_init_from == _STMTS) {
02111
02112 _from_refs = _IN_REFS;
02113
02114 delete _iter_from_exprs;
02115 _iter_from_exprs = 0;
02116
02117 _iter_from_stmts->set_to_last();
02118
02119 _iter_from_exprs = new Iterator<Expression>
02120 (_iter_from_stmts->current().in_refs());
02121
02122
02123
02124 while (_iter_from_exprs->end()) {
02125 delete _iter_from_exprs;
02126 _iter_from_exprs = 0;
02127
02128 if (_from_refs == _IN_REFS) {
02129 _from_refs = _OUT_REFS;
02130 _iter_from_exprs = new Iterator<Expression>
02131 (_iter_from_stmts->current().out_refs());
02132 }
02133 else {
02134
02135 ++(*_iter_from_stmts);
02136
02137 if (_iter_from_stmts->end()) {
02138
02139 return;
02140 }
02141 _from_refs = _IN_REFS;
02142 _iter_from_exprs = new Iterator<Expression>
02143 (_iter_from_stmts->current().in_refs());
02144 }
02145 }
02146
02147 _iter_from_exprs->set_to_last();
02148 _prev_in_STMTS_n_STMTS();
02149 }
02150 else {
02151
02152 _prev_in_EXPR_n_STMTS();
02153 }
02154 }
02155 else if (_init_from == _STMTS) {
02156
02157
02158 _current_dvf = NULL;
02159 _from_refs = _IN_REFS;
02160
02161 delete _iter_from_exprs;
02162 _iter_from_exprs = 0;
02163
02164 _iter_from_stmts->reset();
02165
02166 _iter_from_exprs = new Iterator<Expression>
02167 (_iter_from_stmts->current().in_refs());
02168
02169 _iter_from_exprs->set_to_last();
02170
02171 _prev_in_STMTS_n_EXPR();
02172 }
02173 else {
02174
02175
02176 _ddgraph.compute_dvf_n_arc(_current_dvf, _active_arc, _LAST,
02177 *_from_stmt, *_from_expr, *_to_stmt, *_to_expr);
02178 }
02179 }
02180
02181
02182
02183 void
02184 DDiterator::_next_in_STMTS_n_STMTS()
02185 {
02186 while (1)
02187 if (_iter_to_exprs->valid()) {
02188
02189
02190
02191 _ddgraph.compute_dvf_n_arc(_current_dvf, _active_arc, _FIRST,
02192 _iter_from_stmts->current(), _iter_from_exprs->current()
02193 ,_iter_to_stmts->current(), _iter_to_exprs->current());
02194 if (_current_dvf)
02195 return;
02196 ++(*_iter_to_exprs);
02197 }
02198 else {
02199 delete _iter_to_exprs;
02200 _iter_to_exprs = 0;
02201
02202 if (_to_refs == _IN_REFS) {
02203 _to_refs = _OUT_REFS;
02204 _iter_to_exprs = new Iterator<Expression>
02205 (_iter_to_stmts->current().out_refs());
02206 }
02207 else {
02208 ++(*_iter_to_stmts);
02209
02210 while (_iter_to_stmts->end()) {
02211 ++(*_iter_from_exprs);
02212
02213 while (_iter_from_exprs->end()) {
02214 delete _iter_from_exprs;
02215 _iter_from_exprs = 0;
02216
02217 if (_from_refs == _IN_REFS) {
02218 _from_refs = _OUT_REFS;
02219 _iter_from_exprs = new Iterator<Expression>
02220 (_iter_from_stmts->current().out_refs());
02221 }
02222 else {
02223
02224 ++(*_iter_from_stmts);
02225
02226 if (_iter_from_stmts->end()) {
02227
02228 return;
02229 }
02230 _from_refs = _IN_REFS;
02231 _iter_from_exprs = new Iterator<Expression>
02232 (_iter_from_stmts->current().in_refs());
02233 }
02234 }
02235 _iter_to_stmts->reset();
02236 }
02237 _to_refs = _IN_REFS;
02238
02239 _iter_to_exprs = new Iterator<Expression>
02240 (_iter_to_stmts->current().in_refs());
02241 }
02242 }
02243 }
02244
02245 void
02246 DDiterator::_next_in_STMTS_n_EXPR()
02247 {
02248 while (1) {
02249 if (_iter_from_exprs->valid()) {
02250 _ddgraph.compute_dvf_n_arc(_current_dvf, _active_arc, _FIRST,
02251 _iter_from_stmts->current(),
02252 _iter_from_exprs->current(),
02253 *_to_stmt, *_to_expr);
02254 if (_current_dvf)
02255 return;
02256
02257 ++(*_iter_from_exprs);
02258 }
02259 else {
02260 delete _iter_from_exprs;
02261 _iter_from_exprs = 0;
02262
02263 if (_from_refs == _IN_REFS) {
02264 _from_refs = _OUT_REFS;
02265 _iter_from_exprs = new Iterator<Expression>
02266 (_iter_from_stmts->current().out_refs());
02267 }
02268 else {
02269 ++(*_iter_from_stmts);
02270
02271 if (_iter_from_stmts->end())
02272 return;
02273
02274 _from_refs = _IN_REFS;
02275
02276 _iter_from_exprs = new Iterator<Expression>
02277 (_iter_from_stmts->current().in_refs());
02278 }
02279 }
02280 }
02281 }
02282
02283 void
02284 DDiterator::_next_in_EXPR_n_STMTS()
02285 {
02286 while (1) {
02287 if (_iter_to_exprs->valid()) {
02288 _ddgraph.compute_dvf_n_arc(_current_dvf, _active_arc, _FIRST,
02289 *_from_stmt, *_from_expr,
02290 _iter_to_stmts->current(),
02291 _iter_to_exprs->current());
02292 if (_current_dvf)
02293 return;
02294
02295 ++(*_iter_to_exprs);
02296 }
02297 else {
02298 delete _iter_to_exprs;
02299 _iter_to_exprs = 0;
02300
02301 if (_to_refs == _IN_REFS) {
02302 _to_refs = _OUT_REFS;
02303 _iter_to_exprs = new Iterator<Expression>
02304 (_iter_to_stmts->current().out_refs());
02305 }
02306 else {
02307 ++(*_iter_to_stmts);
02308
02309 if (_iter_to_stmts->end())
02310 return;
02311
02312 _to_refs = _IN_REFS;
02313
02314 _iter_to_exprs = new Iterator<Expression>
02315 (_iter_to_stmts->current().in_refs());
02316 }
02317 }
02318 }
02319 }
02320
02321
02322 void
02323 DDiterator::_prev_in_STMTS_n_STMTS()
02324 {
02325 while (1) {
02326 if (_iter_to_exprs->valid()) {
02327
02328
02329
02330 _ddgraph.compute_dvf_n_arc(_current_dvf, _active_arc, _LAST,
02331 _iter_from_stmts->current(),
02332 _iter_from_exprs->current(),
02333 _iter_to_stmts->current(),
02334 _iter_to_exprs->current());
02335 if (_current_dvf)
02336 return;
02337
02338 --(*_iter_to_exprs);
02339 }
02340 else {
02341 delete _iter_to_exprs;
02342 _iter_to_exprs = 0;
02343
02344 if (_to_refs == _IN_REFS) {
02345 _to_refs = _OUT_REFS;
02346 _iter_to_exprs = new Iterator<Expression>
02347 (_iter_to_stmts->current().out_refs());
02348
02349 _iter_to_exprs->set_to_last();
02350 }
02351 else {
02352 --(*_iter_to_stmts);
02353
02354 while (_iter_to_stmts->end()) {
02355 --(*_iter_from_exprs);
02356
02357 while (_iter_from_exprs->end()) {
02358 delete _iter_from_exprs;
02359 _iter_from_exprs = 0;
02360
02361 if (_from_refs == _IN_REFS) {
02362 _from_refs = _OUT_REFS;
02363
02364 _iter_from_exprs = new Iterator<Expression>
02365 (_iter_from_stmts->current().out_refs());
02366
02367 _iter_from_exprs->set_to_last();
02368 }
02369 else {
02370 --(*_iter_from_stmts);
02371
02372 if (_iter_from_stmts->end()) {
02373
02374 return;
02375 }
02376
02377 _from_refs = _IN_REFS;
02378
02379 _iter_from_exprs = new Iterator<Expression>
02380 (_iter_from_stmts->current().in_refs());
02381
02382 _iter_from_exprs->set_to_last();
02383 }
02384 }
02385 _iter_to_stmts->set_to_last();
02386 }
02387 _to_refs = _IN_REFS;
02388
02389 _iter_to_exprs = new Iterator<Expression>
02390 (_iter_to_stmts->current().in_refs());
02391
02392 _iter_to_exprs->set_to_last();
02393 }
02394 }
02395 }
02396 }
02397
02398 void
02399 DDiterator::_prev_in_STMTS_n_EXPR()
02400 {
02401 while (1) {
02402 if (_iter_from_exprs->valid()) {
02403 _ddgraph.compute_dvf_n_arc(_current_dvf, _active_arc, _LAST,
02404 _iter_from_stmts->current(),
02405 _iter_from_exprs->current(),
02406 *_to_stmt, *_to_expr);
02407 if (_current_dvf)
02408 return;
02409
02410 --(*_iter_from_exprs);
02411 }
02412 else {
02413 delete _iter_from_exprs;
02414 _iter_from_exprs = 0;
02415
02416 if (_from_refs == _IN_REFS) {
02417 _from_refs = _OUT_REFS;
02418
02419 _iter_from_exprs = new Iterator<Expression>
02420 (_iter_from_stmts->current().out_refs());
02421
02422 _iter_from_exprs->set_to_last();
02423 }
02424 else {
02425 --(*_iter_from_stmts);
02426
02427 if (_iter_from_stmts->end())
02428 return;
02429
02430 _from_refs = _IN_REFS;
02431
02432 _iter_from_exprs = new Iterator<Expression>
02433 (_iter_from_stmts->current().in_refs());
02434
02435 _iter_from_exprs->set_to_last();
02436 }
02437 }
02438 }
02439 }
02440
02441 void
02442 DDiterator::_prev_in_EXPR_n_STMTS()
02443 {
02444 while (1) {
02445 if (_iter_to_exprs->valid()) {
02446 _ddgraph.compute_dvf_n_arc(_current_dvf, _active_arc, _LAST,
02447 *_from_stmt, *_from_expr,
02448 _iter_to_stmts->current(),
02449 _iter_to_exprs->current());
02450 if (_current_dvf)
02451 return;
02452
02453 --(*_iter_to_exprs);
02454 }
02455 else {
02456 delete _iter_to_exprs;
02457 _iter_to_exprs = 0;
02458
02459 if (_to_refs == _IN_REFS) {
02460 _to_refs = _OUT_REFS;
02461
02462 _iter_to_exprs = new Iterator<Expression>
02463 (_iter_to_stmts->current().out_refs());
02464
02465 _iter_to_exprs->set_to_last();
02466 }
02467 else {
02468 --(*_iter_to_stmts);
02469
02470 if (_iter_to_stmts->end())
02471 return;
02472
02473 _to_refs = _IN_REFS;
02474
02475 _iter_to_exprs = new Iterator<Expression>
02476 (_iter_to_stmts->current().in_refs());
02477
02478 _iter_to_exprs->set_to_last();
02479 }
02480 }
02481 }
02482 }
02483