ManagerAutoDFAGenReachingDefinitionsStandard.cpp

Go to the documentation of this file.
00001 
00002 // ManagerDFAGenReachingDefinitionsStandard.cpp
00003 
00004 #include <OpenAnalysis/DataFlow/ReachDefs/ManagerDFAGenReachingDefinitionsStandard.hpp>
00005 
00006 namespace OA {
00007   namespace DFAGenReachingDefinitions {
00008 
00009 static bool debug = false;
00010 
00011 
00014 ManagerDFAGenReachingDefinitionsStandard::ManagerDFAGenReachingDefinitionsStandard(OA_ptr<DFAGenReachingDefinitionsIRInterface> _ir) 
00015     : mIR(_ir)
00016 {
00017    OA_DEBUG_CTRL_MACRO("DEBUG_ManagerDFAGenReachingDefinitionsStandard:ALL", debug);
00018    mSolver = new DataFlow::CFGDFSolver(DataFlow::CFGDFSolver::Forward,*this);
00019 }
00020 
00021 OA_ptr<DataFlow::DataFlowSet> ManagerDFAGenReachingDefinitionsStandard::initializeTop()
00022 {
00023     OA_ptr<DataFlow::IRHandleDataFlowSet<StmtHandle>>  retval;
00024     retval = new DataFlow::IRHandleDataFlowSet<StmtHandle>;
00025     return retval;
00026 }
00027 
00028 OA_ptr<DataFlow::DataFlowSet> ManagerDFAGenReachingDefinitionsStandard::initializeBottom()
00029 {
00030     OA_ptr<DataFlow::IRHandleDataFlowSet<StmtHandle>>  retval;
00031     retval = new DataFlow::IRHandleDataFlowSet<StmtHandle>;
00032     return retval;
00033 }
00034 
00035 
00036 OA_ptr<DFAGenReachingDefinitionsStandard> ManagerDFAGenReachingDefinitionsStandard::performAnalysis(ProcHandle proc, 
00037     OA_ptr<CFG::CFGInterface> cfg, OA_ptr<Alias::Interface> alias,
00038     OA_ptr<SideEffect::InterSideEffectInterface> interSE)
00039 {
00040   if (debug) {
00041     std::cout << "In DFAGenReachingDefinitions::ManagerDFAGenReachingDefinitionsStandard::performAnalysis" << std::endl;
00042   }
00043   mDFAGenReachingDefinitionsMap = new DFAGenReachingDefinitionsStandard(proc);
00044 
00045   // store Alias information for use within the transfer function
00046   mAlias = alias;
00047 
00048   // get mapping of stmt to locations they may and must define
00049   OA_ptr<OA::IRStmtIterator> sIt = mIR->getStmtIterator(proc);
00050   for ( ; sIt->isValid(); (*sIt)++) {
00051     OA::StmtHandle stmt = sIt->current();
00052     if (debug) {
00053       std::cout<< "\tstmt (" << stmt.hval() << ") = ";
00054       mIR->dump(stmt,std::cout);
00055     } 
00056     
00057     // initialize each stmt to define an empty set of locations
00058     mStmtMustDefMap[stmt];
00059     mStmtMustUseMap[stmt];
00060     mStmtMayDefMap[stmt];
00061     mStmtMayUseMap[stmt];
00062 
00063     // locations that each statement may or must def
00064     OA_ptr<MemRefHandleIterator> defIterPtr = mIR->getDefMemRefs(stmt);
00065     for (; defIterPtr->isValid(); (*defIterPtr)++) {
00066         MemRefHandle ref = defIterPtr->current();
00067         if (debug) {
00068           std::cout << "\t\tdef ref (" << ref.hval() << ") = ";
00069           mIR->dump(ref,std::cout);
00070         }
00071 
00072         OA_ptr<LocIterator> locIterPtr = alias->getMustLocs(ref);
00073         for (; locIterPtr->isValid(); ++(*locIterPtr)) {
00074             mStmtMustDefMap[stmt].insert(locIterPtr->current());
00075         }
00076 
00077         locIterPtr = alias->getMayLocs(ref);
00078         for (; locIterPtr->isValid(); ++(*locIterPtr)) {
00079             mStmtMayDefMap[stmt].insert(locIterPtr->current());
00080         }
00081     }
00082  
00083     // must or may defines from procedure calls
00084     OA_ptr<IRCallsiteIterator> callsiteItPtr = mIR->getCallsites(stmt);
00085     for ( ; callsiteItPtr->isValid(); ++(*callsiteItPtr)) {
00086       CallHandle expr = callsiteItPtr->current();
00087 
00088       OA_ptr<LocIterator> locIterPtr;
00089       
00090       // MOD
00091       locIterPtr = interSE->getMODIterator(expr);
00092       for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
00093           OA_ptr<Location> modLocPtr = locIterPtr->current();
00094           mStmtMayDefMap[stmt].insert(modLocPtr);
00095       }
00096       
00097       // DEF
00098       locIterPtr = interSE->getDEFIterator(expr);
00099       for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
00100           OA_ptr<Location> defLocPtr = locIterPtr->current();
00101           mStmtMustDefMap[stmt].insert(defLocPtr);
00102       }
00103     }
00104     
00105     
00106        OA_ptr<MemRefHandleIterator> useIterPtr = mIR->getUseMemRefs(stmt);
00107         for (; useIterPtr->isValid(); (*useIterPtr)++ ) {
00108             MemRefHandle useref = useIterPtr->current();
00109              if (debug) {
00110                    std::cout << "\t\tuse ref (" << useref.hval() << ") = ";
00111                    mIR->dump(useref,std::cout);
00112              }
00113 
00114             OA_ptr<LocIterator> locIterPtr = mAlias->getMayLocs(useref);
00115             for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00116                // mLiveMap->insertLive(stmt,locIterPtr->current());
00117                mStmtMayUseMap[stmt].insert(locIterPtr->current());
00118             }
00119         }
00120         
00121   } // loop over statements
00122 
00123   // use the dataflow solver to get the In and Out sets for the BBs
00124   //DataFlow::CFGDFProblem::solve(cfg);
00125   //
00126   mSolver->solve(cfg);  
00127   
00128   // get exit node for CFG and determine what definitions reach that node
00129   OA_ptr<CFG::NodeInterface> node;
00130   
00131   node = cfg->getExit();
00132 
00133   OA_ptr<DataFlow::DataFlowSet> x = mSolver->getOutSet(node);
00134       
00135   OA_ptr<DataFlow::IRHandleDataFlowSet<StmtHandle>> inSet 
00136     = x.convert<DataFlow::IRHandleDataFlowSet<StmtHandle>>();
00137 
00138   return mDFAGenReachingDefinitionsMap;
00139 
00140 }
00141 
00142 OA_ptr<DataFlow::DataFlowSet>
00143 ManagerDFAGenReachingDefinitionsStandard::initializeNodeIN(OA_ptr<CFG::NodeInterface> n)
00144 {
00145      OA_ptr<DataFlow::IRHandleDataFlowSet<StmtHandle> >  retval;
00146      retval = new DataFlow::IRHandleDataFlowSet<StmtHandle>;
00147      return retval;
00148 }
00149 
00150 OA_ptr<DataFlow::DataFlowSet>
00151 ManagerDFAGenReachingDefinitionsStandard::initializeNodeOUT(OA_ptr<CFG::NodeInterface> n)
00152 {
00153      OA_ptr<DataFlow::IRHandleDataFlowSet<StmtHandle>>  retval;
00154      retval = new DataFlow::IRHandleDataFlowSet<StmtHandle>;
00155      return retval;
00156 }
00157 
00158 OA_ptr<DataFlow::DataFlowSet> 
00159 ManagerDFAGenReachingDefinitionsStandard::meet (OA_ptr<DataFlow::DataFlowSet> set1orig, 
00160                        OA_ptr<DataFlow::DataFlowSet> set2orig)
00161 {
00162     OA_ptr<DataFlow::IRHandleDataFlowSet<StmtHandle>> set1
00163         = set1orig.convert<DataFlow::IRHandleDataFlowSet<StmtHandle>>();
00164     if (debug) {
00165         std::cout << "ManagerDFAGenReachingDefinitionsStandard::meet" << std::endl;
00166         std::cout << "\tset1 = ";
00167         set1->dump(std::cout,mIR);
00168         std::cout << ", set2 = ";
00169         set2orig->dump(std::cout,mIR);
00170     }
00171      
00172     
00173     DataFlow::IRHandleDataFlowSet<StmtHandle> retval 
00174         = set1->setUnion(*set2orig);
00175     if (debug) {
00176         std::cout << std::endl << "\tretval set = ";
00177         retval.dump(std::cout,mIR);
00178         std::cout << std::endl;
00179     }
00180        
00181     return retval.clone();
00182 }
00183 
00184 
00185 OA_ptr<DataFlow::DataFlowSet> 
00186 ManagerDFAGenReachingDefinitionsStandard::transfer(OA_ptr<DataFlow::DataFlowSet> in, OA::StmtHandle stmt) 
00187 {
00188     OA_ptr<DataFlow::IRHandleDataFlowSet<StmtHandle>> inRecast 
00189         = in.convert<IRHandleDataFlowSet<StmtHandle>>();
00190 
00191     if (debug) {
00192         std::cout << "In transfer, stmt(hval=" << stmt.hval() << ")= ";
00193         mIR->dump(stmt,std::cout);
00194     }
00195         
00196     
00197   //IN
00198          
00199     DataFlow::IRHandleIterator<StmtHandle> inIter(*inRecast);
00200     for (; inIter.isValid(); ++inIter) {
00201         StmtHandle dfagenreachingdefinitions = inIter.current();
00202         if (debug) {
00203           std::cout << "\tdfagenreachingdefinitions in Inset = ";
00204           mIR->dump(dfagenreachingdefinitions,std::cout);
00205         }
00206 
00207         // insert DFAGenReachingDefinitions into results
00208         mDFAGenReachingDefinitionsMap->insertDFAGenReachingDefinitions(stmt,dfagenreachingdefinitions);
00209    }      
00210 
00211 
00212 //KILL
00213 
00214 //GEN
00215 
00216     return inRecast;
00217 }
00218 
00219   } // end of namespace DFAGenReachingDefinitions
00220 } // end of namespace OA