Go to the documentation of this file.00001
00015 #include "ManagerICFGDep.hpp"
00016 #include <Utils/Util.hpp>
00017
00018
00019 namespace OA {
00020 namespace Activity {
00021
00022 static bool debug = false;
00023
00024
00027 ManagerICFGDep::ManagerICFGDep(OA_ptr<ActivityIRInterface> _ir) : mIR(_ir)
00028 {
00029 OA_DEBUG_CTRL_MACRO("DEBUG_ManagerICFGDep:ALL", debug);
00030 mSolver = new DataFlow::ICFGDFSolver(DataFlow::ICFGDFSolver::Forward,*this);
00031 }
00032
00033
00037 OA_ptr<ICFGDep> ManagerICFGDep::performAnalysis(
00038 OA_ptr<ICFG::ICFGInterface> icfg,
00039 OA_ptr<DataFlow::ParamBindings> paramBind,
00040 OA_ptr<Alias::InterAliasInterface> interAlias,
00041 DataFlow::DFPImplement algorithm)
00042 {
00043 if (debug) {
00044 std::cout << "In ManagerICFGDep::performAnalysis" << std::endl;
00045 }
00046 mDep = new ICFGDep();
00047
00048
00049 mICFG = icfg;
00050 mParamBind = paramBind;
00051 mInterAlias = interAlias;
00052
00053
00054 mSolver->solve(icfg,algorithm);
00055
00056 return mDep;
00057
00058 }
00059
00060
00061
00062
00063
00064
00065
00066 OA_ptr<DataFlow::DataFlowSet>
00067 ManagerICFGDep::initializeTop()
00068 {
00069 OA_ptr<DepDFSet> retval;
00070 retval = new DepDFSet;
00071 return retval;
00072 }
00073
00077 OA_ptr<DataFlow::DataFlowSet>
00078 ManagerICFGDep::initializeNodeIN(OA_ptr<ICFG::NodeInterface> n)
00079 {
00080 return initializeTop();
00081 }
00082
00083 OA_ptr<DataFlow::DataFlowSet>
00084 ManagerICFGDep::initializeNodeOUT(OA_ptr<ICFG::NodeInterface> n)
00085 {
00086 return initializeTop();
00087 }
00088
00089
00090
00091
00092
00095 OA_ptr<DataFlow::DataFlowSet>
00096 ManagerICFGDep::meet (OA_ptr<DataFlow::DataFlowSet> set1,
00097 OA_ptr<DataFlow::DataFlowSet> set2)
00098 {
00099 return set1;
00100 }
00101
00108 OA_ptr<DataFlow::DataFlowSet>
00109 ManagerICFGDep::transfer(ProcHandle proc,
00110 OA_ptr<DataFlow::DataFlowSet> in, OA::StmtHandle stmt)
00111 {
00112 if (debug) {
00113 std::cout << "\tIn transfer, stmt(hval=" << stmt.hval() << ")= ";
00114 mIR->dump(stmt,std::cout);
00115 }
00116
00117
00118 OA_ptr<Alias::Interface> alias = mInterAlias->getAliasResults(proc);
00119
00120
00121 OA_ptr<DepDFSet> stmtDepDFSet;
00122 stmtDepDFSet = new DepDFSet;
00123
00124
00125 LocSet mustDefSet;
00126 LocSet mayDefSet;
00127 LocSet diffUseSet;
00128
00129
00130 std::set<ExprHandle> exprSet;
00131
00132 OA_ptr<AssignPairIterator> espIterPtr
00133 = mIR->getAssignPairIterator(stmt);
00134
00135 if(!espIterPtr.ptrEqual(0)) {
00136
00137 for ( ; espIterPtr->isValid(); ++(*espIterPtr)) {
00138
00139 MemRefHandle mref = espIterPtr->currentTarget();
00140 ExprHandle expr = espIterPtr->currentSource();
00141 if (debug) {
00142 std::cout << "\tmref = " << mIR->toString(mref) << ", ";
00143 std::cout << "expr = " << mIR->toString(expr) << std::endl;
00144 }
00145
00146
00147 exprSet.insert(expr);
00148 if (debug) {
00149 std::cout << "Inserting memref = expr into exprSet"
00150 << std::endl;
00151 OA_ptr<ExprTree> etree = mIR->getExprTree(expr);
00152 etree->dump(std::cout,mIR);
00153 }
00154
00155
00156 OA_ptr<LocIterator> locIterPtr = alias->getMustLocs(mref);
00157 for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00158 if (debug) {
00159 std::cout << "Inserting into mustDefSet: ";
00160 (locIterPtr->current())->output(*mIR);
00161 std::cout << std::endl;
00162 }
00163 mustDefSet.insert(locIterPtr->current());
00164 }
00165
00166
00167 locIterPtr = alias->getMayLocs(mref);
00168 for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00169 if (debug) {
00170 std::cout << "Inserting into mayDefSet: ";
00171 (locIterPtr->current())->output(*mIR);
00172 std::cout << std::endl;
00173 }
00174 mayDefSet.insert(locIterPtr->current());
00175 }
00176 }
00177
00178
00179 } else {
00180 if (debug) {
00181 std::cout << "\tstmt is not EXPR_STMT, stmt = "
00182 << mIR->toString(stmt) << std::endl;
00183 }
00184
00185 OA_ptr<MemRefHandleIterator> mrIterPtr = mIR->getUseMemRefs(stmt);
00186
00187 for (; mrIterPtr->isValid(); (*mrIterPtr)++ ) {
00188 MemRefHandle mref = mrIterPtr->current();
00189 if (debug) {
00190 std::cout << "getting mayLocs for memrefHandle: "
00191 << mIR->toString(mref) << std::endl;
00192 }
00193 OA_ptr<LocIterator> locIterPtr = alias->getMayLocs(mref);
00194 for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00195 if (debug) {
00196 std::cout << "Inserting into diffUseSet: ";
00197 (locIterPtr->current())->output(*mIR);
00198 std::cout << std::endl;
00199 }
00200 diffUseSet.insert(locIterPtr->current());
00201 }
00202 }
00203
00204 mrIterPtr = mIR->getDefMemRefs(stmt);
00205 for (; mrIterPtr->isValid(); (*mrIterPtr)++ ) {
00206 MemRefHandle mref = mrIterPtr->current();
00207 OA_ptr<LocIterator> locIterPtr = alias->getMustLocs(mref);
00208 for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00209 mustDefSet.insert(locIterPtr->current());
00210 }
00211 locIterPtr = alias->getMayLocs(mref);
00212 for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00213 mayDefSet.insert(locIterPtr->current());
00214 }
00215 }
00216 }
00217
00218
00219
00220
00221 OA_ptr<IRCallsiteIterator> callsiteItPtr = mIR->getCallsites(stmt);
00222 for ( ; callsiteItPtr->isValid(); ++(*callsiteItPtr)) {
00223 CallHandle call = callsiteItPtr->current();
00224 if (debug) {
00225 std::cout << "\nhandling all callsite params, ";
00226 std::cout << "call = " << mIR->toString(call) << std::endl;
00227 }
00228
00229
00230 OA_ptr<IRCallsiteParamIterator> cspIterPtr
00231 = mIR->getCallsiteParams(call);
00232 for ( ; cspIterPtr->isValid(); ++(*cspIterPtr)) {
00233 ExprHandle param = cspIterPtr->current();
00234 exprSet.insert(param);
00235 }
00236 }
00237
00238
00239 if (debug) { std::cout << "ExprTree's:" << std::endl; }
00240 DifferentiableLocsVisitor dlVisitor(alias);
00241 std::set<ExprHandle>::iterator exprIter;
00242 for (exprIter=exprSet.begin(); exprIter!=exprSet.end(); exprIter++) {
00243 OA_ptr<ExprTree> etree = mIR->getExprTree(*exprIter);
00244 if (debug) { etree->dump(std::cout,mIR); }
00245 etree->acceptVisitor(dlVisitor);
00246 OA_ptr<LocIterator> locIterPtr
00247 = dlVisitor.getDiffLocsIterator();
00248 if (debug) {
00249 std::cout << "getting diffLocsIterator\n";
00250 }
00251 for ( ; locIterPtr->isValid(); (*locIterPtr)++ ) {
00252 if (debug) {
00253 std::cout << "Inserting into diffUseSet: ";
00254 (locIterPtr->current())->output(*mIR);
00255 std::cout << std::endl;
00256 }
00257 diffUseSet.insert(locIterPtr->current());
00258 }
00259 }
00260
00261
00262
00263 LocSet::iterator useIter, defIter;
00264 for (defIter=mustDefSet.begin(); defIter!=mustDefSet.end(); defIter++) {
00265 mDep->insertMustDefForStmt(stmt,*defIter);
00266 stmtDepDFSet->removeImplicitDep(*defIter,*defIter);
00267 }
00268
00269
00270
00271
00272 OA_ptr<Location> use, def;
00273 for (useIter=diffUseSet.begin(); useIter!=diffUseSet.end(); useIter++) {
00274 for (defIter=mayDefSet.begin(); defIter!=mayDefSet.end(); defIter++) {
00275 stmtDepDFSet->insertDep(*useIter,*defIter);
00276 }
00277 }
00278
00279
00280 mDep->mapStmtToDeps(stmt, stmtDepDFSet);
00281
00282 return in;
00283 }
00284
00285 }
00286 }