ManagerLivenessStandard.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005 #include "ManagerLivenessStandard.hpp"
00006
00007
00008 namespace OA {
00009 namespace Liveness {
00010
00011 static bool debug = false;
00012
00013
00016 ManagerLivenessStandard::ManagerLivenessStandard(OA_ptr<LivenessIRInterface> _ir)
00017 : mIR(_ir)
00018 {
00019 OA_DEBUG_CTRL_MACRO("DEBUG_ManagerLivenessStandard:ALL", debug);
00020 mSolver = new DataFlow::CFGDFSolver(DataFlow::CFGDFSolver::Backward,*this);
00021 }
00022
00023 OA_ptr<DataFlow::DataFlowSet> ManagerLivenessStandard::initializeTop()
00024 {
00025 OA_ptr<DataFlow::LocDFSet> retval;
00026 retval = new DataFlow::LocDFSet;
00027 return retval;
00028 }
00029
00030 OA_ptr<DataFlow::DataFlowSet> ManagerLivenessStandard::initializeBottom()
00031 {
00032 OA_ptr<DataFlow::LocDFSet> retval;
00033 retval = new DataFlow::LocDFSet;
00034 return retval;
00035 }
00036
00037 OA_ptr<LivenessStandard> ManagerLivenessStandard::performAnalysis(ProcHandle proc,
00038 OA_ptr<CFG::CFGInterface> cfg, OA_ptr<Alias::Interface> alias,
00039 OA_ptr<SideEffect::InterSideEffectInterface> interSE,
00040 DataFlow::DFPImplement algorithm)
00041 {
00042 if (debug) {
00043 std::cout << "In Liveness::ManagerLivenessStandard::performAnalysis" << std::endl;
00044 }
00045 mLiveMap = new LivenessStandard(proc);
00046
00047
00048 mAlias = alias;
00049
00050
00051 OA_ptr<OA::IRStmtIterator> sIt = mIR->getStmtIterator(proc);
00052 for ( ; sIt->isValid(); (*sIt)++) {
00053 OA::StmtHandle stmt = sIt->current();
00054 if (debug) {
00055 std::cout<< "\tstmt (" << stmt.hval() << ") = ";
00056 mIR->dump(stmt,std::cout);
00057 }
00058
00059
00060 mStmtMustDefMap[stmt];
00061 mStmtMayUseMap[stmt];
00062
00063
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 }
00078
00079
00080 OA_ptr<IRCallsiteIterator> callsiteItPtr = mIR->getCallsites(stmt);
00081 for ( ; callsiteItPtr->isValid(); ++(*callsiteItPtr)) {
00082 CallHandle expr = callsiteItPtr->current();
00083
00084 OA_ptr<LocIterator> locIterPtr;
00085
00086
00087 locIterPtr = interSE->getDEFIterator(expr);
00088 for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
00089 OA_ptr<Location> defLocPtr = locIterPtr->current();
00090 mStmtMustDefMap[stmt].insert(defLocPtr);
00091 }
00092 }
00093
00094
00095 OA_ptr<MemRefHandleIterator> useIterPtr = mIR->getUseMemRefs(stmt);
00096 for (; useIterPtr->isValid(); (*useIterPtr)++) {
00097 MemRefHandle useref = useIterPtr->current();
00098 if (debug) {
00099 std::cout << "\t\tuse ref (" << useref.hval() << ") = ";
00100 mIR->dump(useref,std::cout);
00101 }
00102
00103 OA_ptr<LocIterator> uselocIterPtr = alias->getMayLocs(useref);
00104 for (; uselocIterPtr->isValid(); ++(*uselocIterPtr)) {
00105 mStmtMayUseMap[stmt].insert(uselocIterPtr->current());
00106 }
00107
00108 }
00109
00110
00111 }
00112
00113
00114
00115
00116
00117 mSolver->solve(cfg,algorithm);
00118
00119
00120 OA_ptr<CFG::NodeInterface> node;
00121
00122 node = cfg->getExit();
00123
00124 OA_ptr<DataFlow::DataFlowSet> x = mSolver->getOutSet(node);
00125
00126 OA_ptr<DataFlow::LocDFSet> inSet
00127 = x.convert<DataFlow::LocDFSet >();
00128
00129
00130 return mLiveMap;
00131
00132 }
00133
00134 OA_ptr<DataFlow::DataFlowSet>
00135 ManagerLivenessStandard::initializeNodeIN(OA_ptr<CFG::NodeInterface> n)
00136 {
00137 OA_ptr<DataFlow::LocDFSet> retval;
00138 retval = new DataFlow::LocDFSet;
00139 return retval;
00140 }
00141
00142 OA_ptr<DataFlow::DataFlowSet>
00143 ManagerLivenessStandard::initializeNodeOUT(OA_ptr<CFG::NodeInterface> n)
00144 {
00145 OA_ptr<DataFlow::LocDFSet> retval;
00146 retval = new DataFlow::LocDFSet;
00147 return retval;
00148 }
00149
00150
00151
00152 OA_ptr<DataFlow::DataFlowSet>
00153 ManagerLivenessStandard::meet (OA_ptr<DataFlow::DataFlowSet> set1orig,
00154 OA_ptr<DataFlow::DataFlowSet> set2orig)
00155 {
00156 OA_ptr<DataFlow::LocDFSet> set1
00157 = set1orig.convert<DataFlow::LocDFSet>();
00158 if (debug) {
00159 std::cout << "ManagerLivenessStandard::meet" << std::endl;
00160 std::cout << "\tset1 = ";
00161 set1->dump(std::cout,mIR);
00162 std::cout << ", set2 = ";
00163 set2orig->dump(std::cout,mIR);
00164 }
00165
00166 DataFlow::LocDFSet retval
00167 = set1->setUnion(*set2orig);
00168 if (debug) {
00169 std::cout << std::endl << "\tretval set = ";
00170 retval.dump(std::cout,mIR);
00171 std::cout << std::endl;
00172 }
00173
00174 return retval.clone();
00175 }
00176
00177
00178 OA_ptr<DataFlow::DataFlowSet>
00179 ManagerLivenessStandard::transfer(OA_ptr<DataFlow::DataFlowSet> in, OA::StmtHandle stmt)
00180 {
00181 OA_ptr<DataFlow::LocDFSet> inRecast
00182 = in.convert<DataFlow::LocDFSet>();
00183
00184 if (debug) {
00185 std::cout << "In transfer, stmt(hval=" << stmt.hval() << ")= ";
00186 mIR->dump(stmt,std::cout);
00187 }
00188
00189
00190 DataFlow::LocDFSetIterator inIter(*inRecast);
00191 for (; inIter.isValid(); ++inIter) {
00192 OA_ptr<Location> livevar = inIter.current();
00193 if (debug) {
00194 std::cout << "\tlivevar in Inset = ";
00195 livevar->dump(std::cout,mIR);
00196 }
00197
00198 mLiveMap->insertLive(stmt,livevar);
00199 }
00200 LocSet::iterator setIter;
00201 for (setIter=mStmtMustDefMap[stmt].begin(); setIter!=mStmtMustDefMap[stmt].end(); setIter++) {
00202 OA_ptr<Location> loc = *setIter;
00203 inRecast->remove(loc);
00204 mLiveMap->removeLive(stmt,loc);
00205
00206 }
00207
00208 LocSet::iterator gensetIter;
00209 for (gensetIter=mStmtMayUseMap[stmt].begin(); gensetIter!=mStmtMayUseMap[stmt].end(); gensetIter++) {
00210 OA_ptr<Location> loc = *gensetIter;
00211 inRecast->insert(loc);
00212 mLiveMap->insertLive(stmt,loc);
00213
00214 }
00215
00216 return inRecast;
00217 }
00218
00219 }
00220 }