Go to the documentation of this file.00001
00016 #include "ManagerReachDefsOverwriteStandard.hpp"
00017
00018
00019 namespace OA {
00020 namespace ReachDefsOverwrite {
00021
00022 static bool debug = false;
00023
00024
00025 ManagerReachDefsOverwriteStandard::ManagerReachDefsOverwriteStandard(OA_ptr<ReachDefs::ReachDefsIRInterface> _ir)
00026 : ReachDefs::ManagerReachDefsStandard(_ir) {}
00027
00028 OA_ptr<ReachDefsOverwriteStandard> ManagerReachDefsOverwriteStandard::performAnalysis(ProcHandle proc,
00029 OA_ptr<CFG::CFGInterface> cfg, OA_ptr<Alias::Interface> alias,
00030 OA_ptr<SideEffect::InterSideEffectInterface> interSE,
00031 DataFlow::DFPImplement algorithm)
00032 {
00033 if (debug) {
00034 std::cout << "In ReachDefsOverwrite::ManagerReachDefsOverwriteStandard::performAnalysis" << std::endl;
00035 }
00036 mReachDefOverwriteMap = new ReachDefsOverwriteStandard(proc);
00037
00038 mAlias = alias;
00039
00040 OA_ptr<OA::IRStmtIterator> sIt = mIR->getStmtIterator(proc);
00041 for ( ; sIt->isValid(); (*sIt)++) {
00042 OA::StmtHandle stmt = sIt->current();
00043 if (debug) {
00044 std::cout<< "\tstmt (" << stmt.hval() << ") = ";
00045 mIR->dump(stmt,std::cout);
00046 }
00047
00048 mStmtMustDefMap[stmt];
00049 mStmtMayDefMap[stmt];
00050
00051 OA_ptr<MemRefHandleIterator> defIterPtr = mIR->getDefMemRefs(stmt);
00052 for (; defIterPtr->isValid(); (*defIterPtr)++) {
00053 MemRefHandle ref = defIterPtr->current();
00054 if (debug) {
00055 std::cout << "\t\tdef ref (" << ref.hval() << ") = ";
00056 mIR->dump(ref,std::cout);
00057 }
00058 OA_ptr<LocIterator> locIterPtr = alias->getMustLocs(ref);
00059 for (; locIterPtr->isValid(); ++(*locIterPtr)) {
00060 mStmtMustDefMap[stmt].insert(locIterPtr->current());
00061 mStmtAllDefMap[stmt].insert(locIterPtr->current());
00062 }
00063 locIterPtr = alias->getMayLocs(ref);
00064 for (; locIterPtr->isValid(); ++(*locIterPtr)) {
00065 mStmtMayDefMap[stmt].insert(locIterPtr->current());
00066 mStmtAllDefMap[stmt].insert(locIterPtr->current());
00067 }
00068 }
00069
00070 OA_ptr<IRCallsiteIterator> callsiteItPtr = mIR->getCallsites(stmt);
00071 for ( ; callsiteItPtr->isValid(); ++(*callsiteItPtr)) {
00072 CallHandle expr = callsiteItPtr->current();
00073 OA_ptr<LocIterator> locIterPtr;
00074
00075 locIterPtr = interSE->getMODIterator(expr);
00076 for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
00077 OA_ptr<Location> modLocPtr = locIterPtr->current();
00078 mStmtMayDefMap[stmt].insert(modLocPtr);
00079 mStmtAllDefMap[stmt].insert(modLocPtr);
00080 }
00081
00082 locIterPtr = interSE->getDEFIterator(expr);
00083 for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
00084 OA_ptr<Location> defLocPtr = locIterPtr->current();
00085 mStmtMustDefMap[stmt].insert(defLocPtr);
00086 mStmtAllDefMap[stmt].insert(defLocPtr);
00087 }
00088 }
00089 }
00090
00091
00092
00093 mSolver->solve(cfg,algorithm);
00094
00095 OA_ptr<CFG::NodeInterface> node;
00096 node = cfg->getExit();
00097 OA_ptr<DataFlow::DataFlowSet> x = mSolver->getOutSet(node);
00098
00099 OA_ptr<DataFlow::IRHandleDataFlowSet<StmtHandle> > inSet
00100 = x.convert<DataFlow::IRHandleDataFlowSet<StmtHandle> >();
00101 DataFlow::IRHandleIterator<StmtHandle> rdIter(inSet);
00102 for (; rdIter.isValid(); ++rdIter) {
00103 StmtHandle reachDef = rdIter.current();
00104 mReachDefOverwriteMap->insertExitReachDef(reachDef);
00105 }
00106 return mReachDefOverwriteMap;
00107 }
00108
00109
00119 OA_ptr<DataFlow::DataFlowSet>
00120 ManagerReachDefsOverwriteStandard::transfer(OA_ptr<DataFlow::DataFlowSet> in, OA::StmtHandle stmt)
00121 {
00122 OA_ptr<DataFlow::IRHandleDataFlowSet<StmtHandle> > inRecast
00123 = in.convert<DataFlow::IRHandleDataFlowSet<StmtHandle> >();
00124 if (debug) {
00125 std::cout << "In transfer, stmt(hval=" << stmt.hval() << ")= ";
00126 mIR->dump(stmt,std::cout);
00127 }
00128
00129
00130
00131 DataFlow::IRHandleIterator<StmtHandle> inIter(inRecast);
00132 for (; inIter.isValid(); ) {
00133 StmtHandle reachdef = inIter.current();
00134 if (debug) {
00135 std::cout << "\treachdef in Inset = ";
00136 mIR->dump(reachdef,std::cout);
00137 }
00138
00139 mReachDefOverwriteMap->insertReachDef(stmt,reachdef);
00140
00141
00142 OA_ptr<std::set<OA_ptr<Location> > > killLocSetPtr
00143 = intersectLocSets(mStmtMayDefMap[reachdef],
00144 mStmtMustDefMap[stmt]);
00145 if (debug) {
00146 std::cout << "\tMayDefs for reachdef = ";
00147 dumpLocSet(mStmtMayDefMap[reachdef],std::cout,mIR);
00148 std::cout << "\tMustDefs for stmt(hval=" << stmt.hval() << ")= ";
00149 dumpLocSet(mStmtMustDefMap[stmt],std::cout,mIR);
00150 std::cout << "\tkillLocSet for stmt(hval=" << stmt.hval() << "(= ";
00151 dumpLocSet(*killLocSetPtr,std::cout,mIR);
00152 }
00153
00154
00155
00156 if ( !killLocSetPtr->empty()
00157 && subSetOf(mStmtMayDefMap[reachdef],*killLocSetPtr) ) {
00158 ++inIter ;
00159 if (debug) {
00160 std::cout << "\tStmt in Kill set: ";
00161 mIR->dump(reachdef,std::cout);
00162 }
00163
00164 inRecast->remove(reachdef);
00165 } else {
00166 ++inIter;
00167 }
00168
00169 OA_ptr<std::set<OA_ptr<Location> > > modLocSet
00170 = intersectLocSets(mStmtAllDefMap[reachdef],
00171 mStmtAllDefMap[stmt]);
00172 if ( !modLocSet->empty() )
00173 mReachDefOverwriteMap->insertOverwrittenBy(reachdef, stmt);
00174 }
00175
00176
00177 if (!mStmtMayDefMap[stmt].empty()) {
00178
00179 inRecast->insert(stmt);
00180 if (debug) {
00181 std::cout << "\tStmt in Def set: ";
00182 mIR->dump(stmt,std::cout);
00183 }
00184 }
00185 return inRecast;
00186 }
00187
00188 }
00189 }