ManagerUsefulStandard.cpp

Go to the documentation of this file.
00001 
00015 #include "ManagerUsefulStandard.hpp"
00016 #include <Utils/Util.hpp>
00017 
00018 
00019 namespace OA {
00020   namespace Activity {
00021 
00022 static bool debug = false;
00023 
00026 ManagerUsefulStandard::ManagerUsefulStandard(OA_ptr<ActivityIRInterface> _ir) 
00027     : mIR(_ir)
00028 {
00029     OA_DEBUG_CTRL_MACRO("DEBUG_ManagerUsefulStandard:ALL", debug);
00030     mSolver = new DataFlow::CFGDFSolver(DataFlow::CFGDFSolver::Backward,*this);
00031 }
00032 
00033 OA_ptr<DataFlow::DataFlowSet> ManagerUsefulStandard::initializeTop()
00034 {
00035     OA_ptr<DataFlow::LocDFSet>  retval;
00036     retval = new DataFlow::LocDFSet;
00037     return retval;
00038 }
00039 
00040 OA_ptr<DataFlow::DataFlowSet> ManagerUsefulStandard::initializeBottom()
00041 {
00042     // FIXME: really should be all accessible locations, but I don't think
00043     // this is used, if it is there will be an assertian
00044     OA_ptr<DataFlow::LocDFSet>  retval;
00045     //retval = new DataFlow::LocDFSet;
00046     return retval;
00047 }
00048 
00054 OA_ptr<UsefulStandard> ManagerUsefulStandard::performAnalysis(ProcHandle proc, 
00055     OA_ptr<CFG::CFGInterface> cfg, OA_ptr<DepStandard> dep,
00056     OA_ptr<DataFlow::LocDFSet> depLocSet,
00057     DataFlow::DFPImplement algorithm)
00058 {
00059   if (debug) {
00060     std::cout << "In ManagerUsefulStandard::performAnalysis" << std::endl;
00061     //cfg->dump(std::cout,mIR);
00062   }
00063   mUsefulMap = new UsefulStandard(proc);
00064 
00065   // store Dep information for use within the transfer function
00066   mDep = dep;
00067   
00068   // store iterator over independent locations
00069   OA_ptr<LocIterator> locIter = depLocSet->getLocIterator();
00070   mDepLocIter = locIter;
00071 
00072   // store CFG for use in initialization
00073   mCFG = cfg;
00074 
00075   // use the dataflow solver to get the In and Out sets for the BBs
00076   //DataFlow::CFGDFProblem::solve(cfg);
00077   mSolver->solve(cfg,algorithm);
00078 
00079   // get the final useful set from the entry node
00080   OA_ptr<CFG::NodeInterface> entry = cfg->getEntry();
00081 //  OA_ptr<DataFlow::DataFlowSet> dfset = mNodeOutSetMap[entry];
00082   OA_ptr<DataFlow::DataFlowSet> dfset = mSolver->getOutSet(entry);
00083 
00084   //  No routine is using this FinalUseful set, so depredated in UsefulStandard
00085   //  All code is still there, but commented out. BK 8/06
00086   //  mUsefulMap->mapFinalUseful(dfset.convert<DataFlow::LocDFSet>());
00087   assert(0);
00088  
00089   return mUsefulMap;
00090 
00091 }
00092 
00093 //------------------------------------------------------------------
00094 // Implementing the callbacks for CFGDFProblem
00095 //------------------------------------------------------------------
00096 /*void ManagerUsefulStandard::initializeNode(OA_ptr<CFG::Interface::Node> n)
00097 {
00098     mNodeInSetMap[n] = new DataFlow::LocDFSet;
00099     mNodeOutSetMap[n] = new DataFlow::LocDFSet;
00100 
00101     // put independent variables in the In and Out Set for last node
00102     // and into UsefulStandard that we are creating
00103     if (n.ptrEqual(mCFG->getExit())) {
00104         OA_ptr<DataFlow::LocDFSet> temp;
00105         temp = new DataFlow::LocDFSet;
00106         
00107         for (mDepLocIter->reset(); mDepLocIter->isValid(); ++(*mDepLocIter) ) {
00108           OA_ptr<Location> loc = mDepLocIter->current();
00109           mUsefulMap->insertDepLoc(loc);
00110           temp->insert(loc);
00111        }
00112        mNodeInSetMap[n] = temp->clone();
00113        mNodeOutSetMap[n] = temp->clone();
00114     }
00115 } */
00116 
00117 
00121 OA_ptr<DataFlow::DataFlowSet>
00122 ManagerUsefulStandard::initializeNodeIN(OA_ptr<CFG::NodeInterface> n)
00123 {
00124      OA_ptr<DataFlow::LocDFSet> retval;
00125      retval = new DataFlow::LocDFSet;
00126 
00127      if (n.ptrEqual(mCFG->getExit())) {
00128         OA_ptr<DataFlow::LocDFSet> temp;
00129         temp = new DataFlow::LocDFSet;
00130 
00131         for (mDepLocIter->reset(); mDepLocIter->isValid(); ++(*mDepLocIter) ) {
00132             OA_ptr<Location> loc = mDepLocIter->current();
00133             mUsefulMap->insertDepLoc(loc);
00134             temp->insert(loc);
00135         }
00136         retval = temp->clone().convert<DataFlow::LocDFSet>();
00137       }
00138      
00139      return retval;
00140 }
00141 
00142 OA_ptr<DataFlow::DataFlowSet>
00143 ManagerUsefulStandard::initializeNodeOUT(OA_ptr<CFG::NodeInterface> n)
00144 {
00145       OA_ptr<DataFlow::LocDFSet> retval;
00146       retval = new DataFlow::LocDFSet;
00147 
00148       if (n.ptrEqual(mCFG->getExit())) {
00149          OA_ptr<DataFlow::LocDFSet> temp;
00150          temp = new DataFlow::LocDFSet;
00151 
00152          for (mDepLocIter->reset(); mDepLocIter->isValid(); ++(*mDepLocIter) ) {
00153               OA_ptr<Location> loc = mDepLocIter->current();
00154               mUsefulMap->insertDepLoc(loc);
00155               temp->insert(loc);
00156           }
00157           retval = temp->clone().convert<DataFlow::LocDFSet>();
00158        }
00159       
00160       return retval;
00161 }
00162 
00163 
00164 
00165 OA_ptr<DataFlow::DataFlowSet> 
00166 ManagerUsefulStandard::meet (OA_ptr<DataFlow::DataFlowSet> set1orig, 
00167                              OA_ptr<DataFlow::DataFlowSet> set2orig)
00168 {
00169     OA_ptr<DataFlow::LocDFSet> set1
00170         = set1orig.convert<DataFlow::LocDFSet>();
00171     if (debug) {
00172         std::cout << "ManagerUsefulStandard::meet" << std::endl;
00173         std::cout << "\tset1 = ";
00174         set1->dump(std::cout,mIR);
00175         std::cout << ", set2 = ";
00176         set2orig->dump(std::cout,mIR);
00177     }
00178        
00179     DataFlow::LocDFSet retval 
00180         = set1->setUnion(*set2orig);
00181     if (debug) {
00182         std::cout << std::endl << "\tretval set = ";
00183         retval.dump(std::cout,mIR);
00184         std::cout << std::endl;
00185     }
00186        
00187     return retval.clone();
00188 }
00189 
00199 OA_ptr<DataFlow::DataFlowSet> 
00200 ManagerUsefulStandard::transfer(OA_ptr<DataFlow::DataFlowSet> out, 
00201                               OA::StmtHandle stmt) 
00202 {
00203     OA_ptr<DataFlow::LocDFSet> outRecast 
00204         = out.convert<DataFlow::LocDFSet>();
00205     OA_ptr<DataFlow::LocDFSet> inUseful;
00206     inUseful = new DataFlow::LocDFSet;
00207 
00208     if (debug) {
00209         std::cout << "In transfer, stmt(hval=" << stmt.hval() << ")= ";
00210         mIR->dump(stmt,std::cout);
00211     }
00212     
00213     // loop through all calls in the statement and record the OutVary
00214     // set for them
00215     OA_ptr<IRCallsiteIterator> callsiteItPtr = mIR->getCallsites(stmt);
00216     for ( ; callsiteItPtr->isValid(); ++(*callsiteItPtr)) {
00217         CallHandle call = callsiteItPtr->current();
00218 
00219         mUsefulMap->copyIntoCallOutUseful(call, outRecast);
00220     }
00221 
00222     // use dep pairs to determine what locations should be in  InUseful 
00223     DataFlow::LocDFSetIterator outLocIter(*outRecast);
00224     for ( ; outLocIter.isValid(); ++outLocIter ) {
00225       OA_ptr<Location> outLoc = outLocIter.current();
00226       if (debug) { std::cout << "\toutLoc = ";  outLoc->dump(std::cout,mIR); }
00227       OA_ptr<LocIterator> locIterPtr;
00228       locIterPtr = mDep->getDiffUseIterator(stmt,outLoc);
00229       for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00230           inUseful->insert(locIterPtr->current());
00231           if (debug) { 
00232             std::cout << "\tinserting into diffUseSet = ";  
00233             locIterPtr->current()->dump(std::cout,mIR); 
00234           }
00235       }
00236     }
00237 
00238     // map to statement in results
00239     mUsefulMap->copyIntoInUseful(stmt, inUseful);
00240    
00241     return inUseful;
00242 }
00243 
00244   } // end of namespace Activity
00245 } // end of namespace OA