00001
00016 #include "LocDFSet.hpp"
00017 #include <Utils/Util.hpp>
00018
00019 namespace OA {
00020 namespace DataFlow {
00021
00022 static bool debug = false;
00023
00024 LocDFSet::LocDFSet()
00025 : mBaseLocToSetMapValid(true), mHasUnknownLoc(false)
00026 {
00027 OA_DEBUG_CTRL_MACRO("DEBUG_LocDFSet:ALL", debug);
00028
00029 mSetPtr = new LocSet;
00030
00031 mInvLocs = new LocSet;
00032 }
00033
00034 LocDFSet::LocDFSet(const LocDFSet &other)
00035 : mBaseLocToSetMapValid(other.mBaseLocToSetMapValid),
00036 mHasUnknownLoc(other.mHasUnknownLoc)
00037 { mSetPtr = new LocSet;
00038 *mSetPtr = *(other.mSetPtr);
00039 mInvLocs = new LocSet;
00040 *mInvLocs = *(other.mInvLocs);
00041
00042 mBaseLocToSetMapValid = false;
00043 }
00044
00045
00046 OA_ptr<DataFlowSet> LocDFSet::clone()
00047 {
00048 OA_ptr<LocDFSet> retval;
00049 retval = new LocDFSet(*this);
00050 return retval;
00051 }
00052
00053
00054
00055 bool LocDFSet::operator ==(DataFlowSet &other) const
00056 {
00057 LocDFSet& recastOther
00058 = dynamic_cast<LocDFSet&>(other);
00059 return *mSetPtr == *(recastOther.mSetPtr);
00060 }
00061
00062 bool LocDFSet::operator !=(DataFlowSet &other) const
00063 {
00064 LocDFSet& recastOther
00065 = dynamic_cast<LocDFSet&>(other);
00066 return *mSetPtr != *(recastOther.mSetPtr);
00067 }
00068
00069 LocDFSet& LocDFSet::setUnion(DataFlowSet &other)
00070 {
00071 LocDFSet& recastOther
00072 = dynamic_cast<LocDFSet&>(other);
00073 OA_ptr<LocSet> temp; temp = new LocSet;
00074 std::set_union(mSetPtr->begin(), mSetPtr->end(),
00075 recastOther.mSetPtr->begin(), recastOther.mSetPtr->end(),
00076 std::inserter(*temp,temp->end()));
00077 *mSetPtr = *temp;
00078 mBaseLocToSetMapValid = false;
00079 return *this;
00080 }
00081
00082 LocDFSet& LocDFSet::setIntersect(LocDFSet &other)
00083 {
00084 OA_ptr<LocSet> temp; temp = new LocSet;
00085 std::set_intersection(mSetPtr->begin(), mSetPtr->end(),
00086 other.mSetPtr->begin(), other.mSetPtr->end(),
00087 std::inserter(*temp,temp->end()));
00088 *mSetPtr = *temp;
00089 mBaseLocToSetMapValid = false;
00090 return *this;
00091 }
00092
00093 LocDFSet& LocDFSet::setDifference(LocDFSet &other)
00094 {
00095 OA_ptr<LocSet> temp; temp = new LocSet;
00096 std::set_difference(mSetPtr->begin(), mSetPtr->end(),
00097 other.mSetPtr->begin(), other.mSetPtr->end(),
00098 std::inserter(*temp,temp->end()));
00099 *mSetPtr = *temp;
00100 mBaseLocToSetMapValid = false;
00101 return *this;
00102 }
00103
00106 OA_ptr<LocDFSet> LocDFSet::callerToCallee(ProcHandle caller,
00107 CallHandle call, ProcHandle callee,
00108 OA_ptr<Alias::InterAliasInterface> interAlias,
00109 OA_ptr<ParamBindings> paramBind,
00110 OA_ptr<CalleeToCallerVisitorIRInterface> ir)
00111 {
00112 OA_ptr<DataFlow::LocDFSet> retval;
00113 retval = new DataFlow::LocDFSet();
00114
00115 if (debug) {
00116 std::cout << "callerToCallee" << std::endl;
00117 }
00118
00119
00120 OA_ptr<Alias::Interface> callerAlias = interAlias->getAliasResults(caller);
00121
00122 OA_ptr<Alias::Interface> calleeAlias = interAlias->getAliasResults(callee);
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 if (debug) {
00151 std::cout << "++++++++ LocDFSet::callerToCallee()\n";
00152 std::cout << " actual ExprTrees to formal may locations:";
00153 }
00154
00155 OA_ptr<ExprHandleIterator> exprIter;
00156 exprIter = paramBind->getActualExprHandleIterator(call);
00157 for (; exprIter->isValid(); (*exprIter)++) {
00158 ExprHandle expr = exprIter->current();
00159 OA_ptr<ExprTree> eTree = paramBind->getActualExprTree(expr);
00160
00161
00162 MemRefHandle memref;
00163 EvalToMemRefVisitor evalVisitor;
00164 eTree->acceptVisitor(evalVisitor);
00165 if (debug) {
00166 eTree->output(*ir);
00167 }
00168 if ( evalVisitor.isMemRef() ) {
00169 memref = evalVisitor.getMemRef();
00170 if (debug) {
00171 std::cout << " MemRef: "
00172 << ir->toString(memref)
00173 << std::endl;
00174 }
00175 } else {
00176 if (debug) {
00177 std::cout << " No MemRef at top of ExprTree\n";
00178 }
00179 continue;
00180 }
00181
00182 SymHandle sym_formal = paramBind->getCalleeFormal(call,memref,callee);
00183 if (debug) {
00184 std::cout << " formal: " << ir->toString(sym_formal)
00185 << std::endl;
00186 }
00187
00188
00189 OA_ptr<MemRefExprIterator> mreIter;
00190 mreIter = ir->getMemRefExprIterator(memref);
00191 for (; mreIter->isValid(); (*mreIter)++) {
00192 OA_ptr<MemRefExpr> mre_actual = mreIter->current();
00193
00194 OA_ptr<MemRefExpr> deref_mre = mre_actual->clone();
00195 bool found_locs = true;
00196 int numDerefs = 0;
00197
00198
00199
00200 while (found_locs) {
00201 found_locs = false;
00202
00203
00204 OA_ptr<MemRefExpr> nullmre;
00205 OA_ptr<Deref> deref;
00206 deref = new Deref(MemRefExpr::USE,nullmre,1);
00207 deref_mre = deref->composeWith(deref_mre);
00208 numDerefs++;
00209
00210 if (debug) {
00211 std::cout << "\t\tgetting maylocs from caller for deref_mre = ";
00212 deref_mre->output(*ir);
00213 std::cout << std::endl;
00214 }
00215
00216 OA_ptr<LocIterator> mayLocIter;
00217 mayLocIter = callerAlias->getMayLocs(*deref_mre,caller);
00218 for (; mayLocIter->isValid(); (*mayLocIter)++) {
00219 found_locs = true;
00220 OA_ptr<Location> loc = mayLocIter->current();
00221 if (debug) {
00222 std::cout << "\t\tmayloc for memref, loc = ";
00223 loc->output(*ir);
00224 }
00225
00226
00227 if (hasOverlapLoc(loc)) {
00228
00229 if (debug) {
00230 std::cout << "\t\t\tcaller LocDFSet hasOverlapLoc(loc) true\n";
00231 }
00232
00233
00234 OA_ptr<MemRefExpr> mre_final;
00235 OA_ptr<NamedRef> mre_formal;
00236 mre_formal = new NamedRef(MemRefExpr::USE, sym_formal);
00237 mre_final = mre_formal->clone();
00238
00239
00240 for (int i = 0; i < numDerefs; i++) {
00241
00242 OA_ptr<MemRefExpr> nullmre;
00243 OA_ptr<Deref> deref;
00244 deref = new Deref(MemRefExpr::USE,nullmre,1);
00245 mre_final = deref->composeWith(mre_final);
00246 }
00247
00248 if (debug) {
00249 std::cout << "\t\tquerying callee with mre_final = ";
00250 mre_final->output(*ir);
00251 std::cout << std::endl;
00252 }
00253
00254
00255 OA_ptr<LocIterator> mayLocIter;
00256 mayLocIter = calleeAlias->getMayLocs(*mre_final,callee);
00257 for (; mayLocIter->isValid(); (*mayLocIter)++) {
00258 OA_ptr<Location> mayloc = mayLocIter->current();
00259 if (debug) {
00260 std::cout << "\t\tmayloc for mre_final, loc = ";
00261 mayloc->output(*ir);
00262 }
00263
00264 retval->insert(mayloc);
00265 }
00266 }
00267 else {
00268 if (debug) {
00269 std::cout << "caller LocDFSet hasOverlapLoc(loc) false" << std::endl;
00270 }
00271 }
00272
00273 }
00274 }
00275 }
00276 }
00277
00278 return retval;
00279 }
00280
00283 OA_ptr<LocDFSet> LocDFSet::callerToCalleeTransitive(ProcHandle caller,
00284 CallHandle call, ProcHandle callee,
00285 OA_ptr<Alias::InterAliasInterface> interAlias,
00286 OA_ptr<ParamBindings> paramBind,
00287 OA_ptr<CalleeToCallerVisitorIRInterface> ir)
00288 {
00289 OA_ptr<DataFlow::LocDFSet> retval;
00290 retval = new DataFlow::LocDFSet();
00291 if (debug) {
00292 std::cout << "callerToCalleeTransitive" << std::endl;
00293 }
00294
00295
00296 OA_ptr<Alias::Interface> alias = interAlias->getAliasResults(caller);
00297
00298
00299 OA_ptr<SymHandleIterator> symIter = paramBind->getFormalIterator(callee);
00300 for (; symIter->isValid(); (*symIter)++ ) {
00301 SymHandle formal = symIter->current();
00302
00303
00304
00305 ExprHandle expr = paramBind->getActualExprHandle(call,formal);
00306 OA_ptr<ExprTree> eTree = paramBind->getActualExprTree(expr);
00307
00308
00309 MemRefsVisitor eTreeVisitor;
00310 eTree->acceptVisitor(eTreeVisitor);
00311 if (debug) { eTree->dump(std::cout,ir); }
00312 if ( !eTreeVisitor.hasMemRef() ) {
00313 continue;
00314 }
00315
00316 OA_ptr<MemRefHandleIterator> memrefIter;
00317 memrefIter = eTreeVisitor.getMemRefsIterator();
00318 for (; memrefIter->isValid(); (*memrefIter)++ ) {
00319 MemRefHandle memref = memrefIter->current();
00320 if (debug) {
00321 std::cout << "\t caller memref = " << ir->toString(memref)
00322 << std::endl;
00323 }
00324
00325
00326 OA_ptr<LocIterator> locIter = alias->getMayLocs(memref);
00327 for ( ; locIter->isValid(); (*locIter)++ ) {
00328 OA_ptr<Location> loc = locIter->current();
00329 if (debug) {
00330 std::cout << "\t\tcaller mayloc for memref, loc = ";
00331 loc->dump(std::cout);
00332 }
00333 if (hasOverlapLoc(loc)) {
00334
00335
00336
00337 OA_ptr<Location> nloc;
00338 nloc = new NamedLoc(formal,true);
00339 retval->insert(nloc);
00340 if (debug) {
00341 std::cout << "\t\thasOverlapLoc so inserting formal sym = "
00342 << ir->toString(formal) << std::endl;
00343 }
00344 }
00345 }
00346 }
00347 }
00348 return retval;
00349 }
00350
00353 OA_ptr<LocDFSet> LocDFSet::calleeToCaller(ProcHandle callee, CallHandle call,
00354 ProcHandle caller,
00355 OA_ptr<Alias::InterAliasInterface> interAlias,
00356 OA_ptr<ParamBindings> paramBind,
00357 OA_ptr<CalleeToCallerVisitorIRInterface> ir)
00358 {
00359 OA_ptr<DataFlow::LocDFSet> retval;
00360 retval = new DataFlow::LocDFSet();
00361 if (debug) {
00362 std::cout << "calleeToCaller" << std::endl;
00363 }
00364
00365
00366
00367 OA_ptr<DataFlow::CalleeToCallerVisitor> locVisitor;
00368 locVisitor = new DataFlow::CalleeToCallerVisitor(callee, call,
00369 caller, interAlias, paramBind, ir);
00370
00371 OA_ptr<LocIterator> locIter = getLocIterator();
00372 for ( ; locIter->isValid(); (*locIter)++ ) {
00373 OA_ptr<Location> loc = locIter->current();
00374 loc->acceptVisitor(*locVisitor);
00375 OA_ptr<LocIterator> callerLoc = locVisitor->getCallerLocIterator();
00376 for ( ; callerLoc->isValid(); (*callerLoc)++ ) {
00377 retval->insert(callerLoc->current());
00378 }
00379 }
00380
00381
00382 return retval;
00383 }
00384
00387 OA_ptr<LocDFSet> LocDFSet::calleeToCallerTransitive(ProcHandle callee,
00388 CallHandle call, ProcHandle caller,
00389 OA_ptr<Alias::InterAliasInterface> interAlias,
00390 OA_ptr<ParamBindings> paramBind,
00391 OA_ptr<CalleeToCallerVisitorIRInterface> ir)
00392 {
00393 OA_ptr<DataFlow::LocDFSet> retval;
00394 retval = new DataFlow::LocDFSet();
00395 if (debug) {
00396 std::cout << "calleeToCallerTransitive" << std::endl;
00397 }
00398
00399
00400 OA_ptr<Alias::Interface> alias = interAlias->getAliasResults(caller);
00401
00402
00403 OA_ptr<SymHandleIterator> symIter = paramBind->getFormalIterator(callee);
00404 for (; symIter->isValid(); (*symIter)++ ) {
00405 SymHandle formal = symIter->current();
00406 OA_ptr<Location> formalLoc;
00407 formalLoc = new NamedLoc(formal,true);
00408
00409
00410 if (hasOverlapLoc(formalLoc)) {
00411
00412
00413
00414 ExprHandle expr = paramBind->getActualExprHandle(call,formal);
00415 OA_ptr<ExprTree> eTree = paramBind->getActualExprTree(expr);
00416
00417
00418 MemRefsVisitor eTreeVisitor;
00419 eTree->acceptVisitor(eTreeVisitor);
00420 if (debug) { eTree->dump(std::cout,ir); }
00421 if ( !eTreeVisitor.hasMemRef() ) {
00422 continue;
00423 }
00424
00425 OA_ptr<MemRefHandleIterator> memrefIter;
00426 memrefIter = eTreeVisitor.getMemRefsIterator();
00427 for (; memrefIter->isValid(); (*memrefIter)++ ) {
00428 MemRefHandle memref = memrefIter->current();
00429 if (debug) {
00430 std::cout << "\t caller memref = " << ir->toString(memref)
00431 << std::endl;
00432 }
00433
00434
00435 OA_ptr<LocIterator> locIter = alias->getMayLocs(memref);
00436 for ( ; locIter->isValid(); (*locIter)++ ) {
00437 OA_ptr<Location> loc = locIter->current();
00438 if (debug) {
00439 std::cout << "\t\tcaller mayloc for memref, loc = ";
00440 loc->dump(std::cout);
00441 }
00442
00443 retval->insert(loc);
00444 }
00445 }
00446 }
00447 }
00448 return retval;
00449 }
00450
00456 OA_ptr<LocDFSet> LocDFSet::callerToCalleeNot(ProcHandle caller,
00457 CallHandle call, ProcHandle callee,
00458 OA_ptr<Alias::InterAliasInterface> interAlias,
00459 OA_ptr<ParamBindings> paramBind,
00460 OA_ptr<CalleeToCallerVisitorIRInterface> ir)
00461 {
00462
00463 LocDFSet killSet;
00464
00465 OA_ptr<LocDFSet> retval;
00466
00467
00468 OA_ptr<Alias::Interface> callerAlias = interAlias->getAliasResults(caller);
00469
00470 OA_ptr<Alias::Interface> calleeAlias = interAlias->getAliasResults(callee);
00471
00472 if (debug) {
00473 std::cout << "++++++++ LocDFSet::callerToCalleeNot()\n";
00474 std::cout << " actual ExprTrees to formal may locations:";
00475 }
00476
00477 OA_ptr<ExprHandleIterator> exprIter;
00478 exprIter = paramBind->getActualExprHandleIterator(call);
00479 for (; exprIter->isValid(); (*exprIter)++) {
00480 ExprHandle expr = exprIter->current();
00481 OA_ptr<ExprTree> eTree = paramBind->getActualExprTree(expr);
00482
00483
00484 MemRefHandle memref;
00485 EvalToMemRefVisitor evalVisitor;
00486 eTree->acceptVisitor(evalVisitor);
00487 if (debug) {
00488 eTree->output(*ir);
00489 }
00490 if ( evalVisitor.isMemRef() ) {
00491 memref = evalVisitor.getMemRef();
00492 if (debug) {
00493 std::cout << " MemRef: "
00494 << ir->toString(memref)
00495 << std::endl;
00496 }
00497 } else {
00498 if (debug) {
00499 std::cout << " No MemRef at top of ExprTree\n";
00500 }
00501 continue;
00502 }
00503
00504 SymHandle sym_formal = paramBind->getCalleeFormal(call,memref,callee);
00505 if (debug) {
00506 std::cout << " formal: " << ir->toString(sym_formal)
00507 << std::endl;
00508 }
00509
00510
00511 OA_ptr<MemRefExprIterator> mreIter;
00512 mreIter = ir->getMemRefExprIterator(memref);
00513 for (; mreIter->isValid(); (*mreIter)++) {
00514 OA_ptr<MemRefExpr> mre_actual = mreIter->current();
00515
00516 OA_ptr<MemRefExpr> deref_mre = mre_actual->clone();
00517 bool found_locs = true;
00518 int numDerefs = 0;
00519
00520
00521
00522 while (found_locs) {
00523 found_locs = false;
00524
00525
00526 OA_ptr<MemRefExpr> nullmre;
00527 OA_ptr<Deref> deref;
00528 deref = new Deref(MemRefExpr::USE,nullmre,1);
00529 deref_mre = deref->composeWith(deref_mre);
00530 numDerefs++;
00531
00532 if (debug) {
00533 std::cout << "\t\tgetting maylocs from caller for deref_mre = ";
00534 deref_mre->output(*ir);
00535 std::cout << std::endl;
00536 }
00537
00538 OA_ptr<LocIterator> mayLocIter;
00539 mayLocIter = callerAlias->getMayLocs(*deref_mre,caller);
00540 for (; mayLocIter->isValid(); (*mayLocIter)++) {
00541 found_locs = true;
00542 OA_ptr<Location> loc = mayLocIter->current();
00543 if (debug) {
00544 std::cout << "\t\tmayloc for memref, loc = ";
00545 loc->output(*ir);
00546 }
00547
00548
00549 if (hasOverlapLoc(loc)) {
00550
00551 if (debug) {
00552 std::cout << "\t\t\tcaller LocDFSet hasOverlapLoc(loc)\n";
00553 }
00554
00555
00556 OA_ptr<MemRefExpr> mre_final;
00557 OA_ptr<NamedRef> mre_formal;
00558 mre_formal = new NamedRef(MemRefExpr::USE,
00559 sym_formal);
00560 mre_final = mre_formal->clone();
00561
00562
00563 for (int i = 0; i < numDerefs; i++) {
00564
00565 OA_ptr<MemRefExpr> nullmre;
00566 OA_ptr<Deref> deref;
00567 deref = new Deref(MemRefExpr::USE,nullmre,1);
00568 mre_final = deref->composeWith(mre_final);
00569 }
00570
00571 if (debug) {
00572 std::cout << "\t\tquerying callee with mre_final = ";
00573 mre_final->output(*ir);
00574 std::cout << std::endl;
00575 }
00576
00577
00578 OA_ptr<LocIterator> mayLocIter;
00579 mayLocIter = calleeAlias->getMayLocs(*mre_final,callee);
00580 if (mayLocIter->isValid()) {
00581
00582
00583 OA_ptr<LocIterator> locIter = getOverlapLocIterator(loc);
00584 for (; locIter->isValid(); (*locIter)++) {
00585 if (debug) {
00586 std::cout << "\t\tinserting loc into kill set: ";
00587 (locIter->current())->output(*ir);
00588 std::cout << "\n";
00589 }
00590
00591 killSet.insert(locIter->current());
00592 }
00593 }
00594 }
00595 }
00596 }
00597 }
00598 }
00599
00600 if (debug) {
00601 std::cout << "\n\t\tkill Set:";
00602 killSet.output(*ir);
00603 std::cout << "\n";
00604 }
00605
00606 retval = new LocDFSet((*this).setDifference(killSet));
00607 if (debug) {
00608 std::cout << "\n\t\tDifference Set: ";
00609 retval->output(*ir);
00610 std::cout << "\n";
00611 }
00612
00613 return retval;
00614 }
00615
00616 void LocDFSet::dump(std::ostream &os)
00617 {
00618 os << "\nLocDFSet: mapValid = " << mBaseLocToSetMapValid << "\n\t mSet = ";
00619
00620 OA_ptr<LocIterator> locIter = getLocIterator();
00621 for ( ; locIter->isValid(); (*locIter)++ ) {
00622 OA_ptr<Location> loc = locIter->current();
00623 loc->dump(os);
00624 os << ", ";
00625 }
00626 os << std::endl;
00627 os << "\tmInvLocs = ";
00628 LocSet::iterator lIter;
00629 lIter = (*mInvLocs).begin();
00630 for ( ; lIter!=(*mInvLocs).end(); lIter++ ) {
00631 OA_ptr<Location> loc = *lIter;
00632 loc->dump(os);
00633 os << ", ";
00634 }
00635 os << std::endl;
00636 os << "\tmBaseLoc to SetMap: ";
00637 std::map<IRHandle,OA_ptr<LocSet> >::iterator mapIter;
00638 mapIter = mBaseLocToSetMap.begin();
00639 for ( ; mapIter!=mBaseLocToSetMap.end(); mapIter++) {
00640 OA_ptr<LocSet> lset = mapIter->second;
00641
00642 os << "\t\t\t loc set for sym: ";
00643 if (lset.ptrEqual(0)) {
00644 os << " empty set\n";
00645 } else {
00646 lIter = (*lset).begin();
00647 for ( ; lIter!=(*lset).end(); lIter++ ) {
00648 OA_ptr<Location> loc = *lIter;
00649 loc->dump(os);
00650 os << ", ";
00651 }
00652 }
00653 }
00654 os << "\nend of LocDFSet dump --------------\n\n";
00655 }
00656
00657
00658
00659 void LocDFSet::dump(std::ostream &os, OA_ptr<IRHandlesIRInterface> ir)
00660 {
00661 os << "\nLocDFSet: mapValid = " << mBaseLocToSetMapValid << "\n\t mSet = ";
00662
00663 OA_ptr<LocIterator> locIter = getLocIterator();
00664 for ( ; locIter->isValid(); (*locIter)++ ) {
00665 OA_ptr<Location> loc = locIter->current();
00666 loc->dump(os,ir);
00667 os << ", ";
00668 }
00669 os << std::endl;
00670 os << "\tmInvLocs = ";
00671 LocSet::iterator lIter;
00672 lIter = (*mInvLocs).begin();
00673 for ( ; lIter!=(*mInvLocs).end(); lIter++ ) {
00674 OA_ptr<Location> loc = *lIter;
00675 loc->dump(os);
00676 os << ", ";
00677 }
00678 os << std::endl;
00679 os << "\tmBaseLoc to SetMap: ";
00680 std::map<IRHandle,OA_ptr<LocSet> >::iterator mapIter;
00681 mapIter = mBaseLocToSetMap.begin();
00682 for ( ; mapIter!=mBaseLocToSetMap.end(); mapIter++) {
00683 OA_ptr<LocSet> lset = mapIter->second;
00684
00685 os << "\t\t\t loc set for sym: ";
00686 if (lset.ptrEqual(0)) {
00687 os << " empty set\n";
00688 } else {
00689 lIter = (*lset).begin();
00690 for ( ; lIter!=(*lset).end(); lIter++ ) {
00691 OA_ptr<Location> loc = *lIter;
00692 loc->dump(os);
00693 os << ", ";
00694 }
00695 }
00696 }
00697 os << "\nend of LocDFSet dump --------------\n\n";
00698 }
00699
00700 void LocDFSet::output(OA::IRHandlesIRInterface& ir)
00701 {
00702
00703 sOutBuild->listStart();
00704 OA_ptr<LocIterator> locIter = getLocIterator();
00705 for ( ; locIter->isValid(); (*locIter)++ ) {
00706 OA_ptr<Location> loc = locIter->current();
00707 sOutBuild->listItemStart();
00708 loc->output(ir);
00709
00710
00711
00712 sOutBuild->listItemEnd();
00713 }
00714 sOutBuild->listEnd();
00715 }
00716
00717 void
00718 LocDFSet::associateWithBaseHandle(IRHandle baseHandle, OA_ptr<Location> loc)
00719 {
00720 if (mBaseLocToSetMap[baseHandle].ptrEqual(0)) {
00721 mBaseLocToSetMap[baseHandle] = new LocSet;
00722 }
00723 mBaseLocToSetMap[baseHandle]->insert(loc);
00724 }
00725
00726
00727
00728 void LocDFSet::addToMap(OA_ptr<Location> loc)
00729 {
00730
00731 OA_ptr<Location> baseLoc = loc->getBaseLoc();
00732
00733
00734 if (baseLoc->isaNamed()) {
00735 OA_ptr<NamedLoc> namedLoc = baseLoc.convert<NamedLoc>();
00736 associateWithBaseHandle(namedLoc->getSymHandle(), loc);
00737
00738 OA_ptr<SymHandleIterator> symIter = namedLoc->getFullOverlapIter();
00739 for ( ; symIter->isValid(); (*symIter)++ ) {
00740 associateWithBaseHandle(symIter->current(), loc);
00741 }
00742 symIter = namedLoc->getPartOverlapIter();
00743 for ( ; symIter->isValid(); (*symIter)++ ) {
00744 associateWithBaseHandle(symIter->current(), loc);
00745 }
00746
00747
00748 } else if (baseLoc->isaUnnamed()) {
00749 OA_ptr<UnnamedLoc> unnamedLoc = baseLoc.convert<UnnamedLoc>();
00750 associateWithBaseHandle(unnamedLoc->getExprHandle(), loc);
00751
00752
00753 } else if (baseLoc->isaInvisible()) {
00754 mInvLocs->insert(loc);
00755
00756
00757 } else if (baseLoc->isaUnknown()) {
00758 mHasUnknownLoc = true;
00759 }
00760
00761 }
00762
00763 void LocDFSet::insert(OA_ptr<Location> loc)
00764 {
00765 if ( ! hasLoc(loc) ) {
00766 mSetPtr->insert(loc);
00767 addToMap(loc);
00768 }
00769 }
00770
00771
00772 void
00773 LocDFSet::disassociateWithBaseHandle(IRHandle baseHandle, OA_ptr<Location> loc)
00774 {
00775 if (!mBaseLocToSetMap[baseHandle].ptrEqual(0)) {
00776 mBaseLocToSetMap[baseHandle]->erase(loc);
00777 }
00778 }
00779
00780 void LocDFSet::removeFromMap(OA_ptr<Location> loc)
00781 {
00782
00783 OA_ptr<Location> baseLoc = loc->getBaseLoc();
00784
00785
00786 if (baseLoc->isaNamed()) {
00787 OA_ptr<NamedLoc> namedLoc = baseLoc.convert<NamedLoc>();
00788 disassociateWithBaseHandle(namedLoc->getSymHandle(), loc);
00789
00790 OA_ptr<SymHandleIterator> symIter = namedLoc->getFullOverlapIter();
00791 for ( ; symIter->isValid(); (*symIter)++ ) {
00792 disassociateWithBaseHandle(symIter->current(), loc);
00793 }
00794 symIter = namedLoc->getPartOverlapIter();
00795 for ( ; symIter->isValid(); (*symIter)++ ) {
00796 disassociateWithBaseHandle(symIter->current(), loc);
00797 }
00798
00799
00800 } else if (baseLoc->isaUnnamed()) {
00801 OA_ptr<UnnamedLoc> unnamedLoc = baseLoc.convert<UnnamedLoc>();
00802 disassociateWithBaseHandle(unnamedLoc->getExprHandle(), loc);
00803
00804
00805 } else if (baseLoc->isaInvisible()) {
00806 mInvLocs->erase(loc);
00807
00808
00809 } else if (baseLoc->isaUnknown()) {
00810 mHasUnknownLoc = false;
00811 }
00812 }
00813
00814 void LocDFSet::remove(OA_ptr<Location> loc)
00815 {
00816 if ( hasLoc(loc) ) {
00817 mSetPtr->erase(loc);
00818 removeFromMap(loc);
00819 }
00820 }
00821
00823 bool LocDFSet::empty() { return mSetPtr->empty(); }
00824
00825 void LocDFSet::updateMap()
00826 {
00827 mBaseLocToSetMap.clear();
00828
00829 OA_ptr<LocIterator> locIter = getLocIterator();
00830 for ( ; locIter->isValid(); (*locIter)++ ) {
00831 addToMap(locIter->current());
00832 }
00833
00834 mBaseLocToSetMapValid = true;
00835
00836 }
00837
00839 bool LocDFSet::setHasOverlapLoc(OA_ptr<Location> loc, OA_ptr<LocSet> aSet)
00840 {
00841 LocSet::iterator locIter;
00842
00843 if (! aSet.ptrEqual(0) ) {
00844 for (locIter=aSet->begin(); locIter!=aSet->end(); locIter++) {
00845 OA_ptr<Location> temp = *locIter;
00846 if (loc->mayOverlap(*temp)) {
00847 return true;
00848 }
00849 }
00850 }
00851
00852 return false;
00853 }
00854
00855
00858 bool LocDFSet::hasOverlapLoc(OA_ptr<Location> loc)
00859 {
00860
00861 if (!mBaseLocToSetMapValid) {
00862 updateMap();
00863 }
00864
00865 if (mHasUnknownLoc) {
00866 return true;
00867 }
00868
00869 std::map<IRHandle,OA_ptr<LocSet> >::iterator mapIter;
00870
00871
00872 OA_ptr<Location> baseLoc = loc->getBaseLoc();
00873
00874
00875 if (baseLoc->isaNamed()) {
00876 OA_ptr<NamedLoc> namedLoc = baseLoc.convert<NamedLoc>();
00877 bool result = false;
00878 std::map<IRHandle,OA_ptr<LocSet> >::iterator mapIter;
00879 mapIter = mBaseLocToSetMap.find(namedLoc->getSymHandle());
00880 if ( mapIter != mBaseLocToSetMap.end()) {
00881 result = setHasOverlapLoc(loc, mapIter->second);
00882 }
00883 return result;
00884
00885
00886 } else if (baseLoc->isaUnnamed()) {
00887 OA_ptr<UnnamedLoc> unnamedLoc = baseLoc.convert<UnnamedLoc>();
00888 bool result = false;
00889 mapIter = mBaseLocToSetMap.find(unnamedLoc->getExprHandle());
00890 if ( mapIter != mBaseLocToSetMap.end()) {
00891 result = setHasOverlapLoc(loc, mapIter->second);
00892 }
00893 return result;
00894
00895
00896 } else if (baseLoc->isaInvisible()) {
00897 return setHasOverlapLoc(loc, mInvLocs);
00898
00899
00900 } else if (baseLoc->isaUnknown()) {
00901 return true;
00902 }
00903
00904 }
00905
00907 OA_ptr<LocDFSet>
00908 LocDFSet::overlapLocSet(OA_ptr<Location> loc, OA_ptr<LocSet> aSet)
00909 {
00910 OA_ptr<LocDFSet> retset;
00911 retset = new LocDFSet();
00912
00913 if (! aSet.ptrEqual(0) ) {
00914 LocSet::iterator locIter;
00915 for (locIter=aSet->begin(); locIter!=aSet->end(); locIter++) {
00916 OA_ptr<Location> temp = *locIter;
00917 if (loc->mayOverlap(*temp)) {
00918 retset->insert(temp);
00919 }
00920 }
00921 }
00922
00923 return retset;
00924 }
00925
00927 OA_ptr<LocIterator> LocDFSet::getOverlapLocIterator(OA_ptr<Location> loc)
00928 {
00929
00930 if (!mBaseLocToSetMapValid) {
00931 updateMap();
00932 }
00933
00934 OA_ptr<LocDFSet> retset;
00935 retset = new LocDFSet();
00936
00937 if (loc->isaUnknown() ) {
00938
00939 return getLocIterator();
00940 }
00941
00942
00943 if (mHasUnknownLoc) {
00944 OA_ptr<Location> unknown;
00945 unknown = new UnknownLoc();
00946 retset->insert(unknown);
00947 }
00948
00949
00950 OA_ptr<Location> baseLoc = loc->getBaseLoc();
00951
00952
00953 if (baseLoc->isaNamed()) {
00954 OA_ptr<NamedLoc> namedLoc = baseLoc.convert<NamedLoc>();
00955 OA_ptr<LocDFSet> tempSet = overlapLocSet(loc,
00956 mBaseLocToSetMap[namedLoc->getSymHandle()]) ;
00957 retset->setUnion( *tempSet );
00958
00959
00960 } else if (baseLoc->isaUnnamed()) {
00961 OA_ptr<UnnamedLoc> unnamedLoc = baseLoc.convert<UnnamedLoc>();
00962 OA_ptr<LocDFSet> tempSet = overlapLocSet(loc,
00963 mBaseLocToSetMap[unnamedLoc->getExprHandle()]);
00964 retset->setUnion( *tempSet );
00965
00966
00967 } else if (baseLoc->isaInvisible()) {
00968 OA_ptr<LocDFSet> tempSet = overlapLocSet(loc, mInvLocs);
00969 retset->setUnion( *tempSet );
00970 }
00971
00972 OA_ptr<LocDFSetIterator> retval;
00973 retval = new LocDFSetIterator(*retset);
00974 return retval;
00975 }
00976
00978 bool LocDFSet::hasLoc(OA_ptr<Location> loc)
00979 {
00980 return mSetPtr->find(loc)!=mSetPtr->end();
00981 }
00982
00984 OA_ptr<LocIterator> LocDFSet::getLocIterator()
00985 {
00986 OA_ptr<LocDFSetIterator> retval;
00987 retval = new LocDFSetIterator(*this);
00988 return retval;
00989 }
00990
00991
00992 }
00993 }
00994