ManagerInterDep.cpp

Go to the documentation of this file.
00001 
00015 #include "ManagerInterDep.hpp"
00016 #include <Utils/Util.hpp>
00017 
00018 
00019 namespace OA {
00020   namespace Activity {
00021 
00022 static bool debug = false;
00023 
00026 ManagerInterDep::ManagerInterDep(
00027   OA_ptr<ActivityIRInterface> _ir) : mIR(_ir)
00028 {
00029     OA_DEBUG_CTRL_MACRO("DEBUG_ManagerInterDep:ALL", debug);
00030     mSolver = new DataFlow::CallGraphDFSolver(DataFlow::CallGraphDFSolver::BottomUp,*this);
00031 }
00032 
00033 OA_ptr<Activity::InterDep> 
00034 ManagerInterDep::performAnalysis(
00035         OA_ptr<CallGraph::CallGraphInterface> callGraph,
00036         OA_ptr<DataFlow::ParamBindings> paramBind,
00037         OA_ptr<Alias::InterAliasInterface> interAlias,
00038         OA_ptr<SideEffect::InterSideEffectInterface> interSE,
00039         OA_ptr<CFG::EachCFGInterface> eachCFG,
00040         DataFlow::DFPImplement algorithm)
00041 {
00042   // store results that will be needed in callbacks
00043   mParamBind = paramBind;
00044   mInterAlias = interAlias;
00045   mInterSE = interSE;
00046   mEachCFG = eachCFG;
00047 
00048   // create an empty InterDep
00049   mInterDep = new InterDep();
00050 
00051   // call iterative data-flow solver for CallGraph
00052   mSolver->solve(callGraph,algorithm);
00053   
00054   return mInterDep;
00055 }
00056 
00057 //========================================================
00058 // implementation of CallGraphDFProblemNew callbacks
00059 //========================================================
00060 //--------------------------------------------------------
00061 // initialization callbacks
00062 //--------------------------------------------------------
00063 
00069 OA_ptr<DataFlow::DataFlowSet> ManagerInterDep::initializeTop()
00070 {
00071     OA_ptr<DepDFSet> retval;
00072     retval = new DepDFSet;
00073     return retval;
00074 }
00075 
00078 OA_ptr<DataFlow::DataFlowSet>  
00079 ManagerInterDep::initializeBottom()
00080 {
00081     assert(0);
00082     // have different bottom based on what procedure we are
00083     // specificallly have to say all defs depend on all uses
00084 
00085     OA_ptr<DepDFSet> retval;
00086     retval = new DepDFSet;
00087     return retval;
00088 }
00089 
00091 OA_ptr<DataFlow::DataFlowSet> 
00092 ManagerInterDep::initializeNode(ProcHandle proc)
00093 {
00094     return initializeTop();
00095 }
00096 
00099 OA_ptr<DataFlow::DataFlowSet> 
00100 ManagerInterDep::initializeEdge(CallHandle call, 
00101                                                  ProcHandle caller,
00102                                                  ProcHandle callee)
00103 {
00104     return initializeTop();
00105 }
00106 
00110 OA_ptr<DataFlow::DataFlowSet> 
00111 ManagerInterDep::initializeEdge(CallHandle call, 
00112                                                  ProcHandle caller,
00113                                                  SymHandle callee)
00114 {
00115     return initializeTop();
00116 }
00117 
00118 //--------------------------------------------------------
00119 // solver callbacks 
00120 //--------------------------------------------------------
00121   
00124 OA_ptr<DataFlow::DataFlowSet> 
00125 ManagerInterDep::meet(OA_ptr<DataFlow::DataFlowSet> set1, 
00126                       OA_ptr<DataFlow::DataFlowSet> set2)
00127 {
00128     if (debug) {
00129         std::cout << "ManagerInterDep::meet" << std::endl;
00130     }
00131     OA_ptr<DepDFSet> remapSet1 = set1.convert<DepDFSet>();
00132     OA_ptr<DepDFSet> remapSet2 = set2.convert<DepDFSet>();
00133     if (debug) {
00134         std::cout << "\tremapSet1 = ";
00135         remapSet1->dump(std::cout, mIR);
00136         std::cout << "\tremapSet2 = ";
00137         remapSet2->dump(std::cout, mIR);
00138     }
00139 
00140     // making sure we don't trounce set1 just in case
00141     OA_ptr<DepDFSet> retval;
00142     OA_ptr<DataFlow::DataFlowSet> temp = remapSet1->clone();
00143     retval = temp.convert<DepDFSet>();
00144     *retval = retval->setUnion(*remapSet2);
00145     if (debug) {
00146         std::cout << "\tretval = ";
00147         OA_ptr<DepDFSet> temp = retval.convert<DepDFSet>();
00148         temp->dump(std::cout, mIR);
00149     }
00150     return retval;
00151 }
00152 
00154 OA_ptr<DataFlow::DataFlowSet>
00155 ManagerInterDep::atCallGraphNode(
00156         OA_ptr<DataFlow::DataFlowSet> inSet, 
00157         OA::ProcHandle proc)
00158 {
00159     if (debug) {
00160         std::cout << "In ManagerInterDep::atCallGraphNode " 
00161                   << mIR->toString(proc) << std::endl;
00162     }
00163 
00164     // create empty depDFSet for this procedure
00165     OA_ptr<DepDFSet> retval; retval = new DepDFSet;
00166 
00167     // get alias results for this procedure
00168     OA_ptr<Alias::Interface> alias = mInterAlias->getAliasResults(proc);
00169     
00170     // create empty Dep results for this procedure
00171     OA_ptr<ManagerDepStandard> depman;
00172     depman = new ManagerDepStandard(mIR);
00173     OA_ptr<DepStandard> depResults 
00174         = depman->performAnalysis(proc, alias,mEachCFG->getCFGResults(proc),
00175                                   mInterDep, mParamBind,
00176                                   DataFlow::ITERATIVE);
00177 
00178     // assign dep results to this procedure
00179     mInterDep->mapProcToDep(proc,depResults);
00180 
00181     // resulting DepDFSet for whole procedure will be sent to each
00182     // of the call edges
00183     if (debug) {
00184         std::cout << "ManagerInterDep::atCallGraphNode, returning ";
00185         depResults->getFinalDep()->dump(std::cout,mIR);
00186     }
00187     return depResults->getFinalDep();
00188 }
00189 
00192 OA_ptr<DataFlow::DataFlowSet>
00193 ManagerInterDep::atCallGraphEdge(
00194         OA_ptr<DataFlow::DataFlowSet> inSet, 
00195         CallHandle call, ProcHandle caller, ProcHandle callee )
00196 {
00197    if (debug) {
00198        std::cout << "atCallGraphEdge::inSet = ";
00199        inSet->dump(std::cout, mIR);
00200    }
00201         
00202    // cast DataFlowSet to more specific subclass
00203    OA_ptr<DepDFSet> recastInSet = inSet.convert<DepDFSet>();
00204 
00205    // create a new DepDFSet that is empty
00206    OA_ptr<DepDFSet> retval;
00207    retval = new DepDFSet;
00208 
00209    assert(callee != ProcHandle(0));
00210 
00211    // iterate over the deps for the call
00212    OA_ptr<DepIterator> depIter = recastInSet->getDepIterator();
00213    for ( ; depIter->isValid(); (*depIter)++ ) {
00214      OA_ptr<Location> useLoc = depIter->use();
00215      OA_ptr<Location> defLoc = depIter->def();
00216      if (debug) {
00217        std::cout << "\tuseLoc = ";
00218        useLoc->dump(std::cout,mIR);
00219        std::cout << std::endl;
00220        std::cout << "\tdefLoc = ";
00221        defLoc->dump(std::cout,mIR);
00222        std::cout << std::endl;
00223      }
00224 
00225      // see if either of these locations are part of implicit
00226      // deps that have been explicitly removed
00227      bool useLocImplicitRemove = false;
00228      bool defLocImplicitRemove = false;
00229      if (recastInSet->isImplicitRemoved(useLoc)) {
00230        useLocImplicitRemove = true;
00231      }
00232      if (recastInSet->isImplicitRemoved(defLoc)) {
00233        defLocImplicitRemove = true;
00234      }
00235 
00236      // have visitor convert both of these to may aliases 
00237      // in caller, if get null location then there is no
00238      // equivalent location in the caller
00239      OA_ptr<DataFlow::CalleeToCallerVisitor> useVisitor; 
00240      useVisitor = new DataFlow::CalleeToCallerVisitor(callee, call, 
00241                                                       caller, mInterAlias, mParamBind, mIR );
00242      useLoc->acceptVisitor(*useVisitor);
00243      OA_ptr<LocIterator> useIter = useVisitor->getCallerLocIterator();
00244 
00245      OA_ptr<DataFlow::CalleeToCallerVisitor> defVisitor;
00246      defVisitor = new DataFlow::CalleeToCallerVisitor(callee, call, 
00247                                                       caller, mInterAlias, mParamBind, mIR);
00248      defLoc->acceptVisitor(*defVisitor);
00249      OA_ptr<LocIterator> defIter = defVisitor->getCallerLocIterator();
00250 
00251      // insert these deps into retval
00252      for (useIter->reset() ; useIter->isValid(); (*useIter)++ ) {
00253        // remove implicit pair if necessary
00254        if (useLocImplicitRemove==true) {
00255          retval->removeImplicitDep(useIter->current(),
00256                                    useIter->current());
00257        }
00258        for (defIter->reset(); defIter->isValid(); (*defIter)++ ) {
00259          retval->insertDep(useIter->current(), defIter->current());
00260          if (debug) {
00261            std::cout << "Inserting into retval, use = ";
00262            useIter->current()->dump(std::cout,mIR);
00263            std::cout << "Inserting into retval, def = ";
00264            defIter->current()->dump(std::cout,mIR);
00265          }
00266 
00267          // remove implicit pair if necessary
00268          if (defLocImplicitRemove==true) {
00269            retval->removeImplicitDep(defIter->current(),
00270                                      defIter->current());
00271          }
00272        }
00273      }
00274 
00275    } 
00276    
00277    // the generated DepDFSet must be associated to the specific call
00278    // to be of any use
00279    mInterDep->mapCallToDep(call, retval);
00280    
00281    return retval;
00282 }
00283 
00284 
00287 OA_ptr<DataFlow::DataFlowSet>
00288 ManagerInterDep::atCallGraphEdge(
00289         OA_ptr<DataFlow::DataFlowSet> inSet, 
00290         CallHandle call, ProcHandle caller, SymHandle callee )
00291 {
00292   if (debug) {
00293     std::cout << "atCallGraphEdge::inSet = ";
00294     inSet->dump(std::cout, mIR);
00295   }
00296   
00297   // cast DataFlowSet to more specific subclass
00298   OA_ptr<DepDFSet> recastInSet = inSet.convert<DepDFSet>();
00299   
00300   // create a new DepDFSet that is empty
00301   OA_ptr<DepDFSet> retval;
00302   retval = new DepDFSet;
00303   
00304   // if callee node is undefined then estimate Dep with side-effect results
00305   // FIXME: no way to pass up must defs, but this will still give us
00306   // a conservative estimate
00307   if (debug) { std::cout << "\tcallee is undefined" << std::endl; }
00308   // get side-effect MOD locations and USE locations
00309   // and make dep pairs
00310   OA_ptr<LocIterator> useIter = mInterSE->getUSEIterator(call);
00311   OA_ptr<LocIterator> modIter = mInterSE->getMODIterator(call);
00312   for (modIter->reset(); modIter->isValid(); (*modIter)++) {
00313     retval->insertDep(useIter->current(), modIter->current());
00314     if (debug) {
00315       std::cout << "\t\tuseIter->current = ";
00316       useIter->current()->dump(std::cout,mIR);
00317       std::cout << "\t\tmodIter->current = ";
00318       modIter->current()->dump(std::cout,mIR);
00319     }
00320   }
00321   
00322   // the generated DepDFSet must be associated to the specific call
00323   // to be of any use
00324   mInterDep->mapCallToDep(call, retval);
00325   
00326   return retval;
00327 }
00328 
00329 
00330 
00331 OA_ptr<DataFlow::DataFlowSet>  
00332 ManagerInterDep::nodeToEdge(ProcHandle proc, 
00333         OA_ptr<DataFlow::DataFlowSet> procDFSet, CallHandle call)
00334 {
00335   if (debug) {
00336       std::cout << "In ManagerInterDep::nodeToEdge" << std::endl;
00337   }
00338 
00339   return procDFSet;
00340 }
00341 
00344 OA_ptr<DataFlow::DataFlowSet>  
00345 ManagerInterDep::edgeToNode(CallHandle call, 
00346         OA_ptr<DataFlow::DataFlowSet> callDFSet, ProcHandle proc)
00347 {
00348     if (debug) {
00349         std::cout << "edgeToNode::callDFSet = ";
00350         callDFSet->dump(std::cout, mIR);
00351     }
00352     return callDFSet;
00353    /* 
00354     // cast DataFlowSet to more specific subclass
00355     OA_ptr<DepDFSet> recastCallDFSet = callDFSet.convert<DepDFSet>();
00356 
00357     // create a new DepDFSet that is empty
00358     OA_ptr<DepDFSet> retval;
00359     retval = new DepDFSet;
00360     
00361     // iterate over the deps for the call
00362     OA_ptr<DepIterator> depIter = recastCallDFSet->getDepIterator();
00363     for ( ; depIter->isValid(); (*depIter)++ ) {
00364         OA_ptr<Location> useLoc = depIter->use();
00365         OA_ptr<Location> defLoc = depIter->def();
00366         if (debug) {
00367             std::cout << "\tuseLoc = ";
00368             useLoc->dump(std::cout,mIR);
00369             std::cout << std::endl;
00370             std::cout << "\tdefLoc = ";
00371             defLoc->dump(std::cout,mIR);
00372             std::cout << std::endl;
00373         }
00374 
00375         // see if either of these locations are part of implicit
00376         // deps that have been explicitly removed
00377         bool useLocImplicitRemove = false;
00378         bool defLocImplicitRemove = false;
00379         if (recastCallDFSet->isImplicitRemoved(useLoc)) {
00380             useLocImplicitRemove = true;
00381         }
00382         if (recastCallDFSet->isImplicitRemoved(defLoc)) {
00383             defLocImplicitRemove = true;
00384         }
00385 
00386         // have visitor convert both of these to may aliases 
00387         // in caller, if get null location then there is no
00388         // equivalent location in the caller
00389         OA_ptr<DataFlow::CalleeToCallerVisitor> useVisitor; 
00390         useVisitor = new DataFlow::CalleeToCallerVisitor(call, 
00391                 proc, mInterAlias, mParamBind);
00392         useLoc->acceptVisitor(*useVisitor);
00393         OA_ptr<LocIterator> useIter = useVisitor->getCallerLocIterator();
00394 
00395         OA_ptr<DataFlow::CalleeToCallerVisitor> defVisitor;
00396         defVisitor = new DataFlow::CalleeToCallerVisitor(call, 
00397                 proc, mInterAlias, mParamBind);
00398         defLoc->acceptVisitor(*defVisitor);
00399         OA_ptr<LocIterator> defIter = defVisitor->getCallerLocIterator();
00400 
00401         // insert these deps into retval
00402         for (useIter->reset() ; useIter->isValid(); (*useIter)++ ) {
00403             // remove implicit pair if necessary
00404             if (useLocImplicitRemove==true) {
00405                 retval->removeImplicitDep(useIter->current(),
00406                                           useIter->current());
00407             }
00408             for (defIter->reset(); defIter->isValid(); (*defIter)++ ) {
00409                 retval->insertDep(useIter->current(), defIter->current());
00410                 if (debug) {
00411                     std::cout << "Inserting into retval, use = ";
00412                     useIter->current()->dump(std::cout,mIR);
00413                     std::cout << "Inserting into retval, def = ";
00414                     defIter->current()->dump(std::cout,mIR);
00415                 }
00416 
00417                 // remove implicit pair if necessary
00418                 if (defLocImplicitRemove==true) {
00419                     retval->removeImplicitDep(defIter->current(),
00420                                               defIter->current());
00421                 }
00422             }
00423         }
00424 
00425     } 
00426 
00427     // the generated DepDFSet must be associated to the specific call
00428     // to be of any use
00429     mInterDep->mapCallToDep(call, retval);
00430 
00431     return retval;
00432     */
00433 }
00434 
00435 
00436 
00437   } // end of namespace Activity
00438 } // end of namespace OA