ManagerDepStandard.cpp

Go to the documentation of this file.
00001 
00015 #include "ManagerDepStandard.hpp"
00016 #include <Utils/Util.hpp>
00017 
00018 
00019 namespace OA {
00020   namespace Activity {
00021 
00022 static bool debug = false;
00023 
00024 
00027 ManagerDepStandard::ManagerDepStandard(OA_ptr<ActivityIRInterface> _ir) 
00028     : mIR(_ir)
00029 {
00030     OA_DEBUG_CTRL_MACRO("DEBUG_ManagerDepStandard:ALL", debug);
00031     mSolver = new DataFlow::CFGDFSolver(DataFlow::CFGDFSolver::Forward,*this);
00032 }
00033 
00034 OA_ptr<DataFlow::DataFlowSet> ManagerDepStandard::initializeTop()
00035 {
00036     OA_ptr<DepDFSet>  retval;
00037     retval = new DepDFSet;
00038     return retval;
00039 }
00040 
00041 OA_ptr<DataFlow::DataFlowSet> ManagerDepStandard::initializeBottom()
00042 {
00043     assert(0);
00044     // would have to know all of the accessible locations
00045     OA_ptr<DepDFSet>  retval;
00046     return retval;
00047 }
00048 
00055 OA_ptr<DepStandard> ManagerDepStandard::performAnalysis(ProcHandle proc, 
00056         OA_ptr<Alias::Interface> alias,
00057         OA_ptr<CFG::CFGInterface> cfg, OA_ptr<InterDep> interDep,
00058         OA_ptr<DataFlow::ParamBindings> paramBind,
00059         DataFlow::DFPImplement algorithm)
00060 {
00061   if (debug) {
00062     std::cout << "In ManagerDepStandard::performAnalysis" << std::endl;
00063   }
00064   mDep = new DepStandard();
00065 
00066   // store information for use within callbacks
00067   mAlias = alias;
00068   mInterDep = interDep;
00069   mParamBind = paramBind;
00070 
00071   // store CFG for use in initialization
00072   mCFG = cfg;
00073   if (debug) {
00074   //    cfg->dump(std::cout,mIR);
00075   }
00076 
00077   // use the dataflow solver to get the In and Out sets for the BBs
00078 //  OA_ptr<DataFlow::DataFlowSet> finalDep = DataFlow::CFGDFSolver::solve(cfg);
00079   OA_ptr<DataFlow::DataFlowSet> finalDep = mSolver->solve(cfg,algorithm);
00080   
00081   if (debug) {
00082       std::cout << "ManagerDepStandard::performAnalysis, finalDep = ";
00083       finalDep->dump(std::cout,mIR);
00084   }
00085   mDep->mapFinalDeps(finalDep.convert<DepDFSet>());
00086   
00087   return mDep;
00088 
00089 }
00090 
00091 //------------------------------------------------------------------
00092 // Implementing the callbacks for CFGDFProblem
00093 //------------------------------------------------------------------
00094 //void ManagerDepStandard::initializeNode(OA_ptr<CFG::Interface::Node> n)
00095 //{
00096 //    mNodeInSetMap[n] = initializeTop();
00097 //    mNodeOutSetMap[n] = initializeTop();
00098 //}
00099 
00100 
00104 OA_ptr<DataFlow::DataFlowSet>
00105 ManagerDepStandard::initializeNodeIN(OA_ptr<CFG::NodeInterface> n)
00106 {
00107      OA_ptr<DataFlow::LocDFSet> retval;
00108      retval = new DataFlow::LocDFSet;
00109      return retval;
00110 }
00111 
00112 OA_ptr<DataFlow::DataFlowSet>
00113 ManagerDepStandard::initializeNodeOUT(OA_ptr<CFG::NodeInterface> n)
00114 {
00115       OA_ptr<DataFlow::LocDFSet> retval;
00116       retval = new DataFlow::LocDFSet;
00117       return retval;
00118 }
00119 
00120 
00121 
00122 OA_ptr<DataFlow::DataFlowSet> 
00123 ManagerDepStandard::meet (OA_ptr<DataFlow::DataFlowSet> set1orig, 
00124                            OA_ptr<DataFlow::DataFlowSet> set2orig)
00125 {
00126     OA_ptr<DepDFSet> set1 = set1orig.convert<DepDFSet>();
00127     if (debug) {
00128         std::cout << "ManagerDepStandard::meet" << std::endl;
00129         std::cout << "\tset1 = ";
00130         set1->dump(std::cout,mIR);
00131         std::cout << ", set2 = ";
00132         set2orig->dump(std::cout,mIR);
00133     }
00134        
00135     DepDFSet retval = set1->setUnion(*set2orig);
00136     if (debug) {
00137         std::cout << std::endl << "\tretval set = ";
00138         retval.dump(std::cout,mIR);
00139         std::cout << std::endl;
00140     }
00141        
00142     return retval.clone();
00143 }
00144 
00152 OA_ptr<DataFlow::DataFlowSet> 
00153 ManagerDepStandard::transfer(OA_ptr<DataFlow::DataFlowSet> in, 
00154                               OA::StmtHandle stmt) 
00155 {
00156     OA_ptr<DepDFSet> inRecast = in.convert<DepDFSet>();
00157     if (debug) {
00158         std::cout << "In transfer, stmt(hval=" << stmt.hval() << ")= ";
00159         mIR->dump(stmt,std::cout);
00160         std::cout << "\tinRecast = ";
00161         inRecast->dump(std::cout,mIR);
00162     }
00163     
00164     // new DepDFSet for this stmt
00165     OA_ptr<DepDFSet> stmtDepDFSet;
00166     stmtDepDFSet = new DepDFSet;
00167     
00168     // set of must defs and differentiable uses for this statement
00169     LocSet mustDefSet;
00170     LocSet mayDefSet;
00171     LocSet diffUseSet;
00172 
00173     // set of expressions to analyze for differentiable uses
00174     std::set<ExprHandle> exprSet;
00175 
00176     OA_ptr<AssignPairIterator> espIterPtr 
00177          = mIR->getAssignPairIterator(stmt);
00178     if(!espIterPtr.ptrEqual(0)) {
00179         
00180         for ( ; espIterPtr->isValid(); ++(*espIterPtr)) {
00181             // unbundle pair
00182             MemRefHandle mref = espIterPtr->currentTarget();
00183             ExprHandle expr = espIterPtr->currentSource();
00184             if (debug) {
00185                 std::cout << "\tmref = " << mIR->toString(mref) << ", ";
00186                 std::cout << "expr = " << mIR->toString(expr) << std::endl;
00187             }
00188 
00189             // add this to list of expressions we need to analyze
00190             exprSet.insert(expr);
00191             if (debug) { 
00192                 std::cout << "Inserting memref = expr into exprSet" 
00193                           << std::endl;
00194                 OA_ptr<ExprTree> etree = mIR->getExprTree(expr);
00195                 etree->dump(std::cout,mIR); 
00196             }
00197 
00198             // keep track of def mustlocs
00199             OA_ptr<LocIterator> locIterPtr = mAlias->getMustLocs(mref);
00200             for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00201                 mustDefSet.insert(locIterPtr->current());
00202             }
00203             // maylocs need to be used for Dep pairs so that we get
00204             // conservative activity results
00205             locIterPtr = mAlias->getMayLocs(mref);
00206             for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00207                 mayDefSet.insert(locIterPtr->current());
00208             }
00209         }
00210     
00211     // all other statement types just get all uses and defs
00212     } else {
00213         if (debug) {
00214             std::cout << "\tstmt is not EXPR_STMT, stmt = ";
00215         }
00216     
00217         OA_ptr<MemRefHandleIterator> mrIterPtr = mIR->getUseMemRefs(stmt);
00218         for (; mrIterPtr->isValid(); (*mrIterPtr)++ ) {
00219             MemRefHandle mref = mrIterPtr->current();
00220             OA_ptr<LocIterator> locIterPtr = mAlias->getMayLocs(mref);
00221             for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00222                 diffUseSet.insert(locIterPtr->current());
00223             }
00224         }
00225         mrIterPtr = mIR->getDefMemRefs(stmt);
00226         for (; mrIterPtr->isValid(); (*mrIterPtr)++ ) {
00227             MemRefHandle mref = mrIterPtr->current();
00228             OA_ptr<LocIterator> locIterPtr = mAlias->getMustLocs(mref);
00229             for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00230                 mustDefSet.insert(locIterPtr->current());
00231             }
00232             locIterPtr = mAlias->getMayLocs(mref);
00233             for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00234                 mayDefSet.insert(locIterPtr->current());
00235             }
00236         }
00237     }
00238 
00239     // iterate over all calls in the statement
00240     // and union use,def pairs for the call into DepDFSet for
00241     // the current stmt 
00242     // also find all expressions that are callsite params and not 
00243     // reference parameters
00244     OA_ptr<IRCallsiteIterator> callsiteItPtr = mIR->getCallsites(stmt);
00245     for ( ; callsiteItPtr->isValid(); ++(*callsiteItPtr)) {
00246         CallHandle call = callsiteItPtr->current();
00247         if (debug) {
00248           std::cout << "\nhandling all callsite params and side-effects, ";
00249           std::cout << "call = " << mIR->toString(call) << std::endl;
00250         }
00251 
00252         // get DepDFSet results for this call and put them in results
00253         // for this stmt, will do meet with procedure DepDFSet at end
00254         OA_ptr<DepDFSet> callDepDFSet = mInterDep->getDepForCall(call);
00255         if (debug) { std::cout << "meet involving call DepDFSet" 
00256                                << std::endl; 
00257                   //   callDepDFSet->dump(std::cout,mIR);
00258                    }
00259         OA_ptr<DataFlow::DataFlowSet> tmp = meet(stmtDepDFSet,callDepDFSet);
00260         stmtDepDFSet = tmp.convert<DepDFSet>();
00261         if (debug) {
00262             std::cout << "\tstmtDepDFSet after meet with callDepDFSet = ";
00263             //stmtDepDFSet->dump(std::cout, mIR);
00264         }
00265 
00266         // looping over actual params
00267         OA_ptr<IRCallsiteParamIterator> cspIterPtr 
00268             = mIR->getCallsiteParams(call);
00269         for ( ; cspIterPtr->isValid(); ++(*cspIterPtr)) {
00270             ExprHandle param = cspIterPtr->current();
00271 
00272             // determine if dealing with a reference parameter
00273             bool isRefParam = false;
00274             OA_ptr<ExprTree> eTreePtr = mIR->getExprTree(param);
00275             EvalToMemRefVisitor evalVisitor;
00276             eTreePtr->acceptVisitor(evalVisitor);
00277             if (debug) { eTreePtr->dump(std::cout,mIR); }
00278             if ( evalVisitor.isMemRef() ) {
00279                 MemRefHandle memref = evalVisitor.getMemRef();
00280                 assert(0); // need to rewrite alg, see MMS
00281                 //if (mParamBind->isRefParam(
00282                 //        mParamBind->getCalleeFormal(call,memref)) )
00283                 //{
00284                 //  isRefParam = true;
00285                // }
00286             }
00287 
00288             // record expr for those that aren't reference parameters
00289             if (isRefParam==false) {
00290                 exprSet.insert(param);
00291                 if (debug) { 
00292                     std::cout << "Inserting param expr into exprSet" 
00293                               << std::endl;
00294                     eTreePtr->dump(std::cout,mIR); 
00295                 }
00296             } 
00297         }
00298     }
00299 
00300     // get differentiable locations from all expressions in stmt
00301     if (debug) { std::cout << "ExprTree's:" << std::endl; }
00302     DifferentiableLocsVisitor dlVisitor(mAlias);
00303     std::set<ExprHandle>::iterator exprIter;
00304     for (exprIter=exprSet.begin(); exprIter!=exprSet.end(); exprIter++) {
00305         OA_ptr<ExprTree> etree = mIR->getExprTree(*exprIter);
00306         if (debug) { etree->dump(std::cout,mIR); }
00307         etree->acceptVisitor(dlVisitor);
00308         OA_ptr<LocIterator> locIterPtr 
00309             = dlVisitor.getDiffLocsIterator();
00310         for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00311             diffUseSet.insert(locIterPtr->current());
00312         }
00313     }
00314     
00315     // store must defs in Dep results as well
00316     // and remove the associated implicit dep from DepDFSet
00317     LocSet::iterator useIter, defIter;
00318     for (defIter=mustDefSet.begin(); defIter!=mustDefSet.end(); defIter++) {
00319         mDep->insertMustDefForStmt(stmt,*defIter);
00320         stmtDepDFSet->removeImplicitDep(*defIter,*defIter);
00321     }
00322    
00323     // map all uses to may defs and vice versa for this statement
00324     // have to do this after removing implicit deps in case it will be
00325     // explicitly put back in
00326     OA_ptr<Location> use, def;
00327     for (useIter=diffUseSet.begin(); useIter!=diffUseSet.end(); useIter++) {
00328       for (defIter=mayDefSet.begin(); defIter!=mayDefSet.end(); defIter++) {
00329           stmtDepDFSet->insertDep(*useIter,*defIter);
00330       }
00331     }
00332 
00333     // map stmtDepDFSet to stmt in depResults
00334     mDep->mapStmtToDeps(stmt, stmtDepDFSet);
00335 
00337     // make a copy of inRecast so we don't overwrite IN
00338     OA_ptr<DepDFSet> tmpCopy; tmpCopy = new DepDFSet(*inRecast);
00339     (*tmpCopy) = tmpCopy->compose(*stmtDepDFSet);
00340     //OA_ptr<DepDFSet> tmpCopy;
00341     //tmpCopy = inRecast->compose(stmtDepDFSet);
00342     if (debug) {
00343         std::cout << "\tManagerDepStandard::transfer, returning tmpCopy = ";
00344         tmpCopy->dump(std::cout,mIR);
00345         std::cout << "\t------ other dump" << std::endl;
00346         tmpCopy->dump(std::cout);
00347     }
00348     return tmpCopy;
00349 }
00350 
00351   } // end of namespace Activity
00352 } // end of namespace OA

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