ManagerSymAliasSetsBottom.cpp

Go to the documentation of this file.
00001 
00022 #include "ManagerSymAliasSetsBottom.hpp"
00023 #include <Utils/Util.hpp>
00024 
00025 
00026 namespace OA {
00027   namespace Alias {
00028 
00029 static bool debug = false;
00030 
00031 // Visitor to collect SymHandle's from MemRefExpr's
00032 class SymHandleCollector : public virtual MemRefExprVisitor {
00033     public:
00034       std::set<SymHandle> mSymSet;
00035       SymHandleCollector() {}
00036       ~SymHandleCollector() {}
00037       void visitNamedRef(NamedRef& ref) 
00038         { mSymSet.insert(ref.getSymHandle()); }
00039       void visitUnnamedRef(UnnamedRef& ref) { }
00040       void visitUnknownRef(UnknownRef& ref) { }
00041       // recursively visit mem-ref-exprs
00042       void visitDeref(Deref& ref) 
00043         { ref.getMemRefExpr()->acceptVisitor(*this); }
00044       void visitSubSetRef(SubSetRef& ref) 
00045         { ref.getMemRefExpr()->acceptVisitor(*this); }
00046 };
00047  
00053 OA_ptr<Alias::SymAliasSets> 
00054 ManagerSymAliasSetsBottom::performAnalysis(ProcHandle proc) 
00055 {
00056     OA_DEBUG_CTRL_MACRO("DEBUG_ManagerSymAliasSetsBottom:ALL", debug);
00057    
00058   // create a SymHandleCollector
00059   SymHandleCollector symCollector;
00060 
00061   OA_ptr<SymAliasSets> retMap; retMap = new Alias::SymAliasSets();
00062 
00063   // for each statement stmt
00064   OA_ptr<OA::IRStmtIterator> sIt = mIR->getStmtIterator(proc);
00065   for ( ; sIt->isValid(); (*sIt)++) {
00066     OA::StmtHandle stmt = sIt->current();
00067         
00068     if (debug) {
00069         std::cout << "\tstmt = ";
00070         mIR->dump(stmt,std::cout);
00071     }
00072 
00073     //   for each memory reference in the stmt
00074     OA_ptr<MemRefHandleIterator> mrIterPtr = mIR->getAllMemRefs(stmt);
00075     for (; mrIterPtr->isValid(); (*mrIterPtr)++ )
00076     {
00077       MemRefHandle memref = mrIterPtr->current();
00078       if (debug) {
00079         std::cout << "\tmemref = ";
00080         mIR->dump(memref,std::cout);
00081       }
00082 
00083       // get the memory reference expressions for this handle
00084       OA_ptr<MemRefExprIterator> mreIterPtr 
00085           = mIR->getMemRefExprIterator(memref);
00086       
00087       // for each mem-ref-expr associated with this memref
00088       for (; mreIterPtr->isValid(); (*mreIterPtr)++) {
00089         OA_ptr<OA::MemRefExpr> mre = mreIterPtr->current();
00090         if (debug) {
00091             std::cout << "\tmre = ";
00092             mre->dump(std::cout,mIR);
00093         }
00094 
00095         // have Visitor collect SymHandles
00096         mre->acceptVisitor(symCollector);
00097 
00098       }
00099     }
00100   }
00101  
00102   // iterate over symbols collected and get their locations to
00103   // determine if they are local and what other symbols they
00104   // may and must overlap
00105   SymHandle lastSym;
00106   std::set<SymHandle>::iterator symIter;
00107   for (symIter=symCollector.mSymSet.begin();
00108        symIter!=symCollector.mSymSet.end(); symIter++ )
00109   {
00110       SymHandle sym = *symIter;
00111 
00112       // first get location
00113       OA_ptr<Location> loc = mIR->getLocation(proc,sym);
00114       if (debug) {
00115           std::cout << "loc = ";
00116           loc->dump(std::cout,mIR);
00117       }
00118 
00119       // determine if we need to map the symbol to the big group
00120 //      if (mIR->isRefParam(sym) || !loc->isLocal()) {
00121 //    BROKEN, don't want to use isRefParam anymore
00122       if ( !loc->isLocal()) {
00123           
00124           // if the lastSym is something other than SymHandle(0)
00125           // merge the symbols containing those symbols
00126           SymHandle symNull = SymHandle(0);
00127           if (lastSym != symNull ) {
00128             retMap->mergeSyms(lastSym, sym);
00129           }
00130 
00131           // map all static overlap symbols to this one as well
00132           OA_ptr<NamedLoc> nmloc = loc.convert<NamedLoc>();
00133           OA_ptr<SymHandleIterator> overlapIter = nmloc->getPartOverlapIter();
00134           for ( ; overlapIter->isValid(); (*overlapIter)++ ) {
00135               retMap->mergeSyms(sym,overlapIter->current());
00136           }
00137           overlapIter = nmloc->getFullOverlapIter();
00138           for ( ; overlapIter->isValid(); (*overlapIter)++ ) {
00139               retMap->mergeSyms(sym,overlapIter->current());
00140           }
00141 
00142           lastSym = sym;
00143       }
00144   }
00145 
00146   return retMap;
00147 }
00148 
00149   } // end of namespace Alias
00150 } // end of namespace OA