ManagerFIAlias.cpp

Go to the documentation of this file.
00001 
00016 #include "ManagerFIAlias.hpp"
00017 #include <Utils/Util.hpp>
00018 
00019 namespace OA {
00020   namespace Alias {
00021 
00022 static bool debug = false;
00023 
00024 ProcHandle AnalyzedProcIterator::current() const { return *mIt; }
00025 bool AnalyzedProcIterator::isValid() const { return ( mIt != mAnalyzedProcs.end());  }
00026 void AnalyzedProcIterator::operator++() { mIt++; }
00027 void AnalyzedProcIterator::reset() { mIt = mAnalyzedProcs.begin(); }
00028 
00029 OA_ptr<IRProcIterator> ManagerFIAlias::getAnalyzedProcIter()
00030 {
00031   OA_ptr<AnalyzedProcIterator> iterator;
00032   iterator = new AnalyzedProcIterator(mAnalyzedProcs);
00033   return iterator;
00034 }
00035 
00036 OA_ptr<LocSetIterator> FixedLocationVisitor::getDirectRefLocIterator()
00037 {
00038   OA_ptr<LocSetIterator> locSetIter;
00039   locSetIter = new LocSetIterator(mDirectRefLocations);
00040   return locSetIter;
00041 }
00042 
00043 void FixedLocationVisitor::visitUnknownRef(UnknownRef& ref) 
00044 { 
00045   notDirect(); 
00046 }
00047     
00048 void FixedLocationVisitor::visitDeref(Deref& ref) 
00049 { 
00050   notDirect(); 
00051 }
00052 
00053 void FixedLocationVisitor::notDirect() 
00054 {
00055   mDirectRef = false;
00056   mDirectRefLocations->clear();
00057 }
00058 
00059 
00060 void FixedLocationVisitor::visitAddressOf(AddressOf& ref)
00061 {
00062    notDirect();
00063 }
00064 
00065 
00066 void FixedLocationVisitor::visitNamedRef(NamedRef& ref) 
00067 {
00068     mLoc = mIR->getLocation(mProc,ref.getSymHandle());
00069     if (mLoc.ptrEqual(0)) {
00070       if (debug) {
00071         std::cout << "FixedLocationVisitor::visitNamedRef, mLoc is null" 
00072                   << std::endl;
00073         std::cout << "\tmProc = " << mIR->toString(mProc) << std::endl;
00074       }
00075       notDirect();
00076     } else {
00077       if (debug) {
00078         std::cout << "FixedLocationVisitor::visitNamedRef, mLoc is direct" 
00079                   << std::endl;
00080         std::cout << "\tmProc = " << mIR->toString(mProc) << std::endl;
00081       }
00082       mDirectRef = true;
00083 
00084       mDirectRefLocations->insert(mLoc);
00085     }
00086 
00087 }
00088 
00089 void FixedLocationVisitor::visitUnnamedRef(UnnamedRef& ref) 
00090 { 
00091     mDirectRef = true;
00092     // UnnamedLocs are not local
00093     mLoc = new UnnamedLoc(ref.getExprHandle(),ref.isLocal());
00094 
00095     if (mDirectRef) {
00096       mDirectRefLocations->insert(mLoc);
00097     }
00098 }
00099 
00100 void FixedLocationVisitor::visitSubSetRef(SubSetRef& ref) 
00101 {
00102   if (debug) { 
00103       std::cout << "In FixedLocationVisitor::visitSubSetRef" << std::endl;
00104   }
00105   // must also visit child memory reference
00106   OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
00107   if (!mre.ptrEqual(0)) {
00108        mre->acceptVisitor(*this);
00109   }     
00110   if(mDirectRef) {
00111        mLoc = new LocSubSet(mLoc,false);
00112        mDirectRefLocations->insert(mLoc);
00113   } 
00114     
00115 }
00116 
00117 
00118 void FixedLocationVisitor::visitFieldAccess(FieldAccess& ref) 
00119 {
00120   if (debug) { 
00121       std::cout << "In FixedLocationVisitor::visitFieldAccess" << std::endl;
00122   }
00123   // must also visit child memory reference
00124   OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
00125   if (!mre.ptrEqual(0)) {
00126        mre->acceptVisitor(*this);
00127   }     
00128   if(mDirectRef) {
00129         OA_ptr<LocFieldSubSet> loc;
00130         loc = new LocFieldSubSet(mLoc, ref.getFieldName());
00131         mLoc = loc;
00132         mDirectRefLocations->insert(mLoc);
00133   }
00134 }
00135 
00138 ManagerFIAlias::ManagerFIAlias( OA_ptr<AliasIRInterface> _ir) : mIR(_ir),
00139     mCount(1)
00140 {
00141     OA_DEBUG_CTRL_MACRO("DEBUG_ManagerFIAlias:ALL", debug);
00142 }
00143 
00146 void ManagerFIAlias::addProcToWorkList(ProcHandle proc)
00147 {
00148   if ( mImplement == REACHABLE_PROCS ) {
00149       if ( mAnalyzedProcs.find(proc) != 
00150            mAnalyzedProcs.end() ) {
00151           return;
00152       }
00153 
00154       if ( mWorklist.find(proc) != 
00155            mWorklist.end() ) {
00156           return;
00157       }
00158 
00159       mWorklist.insert(proc);
00160   }
00161 }
00162 
00170 class OuterRefOpVisitor : public virtual MemRefExprVisitor {
00171   public:
00172     OuterRefOpVisitor() {}
00173     ~OuterRefOpVisitor() {}
00174 
00175     OA_ptr<RefOp> getOuterRefOp() {
00176         return mOuterRefOp;
00177     }
00178     void visitNamedRef(NamedRef& ref) { 
00179     }
00180     void visitUnnamedRef(UnnamedRef& ref) { 
00181     }
00182     void visitUnknownRef(UnknownRef& ref) { 
00183     }
00184     void visitAddressOf(AddressOf& ref) {
00185         // this visitor shouldn't be called on an MRE
00186         // that has its address taken
00187         assert(0);
00188     }
00189     void visitDeref(Deref& ref) { 
00190         assert(ref.getNumDerefs()==1);
00191         OA_ptr<MemRefExpr> nullmre;
00192         mOuterRefOp = new Deref(MemRefExpr::USE, nullmre, 1);
00193     }
00194     // default handling of more specific SubSet specificiations
00195     void visitSubSetRef(SubSetRef& ref) { 
00196         OA_ptr<MemRefExpr> nullmre;
00197         mOuterRefOp = new SubSetRef(MemRefExpr::USE, nullmre);
00198     }
00199     void visitIdxAccess(IdxAccess& ref) { 
00200         OA_ptr<MemRefExpr> nullmre;
00201         OA_ptr<MemRefExpr> childMRE = ref.getMemRefExpr();
00202         assert(!childMRE.ptrEqual(0));
00203         mOuterRefOp = new IdxAccess(MemRefExpr::USE,
00204                                     nullmre, ref.getIdx());
00205 
00206     }
00207 
00208     void visitFieldAccess(FieldAccess& ref) { 
00209         OA_ptr<MemRefExpr> nullmre;
00210         OA_ptr<MemRefExpr> childMRE = ref.getMemRefExpr();
00211         assert(!childMRE.ptrEqual(0));
00212         mOuterRefOp = new FieldAccess(MemRefExpr::USE,
00213                                       nullmre, ref.getFieldName() );
00214     }
00215   
00216   private:
00217     OA_ptr<RefOp> mOuterRefOp;
00218 };
00219 
00220 
00221 bool InvisibleLocationVisitor::isInvisibleRef() 
00222 {
00223   return mInvisibleRef;
00224 }
00225 
00226 OA_ptr<Location> InvisibleLocationVisitor::getInvisibleRefLoc() 
00227 {
00228   return mLoc;
00229 }
00230 
00231 void InvisibleLocationVisitor::visitUnnamedRef(UnnamedRef& ref) 
00232 { 
00233   notInvisible(); 
00234 }
00235 
00236 void InvisibleLocationVisitor::visitUnknownRef(UnknownRef& ref) 
00237 { 
00238   notInvisible(); 
00239 }
00240 
00241 void InvisibleLocationVisitor::notInvisible() 
00242 {
00243   mInvisibleRef = false;
00244   OA_ptr<Location> nullLoc;
00245   mLoc = nullLoc;
00246 }
00247 
00248 void InvisibleLocationVisitor::visitAddressOf(AddressOf& ref)
00249 {
00250   notInvisible(); 
00251 }
00252 
00253 
00254 void InvisibleLocationVisitor::visitNamedRef(NamedRef& ref) 
00255 {
00256     // initialize result
00257     mInvisibleRef = false;
00258     mBaseIsNotLocal = false;
00259     mBaseIsFormal = false;
00260   
00261     mLoc = mIR->getLocation(mProc,ref.getSymHandle());
00262     // symbol isn't visible
00263     if (mLoc.ptrEqual(0)) {
00264       notInvisible();
00265     } else if (!mLoc->isLocal()) {
00266       mBaseIsNotLocal = true;
00267     } else if (mProcFormalSet.find(ref.getSymHandle()) 
00268                != mProcFormalSet.end() ) 
00269     {
00270       mBaseIsFormal = true;
00271     }
00272     // the location will be created on the outermost deref
00273 }
00274 
00275 void InvisibleLocationVisitor::visitDeref(Deref& ref) 
00276 { 
00277     // first call recursively on what we are a dereference for
00278     OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
00279     if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); }
00280     if (mBaseIsNotLocal || mBaseIsFormal) {
00281       mInvisibleRef = true;
00282       // we may not be outermost, but if we are then we need
00283       // to create invisible location.  If we aren't then 
00284       // another RefOp will replace mLoc
00285       
00286       mLoc = new InvisibleLoc(ref.clone());
00287     }
00288 }   
00289 
00290 void InvisibleLocationVisitor::visitSubSetRef(SubSetRef& ref) 
00291 {
00292   OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
00293   if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); }
00294    
00295   if (mInvisibleRef) {
00296     //mLoc = new InvisibleLoc(ref.clone());
00297     OA_ptr<LocSubSet> sloc;
00298     mLoc = new LocSubSet(mLoc, false);
00299   }
00300 }
00301 
00302 void InvisibleLocationVisitor::visitFieldAccess(FieldAccess& ref)
00303 {
00304   OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
00305   if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); }
00306 
00307   if (mInvisibleRef) {
00308     mLoc = new LocFieldSubSet(mLoc,ref.getFieldName());
00309   }
00310 }
00311 
00312 void InvisibleLocationVisitor::visitIdxAccess(IdxAccess& ref)
00313 {
00314   OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
00315   if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); }
00316 
00317   if (mInvisibleRef) {
00318     mLoc = new LocIdxSubSet(mLoc,ref.getIdx());
00319   }
00320 }
00321 
00322 void InvisibleLocationVisitor::visitIdxExprAccess(IdxExprAccess& ref)
00323 {
00324   OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
00325   if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); }
00326 
00327   if (mInvisibleRef) {
00328     mLoc = new LocSubSet(mLoc, false);
00329   }
00330 }
00331 
00332 //-------------------------------------------------------
00333 void VisibleBaseVisitor::visitUnknownRef(UnknownRef& ref) 
00334 { 
00335   mBaseVisible = true;
00336 }
00337     
00338 void VisibleBaseVisitor::visitDeref(Deref& ref) 
00339 { 
00340   // call recursively on what we are a dereference for
00341   OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
00342   if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); }
00343 }
00344 
00345 void VisibleBaseVisitor::visitAddressOf(AddressOf& ref)
00346 {
00347    //assert(0);
00348    mBaseVisible = false;
00349 }
00350 
00351 void VisibleBaseVisitor::visitNamedRef(NamedRef& ref) 
00352 {
00353     OA_ptr<Location> loc = mIR->getLocation(mProc,ref.getSymHandle());
00354     if (loc.ptrEqual(0)) {
00355       mBaseVisible = false;
00356     } else {
00357       mBaseVisible = true;
00358     }
00359 }
00360 
00361 void VisibleBaseVisitor::visitUnnamedRef(UnnamedRef& ref) 
00362 {
00363     mBaseVisible = false;
00364     if(ref.isLocal() == true) {
00365        if(ref.getProcHandle() == mProc) {
00366           mBaseVisible = true;
00367        } 
00368     } else {
00369        mBaseVisible = true; 
00370     }
00371 }
00372 
00373 void VisibleBaseVisitor::visitSubSetRef(SubSetRef& ref) 
00374 {
00375   mBaseVisible = true;  
00376   // call recursively on MemRefExpr encapsulated 
00377   // inside SubSetRef
00378   OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
00379   if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); }
00380 }
00381 
00382 /* MMS 3/25/07, we will need this routine if we ever decide to
00383  * resusitate ManagerFIAliasEquivSets, but it is not needed here
00384  *
00385 void ManagerFIAlias::mergeSubSetRefs(OA_ptr<UnionFindUniverse> ufset) {
00386 
00387      std::map<OA_ptr<MemRefExpr>,int>::iterator mapIter;
00388      for (mapIter=mMREToID.begin(); mapIter!=mMREToID.end(); mapIter++) {
00389           OA_ptr<MemRefExpr> mymre = mapIter->first;
00390               
00391           if(mymre->isaRefOp()) {  
00392             OA_ptr<RefOp> submre;
00393             submre = mymre.convert<RefOp>();
00394             if(submre->isaSubSetRef()) {
00395                OA_ptr<SubSetRef> recast = submre.convert<SubSetRef>();
00396                OA_ptr<MemRefExpr> child_mre;
00397                child_mre = recast->getMemRefExpr();
00398                ufset->Union( ufset->Find(mMREToID[mymre]),
00399                           ufset->Find(mMREToID[child_mre]),
00400                           ufset->Find(mMREToID[child_mre]) );
00401             } 
00402           }
00403      }
00404 }
00405 */
00406 
00407 void
00408 ManagerFIAlias::doPhase1Iteration(StmtHandle stmt, ProcHandle currProc, 
00409                                   OA_ptr<UnionFindUniverse> ufset)
00410 {
00411     // Perform Ryder Phase 1 on stmt.
00412 
00413     // for each ptrassignpair
00414     OA_ptr<PtrAssignPairStmtIterator> pairIter
00415         = mIR->getPtrAssignStmtPairIterator(stmt);
00416     for ( ; pairIter->isValid(); (*pairIter)++ ) {
00417 
00418         OA_ptr<MemRefExpr> target = pairIter->currentTarget();        
00419         OA_ptr<MemRefExpr> source = pairIter->currentSource();        
00420 
00421         // map *target and *source to an id if they don't already have one
00422         OA_ptr<MemRefExpr> sourceDeref, targetDeref;
00423 
00424         // make a deref version of target mre
00425         targetDeref = createDeref( target );
00426         recordMRE(targetDeref, currProc );
00427             
00428         // make a deref version of source mre
00429         sourceDeref = createDeref( source );
00430         recordMRE(sourceDeref, currProc );
00431              
00432         if (debug) {
00433             std::cout << "\tsourceDeref = ";
00434             sourceDeref->output(*mIR);
00435             std::cout << "\ttargetDeref = ";
00436             targetDeref->output(*mIR);
00437             std::cout << "\t===> Union ( "
00438                       << ufset->Find(mMREToID[targetDeref]) << ", "
00439                       << ufset->Find(mMREToID[sourceDeref]) << " )"
00440                       << std::endl;
00441         }
00442                 
00443         // then union the sets with *target and *source 
00444         ufset->Union( ufset->Find(mMREToID[targetDeref]),
00445                       ufset->Find(mMREToID[sourceDeref]),
00446                       ufset->Find(mMREToID[sourceDeref]) );
00447 
00448     } // iteration over ptr assign pairs
00449 
00450 }
00451 
00452 bool
00453 ManagerFIAlias::doPhase2Iteration(OA_ptr<UnionFindUniverse> ufset,
00454                                   std::map<int,std::map<OA_ptr<MemRefExpr>,int> > & map) 
00455 {
00456     bool changed = false;
00457 
00458     // for each memref
00459     std::map<OA_ptr<MemRefExpr>,int>::iterator mreMapIter;
00460     for (mreMapIter=mMREToID.begin(); 
00461          mreMapIter!=mMREToID.end(); mreMapIter++ ) 
00462     {
00463         OA_ptr<MemRefExpr> mre = mreMapIter->first;
00464         if (debug) {
00465             std::cout << std::endl << "\tmre = ";
00466             mre->output(*mIR);
00467             std::cout << "\t\tFind(mMREToID[mre]) = " 
00468                       << ufset->Find(mMREToID[mre]) << std::endl;
00469         }
00470 
00471         // only do the following for real MREs, if the MRE is part of
00472         // an addressOf operation then the outermost MRE doesn't involve
00473         // any memory being accessed
00474         if(mre->isaRefOp()) {
00475             OA_ptr<RefOp> refop = mre.convert<RefOp>();
00476             if(!refop->isaAddressOf()) {
00477                 OuterRefOpVisitor outerRefVisitor;
00478                 mre->acceptVisitor(outerRefVisitor);
00479                 OA_ptr<RefOp> justRefop = outerRefVisitor.getOuterRefOp();
00480                 OA_ptr<MemRefExpr> innerMRE = refop->getMemRefExpr();
00481 
00482                 if (debug) {
00483                     std::cout << "\t\tinnerMRE = ";
00484                     if (! innerMRE.ptrEqual(0) ) {
00485                         innerMRE->output(*mIR);
00486                     } else { 
00487                         std::cout << "<null MRE>" << std::endl;
00488                     }
00489                     std::cout << "\t\tFind( innerMRE ) = "
00490                               << ufset->Find(mMREToID[innerMRE])
00491                               << std::endl;
00492                     std::cout << "\t\tjustRefop = ";
00493                     if (! justRefop.ptrEqual(0) ) {
00494                         justRefop->output(*mIR);
00495                     } else { 
00496                         std::cout << "<null MREF>" << std::endl;
00497                     }
00498                 }
00499 
00500                 // if find(memref)!=find( map[find(innerMRE)][justRefop] )
00501                 int setID = ufset->Find( 
00502                     map[ufset->Find(mMREToID[innerMRE])][justRefop] );
00503                 if ( ufset->Find(mMREToID[mre]) != setID ) {
00504                     changed = true;
00505                     // if map[find(memref->getMemRef)][refop] is not in a part yet
00506                     if (setID == 0) {
00507                         // then put it in the one for memref
00508                         map[ufset->Find(mMREToID[innerMRE])][justRefop] 
00509                             = ufset->Find(mMREToID[mre]);
00510                     // else
00511                     } else {
00512                         merge(ufset->Find(mMREToID[mre]), setID, ufset, map);
00513                     }
00514                 }
00515             }// does not have address taken
00516         } // is a refop
00517     } // over mre
00518     return changed;
00519 }
00520 
00521 void 
00522 ManagerFIAlias::doPhase3Iteration(CallHandle call, ProcHandle currProc,
00523                                   OA_ptr<UnionFindUniverse> ufset,
00524                                   std::map<int,std::map<OA_ptr<MemRefExpr>,int> > & map)
00525 {
00526     // get the mre for the function call (eg. NamedRef('foo'))
00527     OA_ptr<MemRefExpr> callMRE = mIR->getCallMemRefExpr(call);
00528 
00529     // set of all MREs that are aliased with this callMRE
00530     std::set<OA_ptr<MemRefExpr> > aliasedMREs;
00531     aliasedMREs.insert(callMRE);
00532 
00533     // if it is a NamedRef then it can only be referring
00534     // to one procedure (assumption one-to-one mapping
00535     // between symbols for procedures and procedure handles
00536     // for procedures
00537     // If it isn't a nameRef then we must have a function ptr
00538     if (! callMRE->isaNamed()) {
00539 
00540         // gather all the MREs that are in the same set as the callMRE
00541         // NOTICE: only do this if is not a Named, NamedRefs for calls
00542         // aren't actually given an MREToID
00543         aliasedMREs  = allMemRefExprsInSameSet( callMRE, ufset );
00544     }
00545 
00546     // Previously, we iterated over params and then over
00547     // aliases to procedures potentially invoked at the call site.
00548     // I am inverting this.  We visit potential aliases to
00549     // discover new static resolution of indirect calls.  For
00550     // each of these, newly discovered, we need to add it to 
00551     // the worklist.  Doing this in the opposite order would
00552     // not allow us to visit functions without params or without
00553     // pointer params that are only indirectly invoked.  BSW 10/27/06
00554 
00555     // Note that for non-incremental version of ManagerFIAlias
00556     // (i.e., those other than ManagerFIAliasReachable)
00557     // there is no concept of a worklist.  Hence addProcToWorkList
00558     // is a no-op.  Nevertheless, the above-mentioned loop
00559     // rearrangement does not cause any inefficiencies.
00560 
00561     // for all mres in the same set
00562     std::set<OA_ptr<MemRefExpr> >::iterator mreIter; 
00563     for (mreIter=aliasedMREs.begin(); mreIter!=aliasedMREs.end();
00564          mreIter++ )
00565     {
00566         OA_ptr<MemRefExpr> possCallMRE = *mreIter;
00567         OA_ptr<NamedRef> namedProc;
00568 
00569         if (debug) {
00570             std::cout << "Aliased call mre: ";
00571             possCallMRE->output(*mIR);
00572         }
00573 
00574         // if the mre is a NamedRef then
00575         if (possCallMRE->isaNamed()) {
00576             namedProc = possCallMRE.convert<NamedRef>();
00577             if (debug) {
00578                 std::cout << " (Named)" << std::endl;
00579             }
00580         } else {
00581             if (debug) {
00582                 std::cout << " (Unnamed)" << std::endl;
00583             }
00584             continue;
00585         }
00586                   
00587         // get the symbol for the function
00588         SymHandle sym = namedProc->getSymHandle();
00589                 
00590         // get the procedure handle for that symbol
00591         ProcHandle proc = mIR->getProcHandle(sym);
00592 
00593         // check that the symbol actually has an associated procedure
00594         if (proc==ProcHandle(0)) { continue; }
00595 
00596         // We have a statically resolvable function that may
00597         // be invoked at this callsite.  Add it to the
00598         // worklist to be analyzed, if it isn't already pending
00599         // and hasn't already been analyzed.
00600         addProcToWorkList(proc);
00601 
00602         // for each implicit ptrassignpair due to formal/actual binding
00603         OA_ptr<ParamBindPtrAssignIterator> pairIter
00604             = mIR->getParamBindPtrAssignIterator(call);
00605         for ( ; pairIter->isValid(); (*pairIter)++ ) {
00606         
00607             int formalId = pairIter->currentFormalId();
00608             OA_ptr<MemRefExpr> actualMRE = pairIter->currentActual();        
00609             
00610             if (debug) {
00611                 std::cout << "Call mre: ";
00612                 callMRE->output(*mIR);
00613                 std::cout << " formal id: " << formalId << std::endl;
00614             }
00615 
00616             // get the formal symbol for the param binding
00617             // we are handling
00618             SymHandle formalSym = mIR->getFormalSym(proc,formalId);
00619             // if the signature doesn't match then don't process
00620             if (formalSym==SymHandle(0)) { continue; }
00621 
00622             // make mre for the formal
00623             // FIXME: since already do this, could save time
00624             // by memoizing in a map[proc][formalID]
00625             // Create a namedRef for the formal.
00626             bool addressTaken = false;
00627             bool fullAccuracy = true;
00628             // DEF since formal = actual.
00629             MemRefExpr::MemRefType mrType = MemRefExpr::DEF;
00630             OA_ptr<MemRefExpr> formalmre; 
00631             formalmre = new NamedRef(mrType, formalSym);
00632 
00633             // create a dereference for the formalref and actualref
00634             // record both the dereferences
00635             // union the sets they are in
00636             OA_ptr<MemRefExpr> targetDeref = createDeref( formalmre );
00637             recordMRE(targetDeref, proc );
00638             OA_ptr<MemRefExpr> sourceDeref = createDeref( actualMRE );
00639             recordMRE(sourceDeref, currProc);
00640                  
00641             if (debug) {
00642                 std::cout << "ParamBindPtrAssign: ";
00643                 std::cout << "\tsourceDeref = ";
00644                 sourceDeref->output(*mIR);
00645                 std::cout << "\ttargetDeref = ";
00646                 targetDeref->output(*mIR);
00647                 std::cout << "\t===> merge ( "
00648                           << ufset->Find(mMREToID[targetDeref]) << ", "
00649                           << ufset->Find(mMREToID[sourceDeref]) << " )"
00650                           << std::endl;
00651             }
00652                 
00653             // then merge the sets for the target and source deref
00654             merge( ufset->Find(mMREToID[targetDeref]),
00655                    ufset->Find(mMREToID[sourceDeref]),
00656                    ufset, map);
00657 
00658         } // over possible procedures for function call
00659 
00660     } // paramBindPtrAssigns
00661 }
00662 
00663 OA_ptr<UnionFindUniverse>
00664 ManagerFIAlias::performFIAlias( OA_ptr<IRProcIterator> procIter,
00665                                 FIAliasImplement implement )
00666 {
00667     OA_ptr<UnionFindUniverse> ufset;
00668 
00669     mImplement = implement;
00670     if ( mImplement == ALL_PROCS ) {
00671         ufset = performFIAliasAllProcs(procIter);
00672     } else { 
00673         ufset = performFIAliasReachableProcs(procIter);
00674     }
00675 
00676     if ( debug ) {
00677         OA_ptr<IRProcIterator> analyzedProcIter = getAnalyzedProcIter();
00678         int numAnalyzedProcs = 0;
00679         for(analyzedProcIter->reset(); analyzedProcIter->isValid(); ++(*analyzedProcIter)) {
00680             ++numAnalyzedProcs;
00681         }
00682 
00683         std::cout << "ManagerFIAlias::performFIAlias analyzed " << numAnalyzedProcs << " procs." << std::endl;
00684     }
00685 
00686     return ufset;
00687 }
00688 
00689 OA_ptr<UnionFindUniverse>
00690 ManagerFIAlias::performFIAliasAllProcs( OA_ptr<IRProcIterator> procIter)
00691 {
00692     if ( debug ) {
00693         std::cout << "performFIAliasAllProcs" << std::endl;
00694     }
00695 
00696     // ptr to union find datastructure
00697     OA_ptr<UnionFindUniverse> ufset;
00698 
00699     // map each MemRefExpr to a unique id and count them all
00700     initMemRefExprs(procIter);
00701 
00702     // declare the union-find datastructure
00703     // 1 for each memrefExpr we have seen so far and each one
00704     // could get a deref added in the worse case, the extra
00705     // 1 is for zero
00706     ufset = new UnionFindUniverse(2*mCount+1);
00707 
00708 //   mergeSubSetRefs(ufset);
00709 
00710     // for all the stmts in the whole program
00711     // Iterate over all the procedures in the program
00712     for (procIter->reset() ; procIter->isValid(); ++(*procIter)) { 
00713       ProcHandle currProc = procIter->current();
00714 
00715       // Add this procedure to the set of those that are reachable 
00716       // and have already been analyzed (or are about to be analyzed,
00717       // as with currProc).
00718       // FIAlias visits all procs; this makes more sense for 
00719       // FIAliasReachable.
00720       mAnalyzedProcs.insert(currProc);
00721 
00722       // Iterate over the statements of this procedure
00723       OA_ptr<IRStmtIterator> stmtIterPtr = mIR->getStmtIterator(currProc);
00724       // Iterate over the statements of this block adding procedure references
00725       for ( ; stmtIterPtr->isValid(); ++(*stmtIterPtr)) {
00726 
00727         StmtHandle stmt = stmtIterPtr->current();
00728 
00729         if (debug) {
00730           std::cout << "===========================" << std::endl << "stmt = ";
00731           mIR->dump(stmt,std::cout);
00732           std::cout << std::endl;
00733         }
00734 
00735         doPhase1Iteration(stmt, currProc, ufset);
00736 
00737       } // over stmts
00738     } // over procedures
00739 
00740     // this will be the default value for this
00741     // for each partition
00742     //    map[part][memref] = 0; 
00743     std::map<int,std::map<OA_ptr<MemRefExpr>,int> > map;
00744 
00745     bool changed = true;
00746 
00747     while (changed) {
00748 
00750         // do this until there are no more changes
00751       
00752         // Please note that 'phases' are a bit of a misnomer since we
00753         // iterate over phases 2 and 3 together-- as opposed to 
00754         // separately iterating over phase 2, then phase 3.  Doing them
00755         // separately appears to be a bug in Fig 5 of the Ryder 2001 paper.
00756 
00757         if (debug) { 
00758             std::cout << std::endl 
00759                       << "======== Beginning of Phase 2 while loop =====" 
00760                       << std::endl; 
00761         }
00762 
00763         changed = doPhase2Iteration(ufset, map);
00764         
00767       
00768         if (debug) { 
00769             std::cout << std::endl 
00770                       << "======== Beginning of Phase 3 while loop =====" 
00771                       << std::endl; 
00772         }
00773 
00774         // for all the stmts in the whole program
00775         // Iterate over all the procedures in the program
00776         for (procIter->reset() ; procIter->isValid(); ++(*procIter)) { 
00777             ProcHandle currProc = procIter->current();
00778 
00779             // Iterate over the statements of this procedure
00780             OA_ptr<IRStmtIterator> stmtIterPtr = mIR->getStmtIterator(currProc);
00781             // Iterate over the statements of this block adding procedure references
00782             for ( ; stmtIterPtr->isValid(); ++(*stmtIterPtr)) {
00783                 StmtHandle stmt = stmtIterPtr->current();
00784                 // for all the callsites in the stmt
00785                 OA_ptr<IRCallsiteIterator> callIter = mIR->getCallsites(stmt);
00786                 for ( ; callIter->isValid(); (*callIter)++ ) {
00787                     CallHandle call = callIter->current();
00788 
00789                     if (debug) {
00790                         std::cout << "Call site: " << mIR->toString(call) << std::endl;
00791                     }
00792 
00793                     doPhase3Iteration(call, currProc, ufset, map);
00794             
00795                 } // call sites
00796             } // over stmts
00797         } // over procedures
00798     } // iterating to fixed point 
00799 
00800     return ufset;
00801 }
00802 
00803 OA_ptr<UnionFindUniverse>
00804 ManagerFIAlias::performFIAliasReachableProcs( OA_ptr<IRProcIterator> procIter)
00805 {
00806     if ( debug ) {
00807         std::cout << "performFIAliasReachableProcs" << std::endl;
00808     }
00809 
00810     // Maintain a list of procedures known to be reachable, but
00811     // which have not yet been processed.  Those procs in the
00812     // procIter are considered a seed of reachable functions passed
00813     // by the caller.  In the common case, we expect procIter to 
00814     // hold only main.
00815     for (procIter->reset() ; procIter->isValid(); ++(*procIter)) { 
00816       ProcHandle currProc = procIter->current();
00817       addProcToWorkList(currProc);
00818     }
00819 
00820     // Keep a list of ambiguous/indirect calls that require
00821     // alias analysis for resolution.  The ProcHandle is the
00822     // caller.
00823     std::set<std::pair<CallHandle,ProcHandle> > indirect_calls;
00824 
00825     // ptr to union find datastructure
00826     OA_ptr<UnionFindUniverse> ufset;
00827 
00828     // declare the union-find datastructure
00829     // FIAlias would have found all MREs in the program
00830     // at this point and would know how large to make the
00831     // UnionFindUniverse.  We analyze procedures on demand 
00832     // and do not have this information.  We could analyze
00833     // main to seed the size of the universe, but this
00834     // would complicate the loop below.  Instead, just
00835     // set it to something arbitrary and let it grow.
00836     int initialSize = 1024;
00837     ufset = new UnionFindUniverse(2*initialSize+1);
00838 
00839     // this will be the default value for this
00840     // for each partition
00841     //    map[part][memref] = 0; 
00842     std::map<int,std::map<OA_ptr<MemRefExpr>,int> > map;
00843 
00844     bool changed = true;
00845 
00846     unsigned int iter_count = 0;
00847     unsigned int stmts_analyzed = 0;
00848 
00849     while ( changed ) {
00850 
00851         // Iterate over the worlist
00852         while ( mWorklist.begin() != mWorklist.end() ) {
00853 
00854             ProcHandle currProc = *(mWorklist.begin());
00855             mWorklist.erase(currProc);
00856 
00857             // Add this procedure to the set of those that are reachable 
00858             // and have already been analyzed (or are about to be analyzed,
00859             // as with currProc).
00860             mAnalyzedProcs.insert(currProc);
00861 
00862             // Map each MemRefExpr in this proc to a unique id and 
00863             // count them all.
00864             initMemRefExprs(currProc);
00865 
00866             // Iterate over the statements of this procedure.
00867             OA_ptr<IRStmtIterator> stmtIterPtr = 
00868                 mIR->getStmtIterator(currProc);
00869             // Iterate over the statements of this block, adding 
00870             // procedure references.
00871             for ( ; stmtIterPtr->isValid(); ++(*stmtIterPtr)) {
00872 
00873                 stmts_analyzed++;
00874                 StmtHandle stmt = stmtIterPtr->current();
00875                 if (debug) {
00876                     std::cout << "===========================" 
00877                               << std::endl 
00878                               << "stmt = ";
00879                     mIR->dump(stmt,std::cout);
00880                     std::cout << std::endl;
00881                 }
00882 
00883                 doPhase1Iteration(stmt, currProc, ufset);
00884 
00885                 // End Ryder phase 1.
00886 
00887                 // Visit each call in the current proc.  If the
00888                 // target is Named (i.e., resolvable), 
00889                 // then add it to the worklist.  [However, notice
00890                 // that this happens in doPhase3Iteration.] 
00891                 // If the target is not a Named mre, 
00892                 // then it is an indirect call--
00893                 // add it to the list of indirect_calls.
00894                 // In any case, perform phase 2b-- i.e., param
00895                 // bindings.
00896 
00897                 // For all the callsites in the stmt
00898                 OA_ptr<IRCallsiteIterator> callIter = mIR->getCallsites(stmt);
00899                 for ( ; callIter->isValid(); (*callIter)++ ) {
00900                     CallHandle call = callIter->current();
00901 
00902                     if (debug) {
00903                         std::cout << "Call site: " 
00904                                   << mIR->toString(call) 
00905                                   << std::endl;
00906                     }
00907 
00908                     // Get the mre for the function call (eg. NamedRef('foo'))
00909                     OA_ptr<MemRefExpr> callMRE = mIR->getCallMemRefExpr(call);
00910 
00911                     if (!callMRE->isaNamed()) {
00912                         // The call is not a named MRE-- it must be an
00913                         // indirect call.
00914                         indirect_calls.insert(std::pair<CallHandle,ProcHandle>(call,currProc));
00915                     }
00916 
00917                     // Perform param binding-- i.e., phase 2b.
00918                     doPhase3Iteration(call, currProc, ufset, map);
00919 
00920                 } // End iteration over call sites
00921 
00922             } // over stmts
00923 
00924         } // over worklist
00925         
00927         // do this until there are no more changes
00928       
00929         // Please note that 'phases' are a bit of a misnomer since we
00930         // iterate over phases 2 and 3 together-- as opposed to 
00931         // separately iterating over phase 2, then phase 3.  Doing them
00932         // separately appears to be a bug in Fig 5 of the Ryder 2001 paper.
00933 
00934         if (debug) { 
00935             std::cout << std::endl 
00936                       << "======== Beginning of Phase 2 while loop =====" 
00937                       << std::endl; 
00938         }
00939 
00940         changed = doPhase2Iteration(ufset, map);
00941         
00944       
00945         if (debug) { 
00946             std::cout << std::endl 
00947                       << "======== Beginning of Phase 3 while loop =====" 
00948                       << std::endl; 
00949         }
00950 
00951         // Ryder phase 3/CGO phase 2b performs param binding.
00952         // Notice that we have already done this above.  However,
00953         // an indirect call site may have acquired a static
00954         // resolution through alias analysis.  Therefore, revisit
00955         // all indirect call sites and (re-)apply param binding.
00956 
00957         for ( std::set<std::pair<CallHandle,ProcHandle> >::iterator it = indirect_calls.begin();
00958               it != indirect_calls.end(); ++it) {
00959 
00960             CallHandle call = it->first;
00961             ProcHandle caller = it->second;
00962 
00963             doPhase3Iteration(call, caller, ufset, map);
00964         } // call sites
00965         ++iter_count;
00966     } // iterating to fixed point 
00967 
00968     return ufset;
00969 }
00970 
00974 void
00975 ManagerFIAlias::recordMRE( OA_ptr<MemRefExpr> mre, ProcHandle proc )
00976 {
00977     
00978     if (debug) {
00979         std::cout << "In recordMRE ..." << std::endl;
00980         std::cout << "\tmre = ";
00981         mre->output(*mIR);
00982         std::cout << "\tproc = " << mIR->toString(proc) << std::endl;
00983     }
00984 
00985     // check if it doesn't already have an id in the range 1..
00986     if (mMREToID[mre] == 0) {
00987         mMREToID[mre] = mCount++;
00988     }
00989 
00990     mMREToProcs[mre].insert(proc);
00991 }
00992 
00997 void
00998 ManagerFIAlias::recordMRE( OA_ptr<MemRefExpr> mre, ProcHandle proc, 
00999                            MemRefHandle memref)
01000 {
01001     if (debug) {
01002         std::cout << "In recordMRE ..." << std::endl;
01003         std::cout << "\tmre = ";
01004         mre->output(*mIR);
01005         std::cout << "\tproc = " << mIR->toString(proc) << std::endl;
01006         std::cout << "\tmemref = ";
01007         mIR->dump(memref,std::cout);
01008     }
01009     // each MemRefHandle can only show up in one procedure
01010     mMemRefHandleToProc[memref] = proc;
01011 
01012     // check if it doesn't already have an id in the range 1..
01013     if (mMREToID[mre] == 0) {
01014         mMREToID[mre] = mCount++;
01015     }
01016 
01017     // keep track of which MemRefHandles an MRE expresses and which procs
01018     // it is found in
01019     mMREToMemRefHandles[mre].insert(memref);
01020     mMREToProcs[mre].insert(proc);
01021 }
01022 
01024 OA_ptr<MemRefExpr>
01025 ManagerFIAlias::createDeref( OA_ptr<MemRefExpr> mre )
01026 {
01027 
01028    OA_ptr<MemRefExpr> retval;
01029 
01030 /*
01031     // if this is an addressOf then remove the addressOf
01032     if (mre->isaRefOp()) {
01033       OA_ptr<RefOp> refOp = mre.convert<RefOp>();
01034       if(refOp->isaAddressOf()) {
01035          retval = mre->clone();
01036          retval = refOp->getMemRefExpr();
01037          return retval;
01038       }
01039     }
01040 */
01041     int numDerefs = 1;
01042     OA::OA_ptr<OA::Deref> deref_mre;
01043     OA::OA_ptr<OA::MemRefExpr> nullMRE;
01044 
01045     deref_mre = new OA::Deref(
01046                               OA::MemRefExpr::USE,
01047                               nullMRE,
01048                               numDerefs);
01049     retval = deref_mre->composeWith(mre->clone());
01050 
01051     return retval;
01052 
01053 }
01054 
01055 
01056 std::set<OA_ptr<MemRefExpr> > 
01057 ManagerFIAlias::allMemRefExprsInSameSet( OA_ptr<MemRefExpr> pMRE,
01058     OA_ptr<UnionFindUniverse> ufset)
01059 {
01060     std::set<OA_ptr<MemRefExpr> > retval;
01061 
01062     int setID = ufset->Find(mMREToID[pMRE]);
01063 
01064     std::map<OA_ptr<MemRefExpr>,int>::iterator mapIter;
01065     for (mapIter=mMREToID.begin(); mapIter!=mMREToID.end(); mapIter++)
01066     {
01067         OA_ptr<MemRefExpr> mre = mapIter->first;
01068         if (debug) {
01069             std::cout << "allMemRefExprsInSameSet: mre = ";
01070             mre->dump(std::cout);
01071         }
01072         if ( ufset->Find(mMREToID[mre]) == setID ) {
01073             retval.insert(mre);
01074         }
01075     }
01076 
01077     return retval;
01078 }
01079 
01089 class RecordMREsVisitor : public virtual MemRefExprVisitor {
01090   public:
01091     RecordMREsVisitor(ManagerFIAlias &manager, ProcHandle proc )
01092         : mManager(manager), mProc(proc) {}
01093     ~RecordMREsVisitor() {}
01094 
01095     void visitNamedRef(NamedRef& ref) { 
01096         OA_ptr<MemRefExpr> mre = ref.clone();
01097         mManager.recordMRE(mre, mProc); 
01098     }
01099     void visitUnnamedRef(UnnamedRef& ref) {
01100         OA_ptr<MemRefExpr> mre = ref.clone();
01101         mManager.recordMRE(mre, mProc); 
01102     }
01103     void visitUnknownRef(UnknownRef& ref) {
01104         OA_ptr<MemRefExpr> mre = ref.clone();
01105         mManager.recordMRE(mre, mProc); 
01106     }
01107     void visitAddressOf(AddressOf& ref) {
01108         // do not record the addressOf, but record its child
01109         OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
01110         if (!mre.ptrEqual(0)) { 
01111             mre->acceptVisitor(*this); 
01112         }
01113     }
01114     void visitDeref(Deref& ref) { 
01115         // record self
01116         OA_ptr<MemRefExpr> mref = ref.clone();
01117         mManager.recordMRE(mref, mProc); 
01118         // must also visit child memory reference
01119         OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
01120         if (!mre.ptrEqual(0)) { 
01121             mre->acceptVisitor(*this); 
01122         }
01123     }
01124     // default handling of more specific SubSet specificiations
01125     void visitSubSetRef(SubSetRef& ref) {
01126         // record self
01127         OA_ptr<MemRefExpr> mref = ref.clone();
01128         mManager.recordMRE(mref, mProc); 
01129         
01130         // must also visit child memory reference
01131         OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
01132         if (!mre.ptrEqual(0)) { 
01133             mre->acceptVisitor(*this); 
01134         }
01135     }
01136   private:
01137     ManagerFIAlias& mManager;
01138     ProcHandle mProc;
01139 
01140 };
01141 
01142 
01143 void ManagerFIAlias::initMemRefExprs( ProcHandle currProc )
01144 {
01145     // visitor that can record all mres and sub mres within an mre
01146     RecordMREsVisitor visitor(*this, currProc);
01147 
01148     // Iterate over the statements of this procedure
01149     OA_ptr<IRStmtIterator> stmtIterPtr = mIR->getStmtIterator(currProc);
01150     // Iterate over the statements of this block adding procedure references
01151     for ( ; stmtIterPtr->isValid(); ++(*stmtIterPtr)) {
01152 
01153         StmtHandle stmt = stmtIterPtr->current();
01154         if (debug) {
01155           std::cout << std::endl << "stmt = ";
01156           mIR->dump(stmt,std::cout);
01157         }
01158 
01159         // map each memory reference expr to a unique number in the range 1..
01160         OA_ptr<MemRefHandleIterator> mrIterPtr = mIR->getAllMemRefs(stmt);
01161         for (; mrIterPtr->isValid(); (*mrIterPtr)++ ) {
01162             
01163             MemRefHandle memref = mrIterPtr->current();
01164 
01165             // get the memory reference expressions for this handle
01166             OA_ptr<MemRefExprIterator> mreIterPtr 
01167                 = mIR->getMemRefExprIterator(memref);
01168       
01169             // for each mem-ref-expr associated with this memref
01170             for (; mreIterPtr->isValid(); (*mreIterPtr)++) {
01171                 OA_ptr<OA::MemRefExpr> mre = mreIterPtr->current();
01172 
01173                 // associate this mre with the particular MemRefHandle
01174                 recordMRE(mre, currProc, memref);
01175 
01176                 // the recordMREs visitor will get all subrefs
01177                 // and not associate them with a MemRefHandle
01178 
01179                 mre->acceptVisitor(visitor);   
01180             }
01181 
01182         } // loop over MemRefHandles
01183 
01184         // there might be some MemRefExprs in PtrAssignPairs that are
01185         // not associated with a MemRefHandle
01186         // for each ptrassignpair
01187         OA_ptr<PtrAssignPairStmtIterator> pairIter
01188           = mIR->getPtrAssignStmtPairIterator(stmt);
01189         for ( ; pairIter->isValid(); (*pairIter)++ ) {
01190             OA_ptr<MemRefExpr> target = pairIter->currentTarget();        
01191             target->acceptVisitor(visitor);   
01192 
01193             OA_ptr<MemRefExpr> source = pairIter->currentSource();        
01194             source->acceptVisitor(visitor);   
01195         }
01196 
01197         // there can be some implicit MemRefExprs in ParamBindPtrAssigns
01198         // for all the callsites in the stmt
01199         OA_ptr<IRCallsiteIterator> callIter = mIR->getCallsites(stmt);
01200         for ( ; callIter->isValid(); (*callIter)++ ) {
01201             CallHandle call = callIter->current();
01202 
01203             // get the mre for the function call (eg. NamedRef('foo'))
01204             OA_ptr<MemRefExpr> callMRE = mIR->getCallMemRefExpr(call);
01205             callMRE->acceptVisitor(visitor);   
01206 
01207             // for each implicit ptrassignpair due to formal/actual binding
01208             OA_ptr<ParamBindPtrAssignIterator> pairIter
01209               = mIR->getParamBindPtrAssignIterator(call);
01210             for ( ; pairIter->isValid(); (*pairIter)++ ) {
01211                 OA_ptr<MemRefExpr> actualMRE = pairIter->currentActual();        
01212 
01213                 recordMRE(actualMRE, currProc);
01214                 actualMRE->acceptVisitor(visitor);   
01215             }
01216         }
01217 
01218 
01219     } // loop over stmts
01220 
01221     // loop over formals for this procedure and recordMREs for each formal
01222     // also add this formal SymHandle to the set of formals for currProc
01223     int formalCount = 0;
01224     SymHandle formalSym;
01225     while ( (formalSym=mIR->getFormalSym(currProc,formalCount)) 
01226             != SymHandle(0) ) 
01227     {
01228         // put ian set of formals for currProc
01229         mProcToFormalSet[currProc].insert(formalSym);
01230 
01231         // make mre for the formal
01232         // Create a namedRef for the formal.
01233         bool addressTaken = false;
01234         bool fullAccuracy = true;
01235         // DEF since formal = actual.
01236         MemRefExpr::MemRefType mrType = MemRefExpr::DEF;
01237         OA_ptr<MemRefExpr> formalmre; 
01238         formalmre = new NamedRef(mrType, formalSym);
01239 
01240         // recordMRE for formal
01241         // update mMREToMemRefHandle, mMREToProc, and mMREToID
01242         // and updates mCount of all memory references
01243         
01244         formalmre->acceptVisitor(visitor);   
01245 
01246         // increment the count used within this loop
01247         formalCount++;
01248     }
01249 }
01250 
01251 void ManagerFIAlias::initMemRefExprs( OA_ptr<IRProcIterator> procIter )
01252 {
01253     // for all the stmts in the whole program
01254     // Iterate over all the procedures in the program
01255     for (procIter->reset() ; procIter->isValid(); ++(*procIter)) { 
01256       ProcHandle currProc = procIter->current();
01257       initMemRefExprs(currProc);
01258     }
01259 
01260 }
01261 
01265 void ManagerFIAlias::merge(int part1, int part2, 
01266         OA_ptr<UnionFindUniverse> ufset, 
01267         std::map<int,std::map<OA_ptr<MemRefExpr>,int> > & map  ) 
01268 {
01269     int part1_find = ufset->Find(part1);
01270     int part2_find = ufset->Find(part2);
01271     if (part1_find != part2_find) {
01272         std::map<OA_ptr<MemRefExpr>,int> &old1 = map[part1_find];
01273         std::map<OA_ptr<MemRefExpr>,int> &old2 = map[part2_find];
01274         ufset->Union(part1_find, part2_find, part2_find);
01275 
01276         if (debug) {
01277             std::cout << "\t===> Union ( "
01278                       << part1_find << ", " << part2_find << " )" << std::endl;
01279         }
01280 
01281         // loop over all of the mres that are now in the newly unioned set
01282         // I think the fastest way to do this is to look over the mres
01283         // in the two old sets.  Otherwise I have to loop over all the MREs
01284         // and figure out which ones are in the new set.
01285         std::map<OA_ptr<MemRefExpr>,int>::iterator mapIter;
01286         part1_find = ufset->Find(part1);
01287         for (mapIter = old1.begin(); mapIter != old1.end(); mapIter++) {
01288             OA_ptr<MemRefExpr> mre = mapIter->first;
01289             if ( old1[mre]==0 && old2[mre]==0 ) {
01290                 map[part1_find][mre] = 0;
01291             } else if (old2[mre]==0) {
01292                 map[part1_find][mre] = old1[mre];
01293             } else if (old1[mre]==0) {
01294                 map[part1_find][mre] = old2[mre];
01295             } else {
01296                 merge(old1[mre], old2[mre], ufset, map);
01297             }
01298         }
01299         for (mapIter = old2.begin(); mapIter != old2.end(); mapIter++) {
01300             OA_ptr<MemRefExpr> mre = mapIter->first;
01301             if ( old1[mre]==0 && old2[mre]==0 ) {
01302                 map[part1_find][mre] = 0;
01303             } else if (old2[mre]==0) {
01304                 map[part1_find][mre] = old1[mre];
01305             } else if (old1[mre]==0) {
01306                 map[part1_find][mre] = old2[mre];
01307             } else {
01308                 merge(old1[mre], old2[mre], ufset, map);
01309             }
01310         }
01311     }
01312 
01313 }
01314 
01315 void ManagerFIAlias::outputMREsInSet(int setID, 
01316         OA_ptr<UnionFindUniverse> ufset, 
01317         std::map<int,std::map<OA_ptr<MemRefExpr>,int> > & map  ) 
01318 {
01319   std::cout << "All mres in setID = " << setID << std::endl;
01320   std::map<OA_ptr<MemRefExpr>,int>::iterator mapIter;
01321   for (mapIter=mMREToID.begin(); mapIter!=mMREToID.end(); mapIter++) {
01322     if ( ufset->Find(mMREToID[mapIter->first]) == ufset->Find(setID) ) {
01323       OA_ptr<MemRefExpr> mymre = mapIter->first;
01324       mymre->output(*mIR);
01325     }
01326   }
01327 }
01328 
01329   } // end of namespace Alias
01330 } // end of namespace OA
01331