LocDFSet.cpp

Go to the documentation of this file.
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; // recreate map if/when needed
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 // param for these can't be const because will have to 
00054 // dynamic cast to specific subclass
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   // get alias results for caller procedure
00120   OA_ptr<Alias::Interface> callerAlias = interAlias->getAliasResults(caller);
00121   // get alias results for callee procedure
00122   OA_ptr<Alias::Interface> calleeAlias = interAlias->getAliasResults(callee);
00123 
00124   /***********
00125    * new pseudocode for callerToCallee 7/28/06
00126    * for each actual exprTree, act_etree 
00127    *   if there is a MemRefHandle at the top of act_etree put in memref 
00128    *     for each mre for memref, ir->getMemRefExprIterator 
00129    *       found_locs = true 
00130    *       deref_mre = mre clone
00131    *       while (found_locs) 
00132    *         found_locs = false 
00133    *         deref = new Deref of null memref
00134    *         deref_mre = deref->composeWith(deref_mre) 
00135    *         query the alias analysis of Caller for maylocs of deref_mre  
00136    *         for each mayLoc 
00137    *           found_locs = true 
00138    *           if mayloc mayOverlaps with anything in our LocDFSet 
00139    *                                                      (from caller) 
00140    *             -get mre_formal for mre_actual 
00141    *             -create as many derefs on the callee side as you did on the 
00142    *                caller side (just keep calling deref->composeWith on what 
00143    *                you have so far) to get a final_mre. 
00144    *             -query the alias analysis of Callee for maylocs of final_mre 
00145    *             -for each calleeMayLoc 
00146    *               -add mayloc to callee locDFSet 
00147    *************
00148    */
00149 
00150   if (debug) {
00151     std::cout << "++++++++ LocDFSet::callerToCallee()\n";
00152     std::cout << "    actual ExprTrees to formal may locations:";
00153   }
00154   // iterate over all actual parameter ExprTrees in the call
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     // if there is a MemRefHandle at the top of this ExprTree
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     // for each MemRefExpr of this MemRefHandle
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(); //priming the pump
00195       bool found_locs = true;
00196       int numDerefs = 0;
00197 
00198       // loop to find all locations (on the callee side) that may overlap
00199       // with this actual mre (from the caller side)
00200       while (found_locs) {
00201         found_locs = false;
00202 
00203         // Deref mre
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         // query the alias analysis of Caller for maylocs of deref_mre  
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           // if loc mayOverlaps with anything in our LocDFSet (from caller)
00227           if (hasOverlapLoc(loc)) {
00228 
00229             if (debug) {
00230               std::cout << "\t\t\tcaller LocDFSet hasOverlapLoc(loc) true\n";
00231             }
00232             
00233             // get mre_formal for mre_actual
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             // duplicate the number of derefs on callee side as on caller side
00240             for (int i = 0; i < numDerefs; i++) {
00241               // Deref mre
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             // query the alias analysis of Callee for maylocs of mre_final 
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               // add mayloc to callee locDFSet
00264               retval->insert(mayloc);
00265             }
00266           } // end if (hasOverlapLoc(loc))
00267           else {
00268             if (debug) { 
00269               std::cout << "caller LocDFSet hasOverlapLoc(loc) false" << std::endl;
00270             }
00271           }
00272 
00273         } // end of foreach caller-mayloc 
00274       } // end of while (found_locs)
00275     } // end of foreach mre_actual
00276   } // end of foreach actual ExprTree in call
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   // get alias results for caller procedure
00296   OA_ptr<Alias::Interface> alias = interAlias->getAliasResults(caller);
00297   
00298   // iterate over the formal SymHandles of the callee proc
00299   OA_ptr<SymHandleIterator> symIter = paramBind->getFormalIterator(callee);
00300   for (; symIter->isValid(); (*symIter)++ ) {
00301     SymHandle formal = symIter->current();
00302     
00303     // get ExprTrees of the actual parameters for the call
00304     // transitive:  so step into ExprTrees to get all MemRefs
00305     ExprHandle expr = paramBind->getActualExprHandle(call,formal);
00306     OA_ptr<ExprTree> eTree = paramBind->getActualExprTree(expr);
00307     
00308     // get all memrefs in the actual ExprTree
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       // loop over may locs for the memref
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           //assert(0);  // see MMS
00335           //symHandle sym;  // already have the sym handle for formal, above
00336           //SymHandle sym = paramBind->getCalleeFormal(call,memref);
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       } // end of loop over caller maylocs for a memref
00346     } // end of loop over caller memrefhandles assoc. with formal symhandle
00347   } // end of loop over formal symhandles
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     // have visitor convert all locations into aliased locations in
00366     // the caller
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     // BK: don't need extra loop to find non-locals, handled in 
00381     // CalleeToCallerVisitor, above
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   // get alias results for caller procedure
00400   OA_ptr<Alias::Interface> alias = interAlias->getAliasResults(caller);
00401   
00402   // iterate over the formal SymHandles of the callee proc
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     // if callee LocDFSet has any locs that may overlap with formal loc
00410     if (hasOverlapLoc(formalLoc)) {
00411       
00412       // get ExprTrees of the actual parameters for the call
00413       // transitive:  so step into ExprTrees to get all MemRefs
00414       ExprHandle expr = paramBind->getActualExprHandle(call,formal);
00415       OA_ptr<ExprTree> eTree = paramBind->getActualExprTree(expr);
00416       
00417       // get all memrefs in the actual ExprTree
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         // loop over may locs for the memref
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           // insert mayloc into caller LocDFSet
00443           retval->insert(loc);
00444         }
00445       }
00446     } // end of if (hasOverlapLoc)
00447   }// end of loop over formal symhandles
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   // get alias results for caller procedure
00468   OA_ptr<Alias::Interface> callerAlias = interAlias->getAliasResults(caller);
00469   // get alias results for callee procedure
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   // iterate over all actual parameter ExprTrees in the call
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     // if there is a MemRefHandle at the top of this ExprTree
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     // for each MemRefExpr of this MemRefHandle
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(); //priming the pump
00517       bool found_locs = true;
00518       int numDerefs = 0;
00519 
00520       // loop to find all locations (on the callee side) that may overlap
00521       // with this actual mre (from the caller side)
00522       while (found_locs) {
00523         found_locs = false;
00524 
00525         // Deref mre
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         // query the alias analysis of Caller for maylocs of deref_mre  
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           // if loc mayOverlaps with anything in our LocDFSet (from caller)
00549           if (hasOverlapLoc(loc)) {
00550 
00551             if (debug) {
00552               std::cout << "\t\t\tcaller LocDFSet hasOverlapLoc(loc)\n";
00553             }
00554             
00555             // get mre_formal for mre_actual
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             // duplicate the number of derefs on callee side as on caller side
00563             for (int i = 0; i < numDerefs; i++) {
00564               // Deref mre
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             // query the alias analysis of Callee for maylocs of mre_final 
00578             OA_ptr<LocIterator> mayLocIter;
00579             mayLocIter = calleeAlias->getMayLocs(*mre_final,callee);
00580             if (mayLocIter->isValid()) {
00581               // then there was at least one mayLoc added to the callee
00582               // set for this caller loc:  add mayLocs(loc) to kill set
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           } // end if (hasOverlapLoc(loc))
00595         } // end of foreach caller-mayloc 
00596       } // end of while (found_locs)
00597     } // end of foreach mre_actual
00598   } // end of foreach actual ExprTree in call
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   // iterate over IRHandle's and have the IR print them out
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     //os << "\t\t symhandle: " << mapIter->first;
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     // iterate over IRHandle's and have the IR print them out
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       //os << "\t\t symhandle: " << ir->toString(mapIter->first);
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   // iterate over IRHandle's and have the IR print them out
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       //      ostringstream separator;
00710       //      separator << "," << indt;
00711       //      sOutBuild->outputString(separator.str());
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 // NOTE: can't use a visitor because will be inserting loc into
00727 // sets that want OA_ptrs.  More compact this way anyway.
00728 void LocDFSet::addToMap(OA_ptr<Location> loc)
00729 {
00730     // get the base location
00731     OA_ptr<Location> baseLoc = loc->getBaseLoc();
00732 
00733     // Named Location
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     // UnnamedLoc
00748     } else if (baseLoc->isaUnnamed()) {
00749         OA_ptr<UnnamedLoc> unnamedLoc = baseLoc.convert<UnnamedLoc>();
00750         associateWithBaseHandle(unnamedLoc->getExprHandle(), loc);
00751 
00752     // InvisibleLoc
00753     } else if (baseLoc->isaInvisible()) {
00754         mInvLocs->insert(loc);
00755 
00756     // UnknownLoc
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     // get the base location
00783     OA_ptr<Location> baseLoc = loc->getBaseLoc();
00784 
00785     // Named Location
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     // UnnamedLoc
00800     } else if (baseLoc->isaUnnamed()) {
00801         OA_ptr<UnnamedLoc> unnamedLoc = baseLoc.convert<UnnamedLoc>();
00802         disassociateWithBaseHandle(unnamedLoc->getExprHandle(), loc);
00803 
00804     // InvisibleLoc
00805     } else if (baseLoc->isaInvisible()) {
00806         mInvLocs->erase(loc);
00807 
00808     // UnknownLoc
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     // make sure the map is up-to-date
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     // get the base location
00872     OA_ptr<Location> baseLoc = loc->getBaseLoc();
00873 
00874     // Named Location
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     // UnnamedLoc
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     // InvisibleLoc
00896     } else if (baseLoc->isaInvisible()) {
00897         return setHasOverlapLoc(loc, mInvLocs);
00898 
00899     // UnknownLoc
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     // make sure the map is up-to-date
00930     if (!mBaseLocToSetMapValid) {
00931         updateMap();
00932     }
00933 
00934     OA_ptr<LocDFSet> retset;
00935     retset = new LocDFSet();
00936 
00937     if (loc->isaUnknown() ) {
00938         // iterator over all locations in this set
00939         return getLocIterator();
00940     }
00941 
00942     // add the unknown location if it is in this set
00943     if  (mHasUnknownLoc) {
00944         OA_ptr<Location> unknown;
00945         unknown = new UnknownLoc();
00946         retset->insert(unknown);
00947     }
00948 
00949     // get the base location
00950     OA_ptr<Location> baseLoc = loc->getBaseLoc();
00951 
00952     // Named Location
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     // UnnamedLoc
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     // InvisibleLoc
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   } // end of DataFlow namespace
00993 } // end of OA namespace
00994 

Generated on Sat Oct 31 05:21:22 2009 for OpenAnalysis by  doxygen 1.6.1