ManagerActiveStandard.cpp

Go to the documentation of this file.
00001 
00015 #include "ManagerActiveStandard.hpp"
00016 #include <Utils/Util.hpp>
00017 
00018 namespace OA {
00019   namespace Activity {
00020 
00021 static bool debug = false;
00022 
00025 ManagerActiveStandard::ManagerActiveStandard(OA_ptr<ActivityIRInterface> _ir) 
00026     : mIR(_ir) 
00027 {
00028     OA_DEBUG_CTRL_MACRO("DEBUG_ManagerActiveStandard:ALL", debug);
00029 }
00030 
00045 OA_ptr<ActiveStandard> ManagerActiveStandard::performAnalysis(ProcHandle proc, 
00046         OA_ptr<CFG::CFGInterface> cfg,
00047         OA_ptr<Alias::Interface> alias,
00048         OA_ptr<VaryStandard> vary,
00049         OA_ptr<UsefulStandard> useful)
00050 {
00051   mAlias = alias;
00052   mActive = new ActiveStandard(proc);
00053 
00054   if (debug) {
00055     std::cout << "ManagerActiveStandard::performAnalysis: ";
00056     std::cout << "\tAnalyzing procedure " << mIR->toString(proc);
00057     std::cout << std::endl;
00058   }
00059 
00060   // first create DepStandard, VaryStandard, and UsefulStandard
00061   // Dep Analysis
00062 //  OA_ptr<ManagerDepStandard> depman;
00063 //  depman = new ManagerDepStandard(mIR);
00064 
00065   //mDep = depman->performAnalysis(proc, alias, cfg);
00066 
00067 //  if (debug) { mDep->dump(std::cout, mIR); }
00068 
00069   // Vary
00070 //  OA_ptr<ManagerVaryStandard> varyman;
00071 //  varyman = new ManagerVaryStandard(mIR);
00072 
00073 //  OA_ptr<VaryStandard> vary
00074 //        = varyman->performAnalysis(proc, cfg, mDep, indepLocIter);
00075 
00076 //  if (debug) { vary->dump(std::cout, mIR); }
00077 
00078   // Useful
00079 //  OA_ptr<ManagerUsefulStandard> usefulman;
00080 //  usefulman = new ManagerUsefulStandard(mIR);
00081 
00082 //  OA_ptr<UsefulStandard> useful
00083  //       = usefulman->performAnalysis(proc, cfg, mDep, depLocIter);
00084 
00085 //  if (debug) { useful->dump(std::cout, mIR); }
00086 
00087   // initialize OutVaryIterator to iterator over independent variables
00088   OA_ptr<LocIterator> outVaryIterPtr = vary->getIndepSetIterator();
00089   OA_ptr<LocIterator> depLocIter = useful->getDepSetIterator();
00090   StmtHandle prevStmt = StmtHandle(0);
00091 
00092   // for each statement in the procedure
00093   OA_ptr<OA::IRStmtIterator> stmtIterPtr = mIR->getStmtIterator(proc);
00094   for ( ; stmtIterPtr->isValid(); (*stmtIterPtr)++) {
00095     OA::StmtHandle stmt = stmtIterPtr->current();
00096  
00097     // send iterator for OutVary from previous stmt and InVary for current
00098     // stmt into a helper function that determines active locations, whether
00099     // the previous stmt was active, and which memory references in the
00100     // previous and current stmt are active
00101     calculateActive(prevStmt, outVaryIterPtr, 
00102                     stmt, useful->getInUsefulIterator(stmt));
00103 
00104     // get OutVary for this stmt
00105     outVaryIterPtr = vary->getOutVaryIterator(stmt);
00106     prevStmt = stmt;
00107 
00108   }
00109 
00110   // do calculation for point after last stmt
00111   calculateActive(prevStmt, outVaryIterPtr, StmtHandle(0), depLocIter);
00112 
00113    return mActive;
00114   
00115 }
00116 
00122 void ManagerActiveStandard::calculateActive(
00123         StmtHandle prevStmt, OA_ptr<LocIterator> prevOutVaryIter,
00124         StmtHandle stmt, OA_ptr<LocIterator> inUsefulIter)
00125 {
00126     if (debug) {
00127         std::cout << "\tcalculateActive ---------------------" << std::endl;
00128     }
00129 
00130     // get set of active locations
00131     prevOutVaryIter->reset();
00132     for ( ; prevOutVaryIter->isValid(); (*prevOutVaryIter)++ ) {
00133         OA_ptr<Location> loc = prevOutVaryIter->current();
00134         if (debug) { 
00135             std::cout << "\t\tinVary loc = ";
00136             loc->dump(std::cout,mIR);
00137         }
00138         inUsefulIter->reset();
00139         for ( ; inUsefulIter->isValid(); (*inUsefulIter)++ ) {
00140             if (debug) { 
00141                 std::cout << "\t\tinUseful loc = ";
00142                 inUsefulIter->current()->dump(std::cout,mIR);
00143             }
00144             if (loc->mayOverlap(*(inUsefulIter->current())) ) {
00145                 mActive->insertLoc(loc);
00146                 mActive->insertLoc(inUsefulIter->current());
00147                 if (debug) {
00148                   std::cout << "\t\tinserting active loc = ";
00149                   loc->dump(std::cout,mIR);
00150                   std::cout << "\t\tinserting active loc = ";
00151                   inUsefulIter->current()->dump(std::cout,mIR);
00152                 }
00153             }
00154         }
00155     }
00156 
00157     // get all the defines from prevStmt and if any of those memory 
00158     // references have maylocs that may overlap with the active
00159     // locations then the prevStmt and the memory references are active
00160     if (prevStmt != StmtHandle(0)) {
00161       OA_ptr<MemRefHandleIterator> defIterPtr = mIR->getDefMemRefs(prevStmt);
00162       for ( ; defIterPtr->isValid(); (*defIterPtr)++ ) {
00163         MemRefHandle def = defIterPtr->current();
00164         if (debug) {
00165           std::cout << "\t\tdef (" << def.hval() << ") = ";
00166           mIR->dump(def,std::cout);
00167         }
00168 
00169         OA_ptr<LocIterator> activeIterPtr 
00170             = mActive->getActiveLocsIterator();
00171         OA_ptr<LocIterator> locIterPtr = mAlias->getMayLocs(def);
00172         for (; locIterPtr->isValid(); ++(*locIterPtr)) {
00173             OA_ptr<Location> loc = locIterPtr->current();
00174             activeIterPtr->reset();
00175             for (; activeIterPtr->isValid(); (*activeIterPtr)++ ) {
00176                 if (loc->mayOverlap(*(activeIterPtr->current())) ) {
00177                     mActive->insertStmt(prevStmt);
00178                     mActive->insertMemRef(def);
00179                 }
00180             }
00181         }
00182       }
00183     }
00184      
00185     // get all the uses from stmt and if any of those memory 
00186     // references have maylocs that may overlap with the active
00187     // locations then those memory references are active
00188     if (stmt != StmtHandle(0)) {
00189       OA_ptr<MemRefHandleIterator> useIterPtr = mIR->getUseMemRefs(stmt);
00190       for ( ; useIterPtr->isValid(); (*useIterPtr)++ ) {
00191         MemRefHandle use = useIterPtr->current();
00192         if (debug) {
00193           std::cout << "\t\tuse (" << use.hval() << ") = ";
00194           mIR->dump(use,std::cout);
00195         }
00196 
00197         OA_ptr<LocIterator> locIterPtr = mAlias->getMayLocs(use);
00198         OA_ptr<LocIterator> activeIterPtr 
00199             = mActive->getActiveLocsIterator();
00200         for (; locIterPtr->isValid(); ++(*locIterPtr)) {
00201             OA_ptr<Location> loc = locIterPtr->current();
00202             activeIterPtr->reset();
00203             for (; activeIterPtr->isValid(); (*activeIterPtr)++ ) {
00204                 if (loc->mayOverlap(*(activeIterPtr->current())) ) {
00205                     mActive->insertMemRef(use);
00206                 }
00207             }
00208         }
00209       }
00210     }
00211      
00212 }
00213 
00214 
00215   } // end of namespace Activity
00216 } // end of namespace OA

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