ManagerNoAddressOf.cpp

Go to the documentation of this file.
00001 
00018 #include "ManagerNoAddressOf.hpp"
00019 
00020 
00021 namespace OA {
00022   namespace Alias {
00023 
00024 static bool debug = false;
00025 
00028 OA_ptr<Alias::EquivSets> ManagerNoAddressOf::performAnalysis(ProcHandle proc) 
00029 {
00030   if (debug) {
00031       std::cout << "In ManagerNoAddressOf::performAnalysis:" << std::endl;
00032   }
00033 
00034   // Initialize EquivSets by creating an empty set that will contain
00035   // all memory locations but the locals
00036   OA_ptr<EquivSets> retEquivSets; retEquivSets = new Alias::EquivSets(proc);
00037   int bigSetID = retEquivSets->makeEmptySet();
00038 
00039   // FIXME: here need to call AccessLoc::getAccessibleLocIterator
00040   // on a passed in OA_ptr<AccessLoc> and put all accessible
00041   // locations that are not local into the big equivalence set
00042   // Put each local in own equivalence set.
00043 
00044   if (debug) {
00045     std::cout << "\tequivSets so far = ";
00046     retEquivSets->dump(std::cout,mIR);
00047   }
00048 
00049   // for each statement stmt
00050   OA_ptr<OA::IRStmtIterator> sItPtr = mIR->getStmtIterator(proc);
00051   for ( ; sItPtr->isValid(); (*sItPtr)++) {
00052     OA::StmtHandle stmt = sItPtr->current();
00053 
00054     if (debug) {
00055         std::cout << "\tstmt = ";
00056         mIR->dump(stmt,std::cout);
00057     }
00058     
00059     //   for each memory reference in the stmt
00060     OA_ptr<MemRefHandleIterator> mrIterPtr = mIR->getAllMemRefs(stmt);
00061     for (; mrIterPtr->isValid(); (*mrIterPtr)++ )
00062     {
00063       MemRefHandle memref = mrIterPtr->current();
00064       if (debug) {
00065         std::cout << "\tmemref = ";
00066         mIR->dump(memref,std::cout);
00067       }
00068 
00069       // get the memory reference expressions for this handle
00070       OA_ptr<MemRefExprIterator> mreIterPtr 
00071           = mIR->getMemRefExprIterator(memref);
00072       
00073       // for each mem-ref-expr associated with this memref
00074       for (; mreIterPtr->isValid(); (*mreIterPtr)++) {
00075         OA_ptr<OA::MemRefExpr> mre = mreIterPtr->current();
00076         if (debug) {
00077             std::cout << "\tmre = ";
00078             mre->dump(std::cout,mIR);
00079         }
00080 
00081         // see if we have not already mapped an equivalent memrefexpr
00082         int setId = retEquivSets->getEquivSetId(mre);
00083         if (debug) {
00084             std::cout << "\tsetId after getEquivSetId(mre) = " << setId 
00085                       << std::endl;
00086         }
00087 
00088         // need to determine what location mre maps to 
00089         if (setId == EquivSets::SET_ID_NONE ) {
00090             
00091             setId = bigSetID;
00092 
00093             // only handling case where is a named local with  full or
00094             // partial accuracy, trivialMREToLoc may return
00095             // a LocSubSet
00096             // FIXME: make trivialMREToLoc a method of the Manager as
00097             // was done in ManagerAliasMapBasic, because the Manager
00098             // can query the AliasIRInterface for the Location associated
00099             // with a symbol and we won't have to save them separately
00100             OA_ptr<Location> loc 
00101                 = retEquivSets->trivialMREToLoc(mre);
00102             if (debug) {
00103               std::cout << "\tafter trivialMREToLoc, loc = ";
00104               loc->dump(std::cout,mIR);
00105             }
00106 
00107             if (!loc.ptrEqual(NULL) && loc->isLocal()) {
00108                 setId = retEquivSets->getEquivSetId(loc);
00109                 if (debug) {
00110                     std::cout << "\tsetId after getEquivSetId(loc) = " 
00111                               << setId << std::endl;
00112                 }
00113 
00114 
00115        
00116                 // if we didn't find the location in the equiv
00117                 // sets then we need to put the location in an
00118                 // existing equiv set with the same base location
00119                 if (setId==EquivSets::SET_ID_NONE && loc->isaSubSet()) {
00120                     // get base location from locsubset
00121                     OA_ptr<Location> base = loc->getBaseLoc();
00122 
00123                     // determine which equivSet that base is in
00124                     setId = retEquivSets->getEquivSetId(base);
00125                     assert(setId!=EquivSets::SET_ID_NONE);
00126 
00127                     // put the subset into the same equiv set
00128                     retEquivSets->addLocation(loc,setId);
00129 
00130                 } else if (setId==EquivSets::SET_ID_NONE) {
00131                     setId = bigSetID;
00132                 }
00133 
00134             } 
00135         }
00136           
00137         // setId at this point is where the location currently is
00138         // if the memory reference involves an addressOf and
00139         // the location is in a set other than the bigSetID
00140         // then we need to merge setId with bigSetID and
00141         // remap all memory references that pointed to setId
00142         // to bigSetID
00143         if (setId!=bigSetID && mre->hasAddressTaken() )
00144         {
00145             // merge the setId with the bigset
00146             retEquivSets->mergeInto(setId,bigSetID);
00147                     
00148             // FIXME: find all memrefs and mre's that map to the
00149             // setId and make them map to bigSetID
00150 
00151         }
00152         // map mre to set
00153         retEquivSets->mapMemRefToEquivSet(mre,setId);
00154         // map memref to mre and memref to set
00155         retEquivSets->mapMemRefToMemRefExpr(memref,mre);
00156         retEquivSets->mapMemRefToEquivSet(memref,setId);
00157 
00158       } // loop over memref expressions
00159     } // loop over memory references
00160   } // loop over statements
00161 
00162   return retEquivSets;
00163 
00164 }
00165    
00166 
00167   } // end of namespace Alias
00168 } // end of namespace OA

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