CSFIActivity/DUGStandard.cpp

Go to the documentation of this file.
00001 
00014 //--------------------------------------------------------------------
00015 //--------------------------------------------------------------------
00016 
00017 // standard headers
00018 
00019 #include <string.h>
00020 #include <stdlib.h>
00021 #include <iostream>
00022 using std::ostream;
00023 using std::endl;
00024 using std::cout;
00025 using std::cerr;
00026 
00027 #include "DUGStandard.hpp"
00028 
00029 namespace OA {
00030   namespace DUG {
00031 
00032 //--------------------------------------------------------------------
00033 
00034 //--------------------------------------------------------------------
00035 // must be updated any time DUG::Interface::EdgeType changes
00036 static const char *sEdgeTypeToString[] = { 
00037     "F",
00038     "C",
00039     "R",
00040     "P"
00041 //   "CFLOW",
00042 //   "CALL",
00043 //   "RETURN",
00044 //   "PARAM"
00045 };
00046 static const char *sNodeTypeToString[] = { 
00047     "FORMALPARAM_NODE",
00048     "NONEFORMAL_NODE",
00049 };
00050 
00051 //--------------------------------------------------------------------
00054 void Node::Ctor() { 
00055 
00056     mDGNode = new DGraph::NodeImplement;
00057 
00058     mVaried = false;
00059     mUseful = false;
00060     mSelfDependent = false;
00061 #ifdef DEBUG_DUAA
00062     std::cout << "getId(" << getId() << ")" << std::endl;
00063 #endif
00064 }
00065 
00066 
00067 OA_ptr<EdgeInterface> EdgesIterator::currentDUGEdge() const
00068 {
00069     return current().convert<Edge>();
00070 }
00071 
00072 
00073 
00074 OA_ptr<NodeInterface> NodesIterator::currentDUGNode() const
00075 {
00076     return current().convert<Node>();
00077 }
00078 
00079 
00080 
00081 
00082 //--------------------------------------------------------------------
00083 void
00084 Node::dump (ostream& os, OA_ptr<IRHandlesIRInterface> ir)
00085 {
00086 //    os << sNodeTypeToString[mType] << std::endl;
00087     SymHandle sym = getSym();
00088     os << ir->toString(sym) << std::endl;
00089 }
00090 
00091 bool Node::operator==(DGraph::NodeInterface& other) 
00092 {
00093     
00094     return mDGNode->operator==(other);
00095 }
00096 
00097 bool Node::operator<(DGraph::NodeInterface& other) 
00098 {
00099     return mDGNode->operator<(other);
00100 }
00101 
00102 
00103 
00104 void
00105 Node::longdump (ostream& os, OA_ptr<IRHandlesIRInterface> ir)
00106 {
00107     // print the node ID
00108     os << "DUGStandard Node: ";
00109     dump(os,ir);
00110   
00111     if (isAnEntry()) {
00112         os << " (ENTRY)";
00113     } else if (isAnExit()) {
00114         os << " (EXIT)"; 
00115     }
00116     os << endl;
00117   
00118     // print the source(s)
00119     unsigned int count = 0;
00120     OA_ptr<NodesIteratorInterface> srcIter = getDUGSourceNodesIterator();
00121     for ( ; srcIter->isValid(); ++(*srcIter), ++count) {
00122         OA_ptr<NodeInterface> node = srcIter->currentDUGNode();
00123         if (count == 0) { os << " <-- ("; }
00124         else            { os << ", "; }
00125 
00126         node->dump(os,ir);
00127     }
00128     if (count > 0) { os << ")" << endl; }
00129   
00130     // print the sink(s)
00131     count = 0;
00132     OA_ptr<NodesIteratorInterface> outIter = getDUGSinkNodesIterator();
00133     for ( ; outIter->isValid(); ++(*outIter), ++count) {
00134         OA_ptr<NodeInterface> node = outIter->currentDUGNode();
00135         if (count == 0) { os << " --> ("; } 
00136         else            { os << ", "; }
00137     
00138         node->dump(os,ir);
00139     }
00140     if (count > 0) { os << ")" << endl; }
00141 }
00142 
00143 void
00144 Node::dumpdot (ostream& os, OA_ptr<DUGIRInterface> ir)
00145 {
00146     SymHandle sym = getSym();
00147     std::string str = ir->toString(sym);
00148 
00149     char buf1[20];
00150     sprintf(buf1, "(%u)\\n", getId());
00151 
00152     std::string::size_type loc = str.find( "::", 0);
00153     if( loc != std::string::npos ) str.erase(loc, 2);
00154 
00155     str.insert(loc, std::string(buf1));
00156     OA_ptr<Location> memLoc = mDUG->mIR->getLocation(mProc, sym);
00157     if (memLoc.ptrEqual(0)){
00158         std::cout << "^^^^^ NULL LOCATION ^^^^^" << std::endl;
00159         std::cout << "\tmProc(" << mDUG->mIR->toString(mProc);
00160         std::cout << "), sym(" << mDUG->mIR->toString(sym) 
00161                   << ")" << std::endl;
00162     }
00163     else if (!memLoc->isLocal()) {
00164         str.erase(0, loc);
00165         str.insert(0, std::string("JWGLOBAL"));
00166     }
00167     os << "\"" << str << "\"";
00168 }
00169 
00170 //--------------------------------------------------------------------
00171 
00172 OA_ptr<DGraph::EdgesIteratorInterface> 
00173 Node::getIncomingEdgesIterator() const
00174 {
00175     return mDGNode->getIncomingEdgesIterator();
00176 }
00177 
00178 OA_ptr<DGraph::EdgesIteratorInterface> 
00179 Node::getOutgoingEdgesIterator() const
00180 {
00181     return mDGNode->getOutgoingEdgesIterator();
00182 }
00183 
00184 OA_ptr<DGraph::NodesIteratorInterface> 
00185 Node::getSourceNodesIterator() const
00186 {
00187     return mDGNode->getSourceNodesIterator();
00188 }
00189 
00190 OA_ptr<DGraph::NodesIteratorInterface> 
00191 Node::getSinkNodesIterator() const
00192 {
00193     return mDGNode->getSourceNodesIterator();
00194 }
00195 
00196 OA_ptr<EdgesIteratorInterface>
00197 Node::getDUGIncomingEdgesIterator() const
00198 {
00199     OA_ptr<EdgesIterator> retval;
00200     retval = new EdgesIterator(getIncomingEdgesIterator());
00201     return retval;
00202 
00203 }
00204 
00205 OA_ptr<EdgesIteratorInterface>
00206 Node::getDUGOutgoingEdgesIterator() const
00207 {
00208     OA_ptr<EdgesIterator> retval;
00209     retval = new EdgesIterator(getOutgoingEdgesIterator());
00210     return retval;
00211 
00212 }
00213 
00214 OA_ptr<NodesIteratorInterface>
00215 Node::getDUGSourceNodesIterator() const
00216 {
00217     OA_ptr<NodesIterator> retval;
00218     retval = new NodesIterator(getSourceNodesIterator());
00219     return retval;
00220 
00221 }
00222 
00223 OA_ptr<NodesIteratorInterface>
00224 Node::getDUGSinkNodesIterator() const
00225 {
00226     OA_ptr<NodesIterator> retval;
00227     retval = new NodesIterator(getSinkNodesIterator());
00228     return retval;
00229 
00230 }
00231 
00232 
00233 
00234 //--------------------------------------------------------------------
00235 //--------------------------------------------------------------------
00236 Edge::Edge (OA_ptr<DUGStandard> pDUG,
00237             OA_ptr<Node> pNode1, 
00238             OA_ptr<Node> pNode2, 
00239             EdgeType pType, CallHandle call,
00240             ProcHandle proc)
00241     : mDUG(pDUG), mNode1(pNode1), mNode2(pNode2), mType(pType), 
00242       mCall(call), mProc(proc)
00243 {
00244 
00245     // create DGraphEdge for associated DGraph
00246     mDGEdge = new DGraph::EdgeImplement(pNode1->mDGNode,
00247                                         pNode2->mDGNode);
00248 
00249 }
00250 
00251 
00252 //--------------------------------------------------------------------
00253 bool Edge::operator==(DGraph::EdgeInterface& other) 
00254 {
00255     
00256     return mDGEdge->operator==(other);
00257 }
00258 
00259 bool Edge::operator<(DGraph::EdgeInterface& other) 
00260 {
00261     return mDGEdge->operator<(other);
00262 }
00263 
00264 
00265 
00266 void Edge::dump(ostream& os)
00267 {
00268     os << sEdgeTypeToString[mType];
00269 }
00270 
00271 void Edge::dumpdot(ostream& os, OA_ptr<DUGIRInterface> ir)
00272 {
00273     OA_ptr<NodeInterface> srcNode  = getDUGSource();
00274     OA_ptr<NodeInterface> sinkNode = getDUGSink();
00275 
00276     srcNode->dumpdot(os, ir);
00277     os << "->";
00278     sinkNode->dumpdot(os, ir);
00279     dumpdot_label(os, ir);
00280 }
00281 
00282 
00283 void filterStr(std::string& s)
00284 {
00285     std::string::size_type loc = s.find( "::", 0);
00286     if( loc != std::string::npos ) s.erase(0, loc+2);
00287 }
00288 
00289 
00290 
00291 void Edge::dumpdot_label(ostream& os, OA_ptr<DUGIRInterface> ir)
00292 {
00293     CallHandle call = getCall();
00294     EdgeType etype = getType();
00295     os << "[label=\"" << sEdgeTypeToString[etype];
00296     if (call != CallHandle(0)) os << "(" << call.hval() << ")";
00297     os << "\\n";
00298 
00299     ProcHandle proc = getProc();
00300     std::string procStr = ir->toString(proc);
00301     filterStr(procStr);
00302     os << procStr;
00303 
00304     if (call != CallHandle(0)){
00305         if (etype == CALL_EDGE)
00306             os << "\\n-> ";
00307         else{
00308             assert(etype == RETURN_EDGE);
00309             os << "\\n<- ";
00310         }
00311         SymHandle calleeSym = ir->getSymHandle(call);
00312         procStr = ir->toString(calleeSym);
00313         filterStr(procStr);
00314         os << procStr;
00315         os << "\", style=dashed];" << endl;
00316     }
00317     else
00318         os << "\"];" << endl;
00319 }
00320 
00321 
00322 //--------------------------------------------------------------------
00323 //--------------------------------------------------------------------
00324 DUGStandard::DUGStandard(
00325     OA_ptr<DUGIRInterface> pIR,
00326     OA_ptr<DataFlow::ParamBindings> pParamBind)
00327     : mIR(pIR), mParamBind(pParamBind)
00328 {
00329     mEntry       = mExit = NULL;
00330     mDGraph      = new DGraph::DGraphImplement;
00331     mCallNodes   = new std::list<OA_ptr<Node> >;
00332     mReturnNodes = new std::list<OA_ptr<Node> >;
00333     mActiveSymSet    = new std::set<SymHandle>;
00334     mActiveMemRefSet = new std::set<MemRefHandle>;
00335     mActiveStmtSet   = new std::set<StmtHandle>;
00336     mUnknownLocActive = false;
00337 }
00338 
00339 
00340 DUGStandard::~DUGStandard()
00341 {
00342     mEntry = NULL;
00343     mExit = NULL;
00344 }
00345 
00346 //--------------------------------------------------------------------
00347 // DUGStandard Methods
00348 //--------------------------------------------------------------------
00349 
00350 OA_ptr<Edge> 
00351 DUGStandard::getDUGEdge(
00352     const OA_ptr<DGraph::EdgeInterface> dgEdge) const
00353 {
00354 
00355     
00356     assert (0); 
00357     OA_ptr<Edge> retval;
00358     return retval;
00359 }
00360 
00361 OA_ptr<Node> 
00362 DUGStandard::getDUGNode(
00363     const OA_ptr<DGraph::NodeInterface> dgNode) const
00364 {
00365     assert(0);   
00366     OA_ptr<Node> retval;
00367     return retval; 
00368 }
00369 
00370 void DUGStandard::addEdge(OA_ptr<DGraph::EdgeInterface> pEdge)
00371 {
00372     mDGraph->addEdge(pEdge);
00373 }
00374 
00375 void DUGStandard::addNode(OA_ptr<DGraph::NodeInterface> pNode)
00376 {
00377     
00378     mDGraph->addNode(pNode);
00379 }
00380 
00381 
00382 OA_ptr<DGraph::NodesIteratorInterface> DUGStandard::getNodesIterator() const
00383 {
00384     return mDGraph->getNodesIterator();
00385 }
00386 
00387 OA_ptr<DGraph::NodesIteratorInterface>
00388 DUGStandard::getEntryNodesIterator( ) const
00389 {
00390     
00391     return mDGraph->getEntryNodesIterator();
00392 }
00393 
00394 OA_ptr<DGraph::NodesIteratorInterface>
00395 DUGStandard::getExitNodesIterator( ) const
00396 {
00397     return mDGraph->getExitNodesIterator();
00398 }
00399 
00400 
00401 OA_ptr<DGraph::EdgesIteratorInterface> DUGStandard::getEdgesIterator() const
00402 {
00403     
00404     return mDGraph->getEdgesIterator();
00405 }
00406 
00407 OA_ptr<DGraph::NodesIteratorInterface> DUGStandard::getDFSIterator(OA_ptr<DGraph::NodeInterface> n) 
00408 {
00409     
00410     
00411     return mDGraph->getDFSIterator(n);
00412 }
00413 
00414 OA_ptr<DGraph::NodesIteratorInterface> DUGStandard::getBFSIterator() 
00415 { 
00416     assert(0); 
00417     OA_ptr<DGraph::NodesIteratorInterface> retval; 
00418     return retval;
00419 }
00420 
00421 
00422 OA_ptr<DGraph::NodesIteratorInterface>
00423 DUGStandard::getReversePostDFSIterator( DGraph::DGraphEdgeDirection pOrient)
00424 {
00425     return mDGraph->getReversePostDFSIterator(pOrient);
00426 }
00427 
00428 OA_ptr<DGraph::NodesIteratorInterface>
00429 DUGStandard::getReversePostDFSIterator(OA_ptr<DGraph::NodeInterface> root, 
00430                                        DGraph::DGraphEdgeDirection pOrient)
00431 {
00432     assert(0);
00433 }
00434 
00440 OA_ptr<DGraph::NodesIteratorInterface> 
00441 DUGStandard::getPostDFSIterator(DGraph::DGraphEdgeDirection pOrient)
00442 {
00443     assert(0);
00444 }
00445 
00446 OA_ptr<DGraph::NodesIteratorInterface>
00447 DUGStandard::getPostDFSIterator(OA_ptr<DGraph::NodeInterface> root, 
00448                                 DGraph::DGraphEdgeDirection pOrient)
00449 {
00450     assert(0);
00451 }
00452 
00453 
00454 OA_ptr<NodesIteratorInterface> DUGStandard::getDUGNodesIterator() const
00455 {
00456     OA_ptr<NodesIterator> retval;
00457     retval = new NodesIterator(getNodesIterator());
00458     return retval;
00459 
00460 }
00461 
00462 
00463 OA_ptr<NodesIteratorInterface>
00464 DUGStandard::getDUGEntryNodesIterator( ) const
00465 {
00466     OA_ptr<NodesIterator> retval;
00467     retval = new NodesIterator(getEntryNodesIterator());
00468     return retval;
00469 
00470 
00471 }
00472 
00473 OA_ptr<NodesIteratorInterface>
00474 DUGStandard::getDUGExitNodesIterator( ) const
00475 {
00476     OA_ptr<NodesIterator> retval;
00477     retval = new NodesIterator(getExitNodesIterator());
00478     return retval;
00479 
00480 
00481 }
00482 
00483 OA_ptr<EdgesIteratorInterface> DUGStandard::getDUGEdgesIterator() const
00484 {
00485     OA_ptr<EdgesIterator> retval;
00486     retval = new EdgesIterator(getEdgesIterator());
00487     return retval;
00488 
00489 
00490 }
00491 
00492 
00493 OA_ptr<NodesIteratorInterface>
00494 DUGStandard::getDUGReversePostDFSIterator( DGraph::DGraphEdgeDirection pOrient)
00495 {
00496     OA_ptr<NodesIterator> retval;
00497     retval = new NodesIterator(getReversePostDFSIterator(pOrient));
00498     return retval;
00499 }
00500 
00501 OA_ptr<NodesIteratorInterface>
00502 DUGStandard::getDUGDFSIterator(OA_ptr<NodeInterface> n)
00503 {
00504     OA_ptr<NodesIterator> retval;
00505     retval = new NodesIterator(getDFSIterator(n));
00506     return retval;
00507 
00508 
00509 }
00510 
00511 void
00512 DUGStandard::dump (ostream& os, OA_ptr<IRHandlesIRInterface> ir)
00513 {
00514     os << "===== DUGStandard: =====\n"
00515        << endl;
00516   
00517     // print the contents of all the nodes
00518     OA_ptr<NodesIteratorInterface> nodeIter = getDUGNodesIterator();
00519     for ( ; nodeIter->isValid(); ++(*nodeIter)) {
00520         OA_ptr<NodeInterface> node = nodeIter->currentDUGNode();
00521         node->longdump(os, ir);
00522         os << endl;
00523     }
00524   
00525     os << "====================" << endl;
00526 
00527 }
00528 
00529 void
00530 DUGStandard::dumpdot(ostream& os, OA_ptr<DUGIRInterface> ir)
00531 {
00532 
00533     os << "digraph OA_DUG {" << endl;
00534     os << "node [shape=rectangle];" << endl;
00535 
00536     // then output nodes and edges by procedure
00537     OA_ptr<EdgesIteratorInterface> iter;
00538     iter = getDUGEdgesIterator();
00539     for (; iter->isValid(); (*iter)++ ) {
00540         OA_ptr<EdgeInterface> edge = iter->currentDUGEdge();
00541         edge->dumpdot(os, ir);
00542     }
00543 
00544     os << "}" << endl;
00545     os.flush();
00546 }
00547 
00548 
00549 OA_ptr<Node> 
00550 DUGStandard::getNode(SymHandle sym, ProcHandle proc){
00551     
00552 #ifdef DEBUG_DUAA
00553     std::cout << "getNode: " << mIR->toString(sym) << "("
00554               << sym.hval() << ")@" << mIR->toString(proc) << "("
00555               << proc.hval() << ") --- ";
00556 #endif
00557     assert(sym);
00558     OA_ptr<Node> retval = mSymToNode[sym];
00559     if (!retval.ptrEqual(0)) {
00560 #ifdef DEBUG_DUAA
00561         std::cout << "found itself" << std::endl;
00562 #endif
00563         return retval;
00564     }
00565     OA_ptr<Location> loc = mIR->getLocation(proc, sym);
00566     assert (!loc.ptrEqual(0));
00567     OA_ptr<NamedLoc> nloc = loc.convert<NamedLoc>();
00568     OA_ptr<SymHandleIterator> symIter = nloc->getFullOverlapIter();
00569     for ( ; symIter->isValid(); (*symIter)++) {
00570         retval = mSymToNode[symIter->current()];
00571         if (!retval.ptrEqual(0)) {
00572 #ifdef DEBUG_DUAA
00573             std::cout << "found FullOverlap" << std::endl;
00574 #endif
00575             return retval;
00576         }
00577     }
00578 #if 0
00579     symIter = nloc->getPartOverlapIter();
00580     for ( ; symIter->isValid(); (*symIter)++) {
00581         retval = mSymToNode[symIter->current()];
00582         if (!retval.ptrEqual(0)) {
00583 #ifdef DEBUG_DUAA
00584             std::cout << "found PartOverlap" << std::endl;
00585 #endif
00586             return retval;
00587         }
00588     }
00589 #endif
00590     assert (retval.ptrEqual(0));
00591     OA_ptr<DUGStandard> temp; temp = this;
00592     retval = new Node(temp, proc, sym);
00593     assert(!retval.ptrEqual(0));
00594     mSymToNode[sym] = retval;
00595     addNode(retval);
00596 #ifdef DEBUG_DUAA
00597     std::cout << "added" << std::endl;
00598 #endif
00599 
00600     return retval;
00601 }
00602 
00603 // true if a node exists for 'loc'
00604 bool
00605 DUGStandard::isNode(SymHandle sym, ProcHandle proc){
00606 #ifdef DEBUG_DUAA
00607     std::cout << "isNode: " << mIR->toString(sym) << "("
00608               << sym.hval() << ")@" << mIR->toString(proc) << "("
00609               << proc.hval() << ") --- ";
00610 #endif
00611     assert(sym);
00612     OA_ptr<Node> retval = mSymToNode[sym];
00613     if (!retval.ptrEqual(0)) {
00614 #ifdef DEBUG_DUAA
00615         std::cout << "found itself" << std::endl;
00616 #endif
00617         return true;
00618     }
00619     OA_ptr<Location> loc = mIR->getLocation(proc, sym);
00620     if (loc.ptrEqual(0)) {
00621 #ifdef DEBUG_DUAA
00622         std::cout << "NULL location" << std::endl;
00623 #endif
00624         return false;
00625     }
00626     OA_ptr<NamedLoc> nloc = loc.convert<NamedLoc>();
00627     OA_ptr<SymHandleIterator> symIter = nloc->getFullOverlapIter();
00628     for ( ; symIter->isValid(); (*symIter)++) {
00629         retval = mSymToNode[symIter->current()];
00630         if (!retval.ptrEqual(0)) {
00631 #ifdef DEBUG_DUAA
00632             std::cout << "found FullOverlap" << std::endl;
00633 #endif
00634             return true;
00635         }
00636     }
00637 #if 0
00638     symIter = nloc->getPartOverlapIter();
00639     for ( ; symIter->isValid(); (*symIter)++) {
00640         retval = mSymToNode[symIter->current()];
00641         if (!retval.ptrEqual(0)) {
00642 #ifdef DEBUG_DUAA
00643             std::cout << "found PartOverlap" << std::endl;
00644 #endif
00645             return true;
00646         }
00647     }
00648 #endif
00649 #ifdef DEBUG_DUAA
00650     std::cout << "not found" << std::endl;
00651 #endif
00652     return false;
00653 }
00654 
00655 
00656 
00657 void 
00658 DUGStandard::insertActiveSymSet(OA_ptr<Location> loc)
00659 {
00660     // Unknown
00661     if (loc->isaUnknown()) {
00662 
00663         mUnknownLocActive = true;
00664 
00665         // Named
00666     } else if (loc->isaNamed()) {
00667       
00668         OA_ptr<NamedLoc> nloc = loc.convert<NamedLoc>();
00669 #ifdef DEBUG_DUAA
00670         std::cout << "DUGStandard::insertActiveSymSet:(loc)"; 
00671         loc->dump(std::cout, mIR);
00672         std::cout << std::endl;
00673 #endif  
00674         insertActiveSymSet( nloc->getSymHandle() );
00675 
00676         OA_ptr<SymHandleIterator> symIter = nloc->getFullOverlapIter();
00677         for ( ; symIter->isValid(); (*symIter)++) {
00678 #ifdef DEBUG_DUAA
00679             std::cout << "\tFullOverlap: " << mIR->toString(symIter->current()); 
00680             std::cout << std::endl;
00681 #endif  
00682             insertActiveSymSet( symIter->current());
00683         }
00684         symIter = nloc->getPartOverlapIter();
00685         for ( ; symIter->isValid(); (*symIter)++) {
00686 #ifdef DEBUG_DUAA
00687             std::cout << "\tPartialOverlap: "; 
00688             std::cout << std::endl;
00689 #endif  
00690             insertActiveSymSet(symIter->current());
00691         }
00692  
00693         // Unnamed
00694     } else if (loc->isaUnnamed()) {
00695     
00696         //assert(0);
00697         // not handling this yet
00698 
00699         // Invisible
00700     } else if (loc->isaInvisible()) {
00701 
00702         OA_ptr<InvisibleLoc> invLoc 
00703             = loc.convert<InvisibleLoc>();
00704         OA_ptr<MemRefExpr> mre = invLoc->getMemRefExpr();
00705 
00706         // get symbol from memory reference expression if no derefs
00707         // FIXME: here need another visitor for MemRefExpr, for now assuming
00708         // only named ones
00709         if (mre->isaNamed()) {
00710             OA_ptr<NamedRef> namedRef 
00711                 = namedRef.convert<NamedRef>();
00712             insertActiveSymSet( namedRef->getSymHandle() );
00713         } else {
00714             assert(0);
00715         }
00716 
00717         // LocSubSet
00718     } else if (loc->isaSubSet()) {
00719 
00720         OA_ptr<Location> baseLoc = loc->getBaseLoc();
00721         // FIXME: now really want to call visitor on this guy but instead will just
00722         // call this function recursively
00723         insertActiveSymSet(baseLoc);
00724 
00725     } else {
00726 
00727         assert(0);
00728     }
00729 }
00730 
00731 
00732 void 
00733 Node::setActive(SymHandle sym)
00734 {
00735     assert(mProc);
00736     // will be storing activity results for stmt and memrefs in
00737     // ActiveStandard for current procedure
00738     if (mDUG->mActiveMap[mProc].ptrEqual(0)) {
00739         mDUG->mActiveMap[mProc] = new OA::Activity::ActiveStandard(mProc);
00740     }
00741 
00742     mDUG->insertActiveSymSet(sym);
00743 
00744     std::set<MemRefHandle> mrefSet;
00745     mrefSet = mDUG->getMemRefSet(sym);
00746     if (!mrefSet.empty()){
00747         std::set<MemRefHandle>::iterator i = mrefSet.begin();
00748         for(; i != mrefSet.end(); i++) {
00749             mDUG->insertActiveMemRefSet(*i, mProc);
00750         }
00751     }
00752 
00753 
00754     std::set<StmtHandle> stmtSet;
00755     stmtSet = mDUG->getStmtSet(sym);
00756     if (!stmtSet.empty()){
00757         std::set<StmtHandle>::iterator i = stmtSet.begin();
00758         for(; i != stmtSet.end(); i++)
00759             mDUG->insertActiveStmtSet(*i, mProc);
00760     }
00761 
00762 }
00763 
00764 
00765 void 
00766 Node::setActive()
00767 {
00768     setActive(mSym);
00769 
00770     OA_ptr<Location> loc = mDUG->mIR->getLocation(getProc(), mSym);
00771     OA_ptr<NamedLoc> nmloc = loc.convert<NamedLoc>();
00772     assert(!nmloc.ptrEqual(0));
00773     OA_ptr<SymHandleIterator> overlapIter = nmloc->getFullOverlapIter();
00774     for ( ; overlapIter->isValid(); (*overlapIter)++ ) {
00775         SymHandle sym = overlapIter->current();
00776         setActive(sym);
00777     }
00778 
00779     overlapIter = nmloc->getPartOverlapIter();
00780     for ( ; overlapIter->isValid(); (*overlapIter)++ ) {
00781         SymHandle sym = overlapIter->current();
00782         setActive(sym);
00783     }
00784 }
00785 
00786 #ifdef DEBUG_PATH
00787 std::list<Node* > debugPathVaried;
00788 std::list<Node* > debugPathUseful;
00789 std::string debug_sym("SUMBAL::XLM");
00790 std::string debug_sym2("P1::X");
00791 #endif
00792 void 
00793 Node::markVaried(std::list<CallHandle>& callStack,
00794                  OA_ptr<Activity::ActivityIRInterface> ir,
00795                  std::set<OA_ptr<EdgeInterface> >& visited,
00796                  std::set<std::pair<unsigned,unsigned> >& onPath,
00797                  ProcHandle proc,
00798                  unsigned prevId, 
00799                  OA_ptr<EdgeInterface> parenEdge,
00800                  bool activeWithVariedOnly)
00801 { 
00802 #ifdef DEBUG_DUAA
00803   static unsigned recDepth=0;
00804   recDepth++;
00805 #endif
00806     unsigned currId = getId();
00807 
00808     EdgeType parenEType = CFLOW_EDGE;
00809     CallHandle parenCall = CallHandle(0);
00810     if (!parenEdge.ptrEqual(0)) {
00811         parenEType = parenEdge->getType();
00812         parenCall = parenEdge->getCall();
00813     }
00814 
00815 #ifdef DEBUG_DUAA
00816     std::cout << "markVaried " << recDepth << " entering for " << mDUG->mIR->toString(getSym()).c_str() << std::endl; 
00817     std::cout << "-v->"; 
00818     if (parenEdge.ptrEqual(0)) {
00819         std::cout << "NULL edge";
00820     }else
00821         parenEdge->dumpdot(std::cout, mDUG->mIR);
00822     std::cout << std::endl;
00823 #endif  
00824     bool isVariedBefore = isVaried();
00825     setVaried();
00826 #ifdef DEBUG_PATH
00827     debugPathVaried.push_back(this);
00828     std::string symStr(mDUG->mIR->toString(getSym()));
00829     bool fromSymFound = false;
00830     if (symStr == debug_sym || symStr == debug_sym2 ){
00831         fromSymFound = true;
00832         std::cout << std::endl << recDepth << "=========================" << std::endl;
00833         std::list<Node* >::iterator nodeIter = debugPathVaried.begin();
00834         for(;nodeIter != debugPathVaried.end(); nodeIter++){
00835             std::cout << " -v-> ";
00836             (*nodeIter)->dump(std::cout, mDUG->mIR);
00837         }
00838         std::cout << std::endl << recDepth << "=========================" << std::endl;
00839 //      OA_ptr<EdgesIteratorInterface> succIterPtr;
00840 //      succIterPtr = getDUGOutgoingEdgesIterator();
00841 //      // iterate over the successors
00842 //      std::cout << recDepth << " before loop successor edges: " << std::endl;
00843 //      for (; succIterPtr->isValid(); ++(*succIterPtr)) {
00844 //        succIterPtr->currentDUGEdge()->dumpdot(std::cout, mDUG->mIR);
00845 //        std:: cout << std::endl;
00846 //      }
00847 //      std::cout << recDepth << " thats it for the before loop successor edges " << std::endl;
00848     }
00849 #endif
00850 #ifdef CONTEXT_SENSITIVITY
00851     if (!parenEdge.ptrEqual(0) && parenEdge->getType() == RETURN_EDGE)
00852         insertVariedContext(parenEdge->getCall());
00853 #endif 
00854 
00855     int nonParentSuccessors = 0;
00856     bool valueThroughGlobals = false;
00857     if (callStack.front() == CallHandle(1)) 
00858         valueThroughGlobals = true;
00859 
00860     // set up iterator for successor edges
00861     OA_ptr<EdgesIteratorInterface> succIterPtr;
00862     succIterPtr = getDUGOutgoingEdgesIterator();
00863     // iterate over the successors
00864     for (; succIterPtr->isValid(); ++(*succIterPtr)) {
00865 
00866         OA_ptr<EdgeInterface> succEdge = succIterPtr->currentDUGEdge();
00867         OA_ptr<NodeInterface> succNode = succEdge->getDUGSink();
00868 #ifdef DEBUG_DUAA
00869         if (symStr == debug_sym) { 
00870           std::cout << recDepth << " looking at successor edge ";
00871           succEdge->dumpdot(std::cout, mDUG->mIR);
00872           std:: cout << std::endl;
00873         }
00874 #endif
00875         OA_ptr<Node> sn = succNode.convert<Node>();
00876         OA_ptr<Edge> se = succEdge.convert<Edge>();
00877 
00878         SymHandle s = sn->getSym();
00879 
00880         unsigned succId = succNode->getId();
00881         EdgeType etype = succEdge->getType();
00882 
00883 #ifdef DEBUG_PATH
00884         std::string symStr2(mDUG->mIR->toString(s));
00885         bool toSymFound = (symStr2 == debug_sym2);
00886 #endif 
00887         std::pair<unsigned, unsigned> pathNode;
00888         switch(etype) {
00889             case CALL_EDGE: 
00890                 pathNode = std::pair<unsigned,unsigned>
00891                     (succEdge->getCall().hval(),succId); break;
00892             case PARAM_EDGE:
00893                 if (callStack.empty())
00894                     pathNode = std::pair<unsigned,unsigned>(1,succId); 
00895                 else
00896                     pathNode = std::pair<unsigned,unsigned>
00897                         (callStack.front().hval(),succId); break;
00898             case RETURN_EDGE:
00899             case CFLOW_EDGE:
00900                 pathNode = std::pair<unsigned,unsigned>(1,succId); break;
00901             default: assert(0);
00902         }
00903 
00904         if (etype != RETURN_EDGE || succId != prevId){
00905           nonParentSuccessors++;
00906 //        std::string psymStr(mDUG->mIR->toString(getSym()));
00907 //        if (psymStr == debug_sym ){
00908 //          std::cout << recDepth << "*** nonParentSuccessors is now " << nonParentSuccessors 
00909 //                    << " for eType:  " << etype << " != " <<  RETURN_EDGE
00910 //                    << " succId " << succId
00911 //                    << " prevId " << prevId
00912 //                    << std::endl; 
00913 //        }
00914         }
00915 
00916 #ifdef DEBUG_PATH
00917         if (fromSymFound && toSymFound){
00918             if (visited.find(succEdge) != visited.end())
00919                 std::cout << " visited" << std::endl;
00920             if (onPath.find(pathNode)  != onPath.end())
00921                 std::cout << " onPath" << std::endl;
00922         }
00923 #endif 
00924 #ifdef CONTEXT_SENSITIVITY
00925         // formal param nodes involved in a loop are set for 'self dependence'.
00926         if (!succEdge.ptrEqual(0) && etype == CFLOW_EDGE &&
00927             sn->isFormalParamNode() && onPath.find(pathNode)  != onPath.end())
00928             sn->setSelfDependent();
00929         if (// onPath.find(pathNode)  != onPath.end()   &&
00930             succId != prevId && etype == RETURN_EDGE &&
00931             (callStack.front() == succEdge->getCall() || valueThroughGlobals)){
00932             sn->insertVariedContext(succEdge->getCall());
00933         }
00934 #endif 
00935         if (visited.find(succEdge) != visited.end() ||
00936 //          onPath.find(pathNode)  != onPath.end()  ||
00937 //          succId == prevId                        ||
00938             se->isExplored4Varied(callStack.front())) 
00939         {
00940             continue;
00941         }
00942 
00943         onPath.insert(pathNode);
00944 
00945         switch(etype) {
00946             case (CALL_EDGE):
00947             {
00948                 // to deal with value passing through global variables between procedures
00949                 ProcHandle callerProc = succEdge->getSourceProc();
00950                 if (proc != callerProc){ 
00951 #ifdef DEBUG_DUAA
00952                     std::cout << "valthruglobals: begin" << std::endl;
00953 #endif  
00954                     callStack.push_front(CallHandle(1));
00955                 }
00956           
00957                 callStack.push_front(succEdge->getCall());
00958                 visited.insert(succEdge);
00959         
00960                 succNode->markVaried(callStack, ir, visited, onPath, 
00961                                      succEdge->getSinkProc(), currId, 
00962                                      succEdge,
00963                                      activeWithVariedOnly);
00964                 callStack.pop_front();
00965                 if (proc != callerProc){ 
00966 #ifdef DEBUG_DUAA
00967                     std::cout << "valthruglobals: end" << std::endl;
00968 #endif  
00969                     callStack.pop_front();
00970                 }
00971                 break;
00972             }
00973             case (RETURN_EDGE):
00974 #ifdef DEBUG_PATH
00975                 if (fromSymFound && toSymFound){
00976                     if (callStack.front() != succEdge->getCall() &&
00977                         !valueThroughGlobals)
00978                         std::cout << " nonmatching context" << std::endl;
00979                 }
00980 #endif 
00981                 if (callStack.front() == succEdge->getCall() || valueThroughGlobals){
00982                     if (!valueThroughGlobals) callStack.pop_front();
00983                     visited.insert(succEdge);
00984 
00985                     succNode->markVaried(callStack, ir, visited, onPath, 
00986                                          succEdge->getProc(), currId, 
00987                                          succEdge,
00988                                          activeWithVariedOnly);
00989                     if (!valueThroughGlobals) callStack.push_front(succEdge->getCall());
00990                 }
00991 #ifdef DEBUG_DUAA
00992                 else{
00993                     std::cout << "markVaried: " << (callStack.front() == succEdge->getCall())
00994                               << (unsigned)callStack.front().hval() << "<->"
00995                               << (unsigned)succEdge->getCall().hval() << std::endl;
00996                 }
00997 #endif  
00998                 break;
00999             default: // for both CFLOW_EDGE and PARAM_EDGE
01000                 if (succEdge->getType() == PARAM_EDGE) 
01001                     se->setExplored4Varied(callStack.front());
01002                 else
01003                     visited.insert(succEdge);
01004                 // to deal with value passing through global variables between procedures
01005                 ProcHandle succProc = succEdge->getProc();
01006                 if (proc != succProc) {
01007                     callStack.push_front(CallHandle(1));
01008           
01009                     succNode->markVaried(callStack, ir, visited, onPath, 
01010                                          succProc, currId, succEdge,
01011                                          activeWithVariedOnly);
01012                     callStack.pop_front();
01013                 }
01014                 else{
01015                     succNode->markVaried(callStack, ir, visited, onPath, 
01016                                          proc, currId, succEdge,
01017                                          activeWithVariedOnly);
01018                 }
01019           
01020                 break;
01021         }
01022 
01023         onPath.erase(pathNode);
01024     }
01025 
01026 #ifdef CONTEXT_SENSITIVITY
01027     if (isSelfDependent() && parenEType == CALL_EDGE){
01028         OA_ptr<NodeInterface> parenNode = parenEdge->getDUGSource();
01029         OA_ptr<Node> pn = parenNode.convert<Node>();
01030         pn->insertVariedContext(parenEdge->getCall());
01031         // if this node is a formal parameter and self dependent,
01032         // all the actual parameter nodes are self dependent.
01033         pn->setSelfDependent();
01034 #ifdef DEBUG_PATH
01035         std::string psymStr(mDUG->mIR->toString(pn->getSym()));
01036         if (psymStr == debug_sym ){
01037             std::cout << "*** thermodynamics_::FVERS became self-dependent " 
01038                       << "at " << symStr << "***" << std::endl;
01039         }
01040 #endif
01041     }
01042 #endif 
01043 #ifdef DEBUG_DUAA
01044     std::string psymStr(mDUG->mIR->toString(getSym()));
01045     if (psymStr == debug_sym ){
01046       std::cout << recDepth << "testing for " 
01047                 << symStr 
01048                 << "nonParentSuccessors " << nonParentSuccessors
01049                 << "isVariedBefore " << isVariedBefore
01050                 << "isSelfDependent() " << isSelfDependent()
01051                 << "parenEType " << parenEType
01052                 << "mDUG->isDependent(getProc(), getSym()) " << mDUG->isDependent(getProc(), getSym())
01053                 << std::endl;
01054     }
01055 #endif 
01056     // Actual or formal parameters without any outgoing edges shouldn't be
01057     // activated.
01058     if (nonParentSuccessors == 0
01059         && !isVariedBefore && !isSelfDependent() && 
01060         ( parenEType == CALL_EDGE || parenEType == RETURN_EDGE) && 
01061         !mDUG->isDependent(getProc(), getSym()) ) {
01062       // see if we have any variedNonCallPredecessors:
01063       bool variedNonCallPredecessor=false;
01064       OA_ptr<EdgesIteratorInterface> predIterPtr;
01065       predIterPtr = getDUGIncomingEdgesIterator();
01066       // iterate over the predecessors 
01067       for (; predIterPtr->isValid() 
01068              ; ++(*predIterPtr)) {
01069         OA_ptr<EdgeInterface> predEdge = predIterPtr->currentDUGEdge();
01070         if (predEdge->getType()!=CALL_EDGE) { 
01071           OA_ptr<NodeInterface> predNode = predEdge->getDUGSource();
01072           OA_ptr<Node> pn = predNode.convert<Node>();
01073           if (pn->isVaried()) { 
01074             variedNonCallPredecessor=true;
01075             break;
01076           }
01077         }
01078       }
01079       if (!variedNonCallPredecessor){ 
01080         unsetVaried();
01081 #ifdef DEBUG_PATH
01082         std::cout << " unsetVaried:"; dump(std::cout, mDUG->mIR);
01083 #endif
01084 #ifdef DEBUG_DUAA
01085         std::cout << "unsetVaried("; dumpdot(std::cout, mDUG->mIR); 
01086         std::cout << ")" << std::endl;
01087 #endif  
01088       }
01089     }
01090     if (activeWithVariedOnly)
01091       setActive();
01092 #ifdef DEBUG_DUAA
01093     std::cout << "<-" << std::endl;
01094     std::cout << "markVaried " << recDepth << " leaving for " << mDUG->mIR->toString(getSym()).c_str() << std::endl; 
01095     --recDepth;  
01096 #endif
01097 #ifdef DEBUG_PATH
01098     debugPathVaried.pop_back();
01099 #endif
01100 }
01101 
01102 void
01103 Node::markUseful(std::list<CallHandle>& callStack,
01104                  OA_ptr<Activity::ActivityIRInterface> ir,
01105                  std::set<OA_ptr<EdgeInterface> >& visited,
01106                  std::set<std::pair<unsigned,unsigned> >& onPath,
01107                  ProcHandle proc,
01108                  unsigned prevId, 
01109                  OA_ptr<EdgeInterface> parenEdge)
01110 {
01111     if (!isVaried()) {
01112 #ifdef DEBUG_DUAA
01113         std::cout << "notVaried: "; 
01114         dumpdot(std::cout, mDUG->mIR);
01115         if (!parenEdge.ptrEqual(0)) {
01116             std::cout << "(call:" << parenEdge->getCall().hval() << ")"; 
01117         }
01118         std::cout << std::endl; 
01119 #endif  
01120         return;
01121     }
01122 #ifdef DEBUG_DUAA
01123     std::cout << " calling markUseful for : " << mDUG->mIR->toString(getSym()).c_str() << " following edge :";
01124 #endif  
01125     unsigned currId = getId();
01126 
01127     EdgeType parenEType = CFLOW_EDGE;
01128     CallHandle parenCall = CallHandle(0);
01129     if (!parenEdge.ptrEqual(0)) {
01130         parenEType = parenEdge->getType();
01131         parenCall = parenEdge->getCall();
01132     }
01133 
01134 #ifdef DEBUG_DUAA
01135     std::cout << "-u->"; 
01136     if (parenEdge.ptrEqual(0)) {
01137         std::cout << "NULL edge";
01138     }else
01139         parenEdge->dumpdot(std::cout, mDUG->mIR);
01140     std::cout << "(call:" << parenCall.hval() << ")" << std::endl; 
01141     std::string symStr(mDUG->mIR->toString(getSym()));
01142     if (symStr == debug_sym  || symStr == debug_sym2){
01143       std::cout << "useful before: " << isUseful() << " for "; dump(std::cout, mDUG->mIR);
01144     }
01145 #endif  
01146     bool isUsefulBefore = isUseful();
01147     setUseful();
01148 #ifdef DEBUG_PATH
01149     std::cout << "setUseful:"; dump(std::cout, mDUG->mIR); 
01150     debugPathUseful.push_back(this);
01151     if (symStr == debug_sym || symStr == debug_sym2 ){
01152         std::cout << std::endl << "===== U PATH BEGIN =========" << std::endl;
01153         std::list<Node* >::iterator nodeIter = debugPathUseful.begin();
01154         for(;nodeIter != debugPathUseful.end(); nodeIter++){
01155             (*nodeIter)->dump(std::cout, mDUG->mIR);
01156         }
01157         std::cout << std::endl << "===== U PATH END ===========" << std::endl;
01158     }
01159 #endif
01160     int nonChildAncestors = 0;
01161     bool nonCallPredEdge=false; 
01162     bool isIndependent = mDUG->isIndependent(getProc(), getSym()) && 
01163         !mDUG->isDependent(getProc(), getSym());
01164 
01165     bool valueThroughGlobals = false;
01166     if (callStack.front() == CallHandle(1)) valueThroughGlobals = true;
01167 
01168     // set up iterator for predecessor edges
01169     OA_ptr<EdgesIteratorInterface> predIterPtr;
01170     predIterPtr = getDUGIncomingEdgesIterator();
01171     // iterate over the predecessors 
01172     for (; predIterPtr->isValid() 
01173              ; ++(*predIterPtr)) {
01174       
01175         OA_ptr<EdgeInterface> predEdge = predIterPtr->currentDUGEdge();
01176 #ifdef DEBUG_DUAA
01177         std::cout << "now looking at edge: ";  predEdge->dumpdot(std::cout, mDUG->mIR);
01178 #endif  
01179         OA_ptr<NodeInterface> predNode = predEdge->getDUGSource();
01180         unsigned predId = predNode->getId();
01181         EdgeType etype = predEdge->getType();
01182 
01183         OA_ptr<Edge> pe = predEdge.convert<Edge>();
01184 
01185         std::pair<unsigned, unsigned> pathNode;
01186         switch(etype) {
01187             case RETURN_EDGE:
01188                 pathNode = std::pair<unsigned,unsigned>
01189                     (predEdge->getCall().hval(),predId); break;
01190             case PARAM_EDGE:
01191                 if (callStack.empty())
01192                     pathNode = std::pair<unsigned,unsigned>(1,predId); 
01193                 else
01194                     pathNode = std::pair<unsigned,unsigned>
01195                         (callStack.front().hval(),predId); break;
01196             case CALL_EDGE: 
01197             case CFLOW_EDGE:
01198                 pathNode = std::pair<unsigned,unsigned>(1,predId); break;
01199             default: assert(0);
01200         }
01201         if (etype!=CALL_EDGE) nonCallPredEdge=true;
01202         if (predId != prevId || parenCall != predEdge->getCall()) nonChildAncestors++;
01203         if (visited.find(predEdge) != visited.end() ||
01204             onPath.find(pathNode)  != onPath.end()  ||
01205             pe->isExplored4Useful(callStack.front())) {
01206 #ifdef DEBUG_DUAA
01207           std::cout << "CONTINUE(" << currId << " -> " << predId << "): was visited:" << (visited.find(predEdge) != visited.end()) 
01208                     << " (" << pathNode.first << ","<<  pathNode.second << ") is on path:" << (onPath.find(pathNode) != onPath.end()) << " edge: ";  predEdge->dumpdot(std::cout, mDUG->mIR);
01209 #endif  
01210             continue;
01211         }
01212         onPath.insert(pathNode);
01213 
01214         switch(etype) {
01215             case (CALL_EDGE):
01216                 if (callStack.front() == predEdge->getCall() || valueThroughGlobals ){
01217                     if (!valueThroughGlobals) callStack.pop_front();
01218                     visited.insert(predEdge);
01219                     predNode->markUseful(callStack, ir, visited, onPath, 
01220                                          predEdge->getProc(), currId, predEdge);
01221                     if (!valueThroughGlobals) callStack.push_front(predEdge->getCall());
01222                 } 
01223 #ifdef DEBUG_DUAA
01224                 else {
01225                     std::cout << "stack not match(" << currId << "+>" << predId << "): stack(" 
01226                               << callStack.front().hval() << ") vs. edgeCall("
01227                               << predEdge->getCall().hval() << ")" << std::endl;
01228                 }
01229 #endif  
01230                 break;
01231             case (RETURN_EDGE):
01232             {
01233 #ifdef CONTEXT_SENSITIVITY
01234                 if (!isVariedContext(predEdge->getCall())) break;
01235 #endif  
01236                 ProcHandle callerProc = predEdge->getSinkProc();
01237                 if (proc != callerProc){ 
01238                     callStack.push_front(CallHandle(1));
01239 #ifdef DEBUG_DUAA
01240                     std::cout << "valthruglobals: begin" << std::endl;
01241 #endif  
01242                 }
01243 
01244                 callStack.push_front(predEdge->getCall());
01245                 visited.insert(predEdge);
01246                 predNode->markUseful(callStack, ir, visited, onPath, 
01247                                      predEdge->getSourceProc(), 
01248                                      currId, predEdge);
01249                 callStack.pop_front();
01250                 if (proc != callerProc){ 
01251                     callStack.pop_front();
01252 #ifdef DEBUG_DUAA
01253                     std::cout << "valthruglobals: end" << std::endl;
01254 #endif  
01255                 }
01256                 break;
01257             }
01258             default: // for both CFLOW_EDGE and PARAM_EDGE
01259                 if (predEdge->getType() == PARAM_EDGE) 
01260                     pe->setExplored4Useful(callStack.front());
01261                 else
01262                     visited.insert(predEdge);
01263                 ProcHandle predProc = predEdge->getProc();
01264                 if (proc != predProc) {
01265                     callStack.push_front(CallHandle(1));
01266 #ifdef DEBUG_DUAA
01267                     std::cout << "valthruglobals: begin" << std::endl;
01268 #endif  
01269                     predNode->markUseful(callStack, ir, visited, onPath, 
01270                                          predProc, currId, predEdge);
01271                     callStack.pop_front();
01272 #ifdef DEBUG_DUAA
01273                     std::cout << "valthruglobals: end" << std::endl;
01274 #endif  
01275                 }
01276                 else
01277                 {
01278                     predNode->markUseful(callStack, ir, visited, onPath, 
01279                                          proc, currId, predEdge);
01280                 }
01281                 break;
01282         }
01283 
01284         onPath.erase(pathNode);
01285     }
01286 
01287     // Formal parameters without any outgoing edges shouldn't be
01288     // activated.
01289     if ( nonChildAncestors == 0  && !isUsefulBefore && !isSelfDependent() && 
01290         ( parenEType == RETURN_EDGE || parenEType == CALL_EDGE) &&
01291         !mDUG->isIndependent(getProc(), getSym()) ){
01292       // see if we have any usefulNonReturnSuccessors:
01293       bool usefulNonReturnSuccessors=false;
01294       OA_ptr<EdgesIteratorInterface> succIterPtr;
01295       succIterPtr = getDUGOutgoingEdgesIterator();
01296       // iterate over the successors 
01297       for (; succIterPtr->isValid() 
01298              ; ++(*succIterPtr)) {
01299         OA_ptr<EdgeInterface> succEdge = succIterPtr->currentDUGEdge();
01300         if (succEdge->getType()!=RETURN_EDGE) { 
01301           OA_ptr<NodeInterface> succNode = succEdge->getDUGSource();
01302           OA_ptr<Node> pn = succNode.convert<Node>();
01303           if (pn->isVaried()) { 
01304             usefulNonReturnSuccessors=true;
01305             break;
01306           }
01307         }
01308       }
01309       if (!usefulNonReturnSuccessors){ 
01310 #ifdef DEBUG_DUAA
01311         std::cout << " unsetUseful:"; dump(std::cout, mDUG->mIR);
01312 #endif  
01313         unsetUseful();
01314       }
01315     }else{
01316       if (!nonCallPredEdge && !isSelfDependent()) {
01317         OA_ptr<EdgesIteratorInterface> succIterPtr;
01318         succIterPtr = getDUGOutgoingEdgesIterator();
01319         // iterate over the successors and see if there are any non return edges
01320         for (; succIterPtr->isValid(); ++(*succIterPtr)) {
01321           if (succIterPtr->currentDUGEdge()->getType()!=RETURN_EDGE) { 
01322 #ifdef DEBUG_DUAA
01323             std::cout << "setActive(" << currId << ")" << std::endl;
01324 #endif 
01325             setActive();
01326             break; 
01327           }
01328         } 
01329 #ifdef DEBUG_DUAA
01330         if (!succIterPtr->isValid()) { 
01331           std::cout << "keeping passive non-self dependent dummy parameter: "; dump(std::cout, mDUG->mIR);
01332         }
01333 #endif 
01334       }
01335       else { 
01336 #ifdef DEBUG_DUAA
01337         std::cout << "setActive(" << currId << ")" << std::endl;
01338 #endif 
01339        setActive();
01340       }
01341     }
01342 #ifdef DEBUG_DUAA
01343     std::cout << "<-" << std::endl;
01344 #endif  
01345 #ifdef DEBUG_PATH
01346     debugPathUseful.pop_back();
01347 #endif
01348 #ifdef DEBUG_DUAA
01349     std::cout << " returning from markUseful for : "; dump(std::cout, mDUG->mIR);
01350 #endif  
01351 
01352 }
01353 
01355 bool DUGStandard::isActive(SymHandle sym)
01356 {
01357     // an unknown location is active, therefore all symbols are active
01358     if (mUnknownLocActive) {
01359         return true;
01360     } else if (mActiveSymSet->find(sym) != mActiveSymSet->end()) {
01361         return true;
01362     } else {
01363         return false;
01364     }  
01365 }
01366 
01367 
01368 
01370 bool DUGStandard::isActive(MemRefHandle memref)
01371 {
01372     if (mActiveMemRefSet->find(memref) != mActiveMemRefSet->end()) {
01373         return true;
01374     } else {
01375         return false;
01376     }
01377 }
01378 
01379 
01380 
01381 // 'true' if there is a path from 'useNode' to 'this'
01382 bool
01383 Node::isPathFrom(OA_ptr<NodeInterface> useNode,
01384                  std::set<OA_ptr<NodeInterface> >& visited)
01385 { 
01386     if (useNode.ptrEqual(this)) return true;
01387 
01388     // traverse backward from this nodes
01389     OA_ptr<EdgesIteratorInterface> predIterPtr
01390         = getDUGIncomingEdgesIterator();
01391     for (; predIterPtr->isValid(); ++(*predIterPtr)) {
01392         OA_ptr<EdgeInterface> predEdge = predIterPtr->currentDUGEdge();
01393         OA_ptr<NodeInterface> predNode = predEdge->getDUGSource();
01394   
01395         if (visited.find(predNode) != visited.end()) continue;
01396         visited.insert(predNode);
01397         if (predNode->isPathFrom(useNode, visited)) return true;
01398     }
01399 
01400     return false;
01401 }
01402 
01403 
01404 
01405 // returns a set of outgoing nodes of this proc
01406 void
01407 Node::findOutgoingNodes(ProcHandle proc, 
01408                         std::set<SymHandle>& OutGoingNodeSet,
01409                         std::set<SymHandle>& visited)
01410 { 
01411     SymHandle sym = getSym();
01412     if (visited.find(sym) != visited.end()) return;
01413     visited.insert(sym);
01414 
01415     bool edgesToOtherProcs = false;
01416     // traverse foreward from this nodes
01417     OA_ptr<EdgesIteratorInterface> succIterPtr
01418         = getDUGOutgoingEdgesIterator();
01419     for (; succIterPtr->isValid(); ++(*succIterPtr)) {
01420         OA_ptr<EdgeInterface> succEdge = succIterPtr->currentDUGEdge();
01421         OA_ptr<NodeInterface> succNode = succEdge->getDUGSink();
01422 
01423         if (succEdge->getType() != CFLOW_EDGE) continue;
01424         if (succEdge->getProc() != proc) {
01425             if (!edgesToOtherProcs) {
01426                 OutGoingNodeSet.insert(sym);
01427                 edgesToOtherProcs = true;
01428             }
01429             continue;
01430         }
01431 
01432         succNode->findOutgoingNodes(proc, OutGoingNodeSet, visited);
01433     }
01434 }
01435 
01436 
01437 
01438 // true if this has an outgoing edge to other procedures
01439 bool
01440 Node::hasEdgesToOtherProc(ProcHandle proc, std::set<SymHandle>& visited)
01441 { 
01442     SymHandle sym = getSym();
01443     if (visited.find(sym) != visited.end()) return false;
01444     visited.insert(sym);
01445 
01446     // traverse foreward from this nodes
01447     OA_ptr<EdgesIteratorInterface> succIterPtr = getDUGOutgoingEdgesIterator();
01448     for (; succIterPtr->isValid(); ++(*succIterPtr)) {
01449         OA_ptr<EdgeInterface> succEdge = succIterPtr->currentDUGEdge();
01450         OA_ptr<NodeInterface> succNode = succEdge->getDUGSink();
01451         
01452         EdgeType etype = succEdge->getType();
01453         if (etype != CFLOW_EDGE && etype != CALL_EDGE) continue;
01454         if (succEdge->getProc() != proc) return true;
01455         if (etype == CFLOW_EDGE && succNode->hasEdgesToOtherProc(proc, visited)) 
01456             return true;
01457     }
01458     return false;
01459 }
01460 
01461 
01462 
01463 // true if this has an incoming edge to other procedures
01464 bool
01465 Node::hasEdgesFromOtherProc(ProcHandle proc, std::set<SymHandle>& visited)
01466 { 
01467     SymHandle sym = getSym();
01468     if (visited.find(sym) != visited.end()) return false;
01469     visited.insert(sym);
01470 
01471     // traverse backward from this nodes
01472     OA_ptr<EdgesIteratorInterface> predIterPtr = getDUGIncomingEdgesIterator();
01473     for (; predIterPtr->isValid(); ++(*predIterPtr)) {
01474         OA_ptr<EdgeInterface> predEdge = predIterPtr->currentDUGEdge();
01475         OA_ptr<NodeInterface> predNode = predEdge->getDUGSource();
01476   
01477         EdgeType etype = predEdge->getType();
01478         if (etype != CFLOW_EDGE) continue;
01479         if (predEdge->getProc() != proc) return true;
01480         if (predNode->hasEdgesFromOtherProc(proc, visited)) 
01481             return true;
01482     }
01483     return false;
01484 }
01485 
01486 
01487 
01488   } // end namespace DUGStandard
01489 } // end namespace OA