ManagerParamBindings.cpp

Go to the documentation of this file.
00001 
00015 #include "ManagerParamBindings.hpp"
00016 #include <Utils/Util.hpp>
00017 
00018 
00019 namespace OA {
00020   namespace DataFlow {
00021 
00022 static bool debug = false;
00023 
00024 ManagerParamBindings::ManagerParamBindings(
00025     OA_ptr<DataFlow::ParamBindingsIRInterface> _ir) : mIR(_ir)
00026 {
00027     OA_DEBUG_CTRL_MACRO("DEBUG_ManagerParamBindings:ALL", debug);
00028 }
00029 
00032 OA_ptr<ParamBindings> 
00033 ManagerParamBindings::performAnalysis( OA_ptr<CallGraph::CallGraphInterface> callGraph )
00034 {
00035   // empty set of parameter bindings that we are going to fill
00036   OA_ptr<ParamBindings> retval;
00037   retval = new ParamBindings;
00038 
00039   if (debug) {
00040       std::cout << "In ManagerParamBindings::performAnalysis" << std::endl;
00041   }
00042 
00043   // for each node in the call graph get the set of formal 
00044   // parameters (that are actually refefenced)
00045 
00046   
00052   OA_ptr<CallGraph::NodesIteratorInterface> nodeIter = callGraph->getCallGraphNodesIterator();
00053   for (;nodeIter->isValid();++(*nodeIter)) {
00054     OA_ptr<CallGraph::NodeInterface> aCGNode=nodeIter->currentCallGraphNode();
00055     // don't bother with things we don't have a definition for 
00056     if (!aCGNode->isDefined()) 
00057       continue;
00058     ProcHandle aProcHandle=aCGNode->getProc();
00059 
00060     // iterate over all statements in the procedure
00061     OA_ptr<IRStmtIterator> stmtIterPtr = mIR->getStmtIterator(aProcHandle);
00062     // Iterate over the statements of this block adding procedure references
00063     for ( ; stmtIterPtr->isValid(); ++(*stmtIterPtr)) {
00064         StmtHandle stmt = stmtIterPtr->current();
00065 
00066         // get all of the memory references for the statement
00067         OA_ptr<MemRefHandleIterator> mrIterPtr = mIR->getAllMemRefs(stmt);
00068         for (; mrIterPtr->isValid(); (*mrIterPtr)++ ) {
00069             MemRefHandle memref = mrIterPtr->current();
00070 
00071             // get the memory reference expressions for this handle
00072             OA_ptr<MemRefExprIterator> mreIterPtr 
00073                 = mIR->getMemRefExprIterator(memref);
00074       
00075             // for each mem-ref-expr associated with this memref
00076             for (; mreIterPtr->isValid(); (*mreIterPtr)++) {
00077                 OA_ptr<OA::MemRefExpr> mre = mreIterPtr->current();
00078                 if (debug) {
00079                     std::cout << "\tmre = ";
00080                     mre->output(*mIR);
00081                     std::cout << std::endl;
00082                 }
00083 
00084                 // check all symbol handles within MRE to see if formal
00085                 FormalFinderVisitor visitor(mIR, aProcHandle, retval);
00086                 mre->acceptVisitor(visitor);
00087             }
00088         }
00089     }
00090   }
00091 
00092   OA_ptr<std::list<ExprHandle> > exprList;
00093 
00094   // for each edge in the call graph get parameter binding
00095   OA_ptr<CallGraph::EdgesIteratorInterface> 
00096       edgeIter = callGraph->getCallGraphEdgesIterator();
00097   for ( ; edgeIter->isValid(); ++(*edgeIter) ) {
00098     OA_ptr<CallGraph::EdgeInterface> edge = edgeIter->currentCallGraphEdge();
00099     // only do all this if the callee is defined
00107     OA_ptr<CallGraph::NodeInterface> callee = edge->getCallGraphSink();
00108     if(!callee->isDefined()) {
00109        
00110         continue;
00111     }
00112 
00113     // get procedure handle for caller
00117     OA_ptr<CallGraph::NodeInterface> caller = edge->getCallGraphSource();
00118     ProcHandle callerProc = caller->getProc();
00119 
00120     // get procedure handle for callee
00121     ProcHandle calleeProc = callee->getProc();
00122 
00123     // iterate over parameters at call site
00124     CallHandle call = edge->getCallHandle();
00125     OA_ptr<IRCallsiteParamIterator> paramIterPtr = mIR->getCallsiteParams(call);
00126     exprList = new std::list<ExprHandle>;
00127     for ( ; paramIterPtr->isValid(); (*paramIterPtr)++ ) {
00128         ExprHandle param = paramIterPtr->current();
00129         
00130         // compile list of ExprHandles of actual parameters in-order
00131         exprList->push_back(param);
00132 
00133         if (debug) {
00134           std::cout << "==== param = " << mIR->toString(param) << std::endl;
00135           std::cout << "callerProc = " << mIR->toString(callerProc) 
00136                     << ", hval = " << callerProc.hval() << std::endl;
00137           std::cout << "calleeProc = " << mIR->toString(calleeProc) 
00138                     << ", hval = " << calleeProc.hval() << std::endl;
00139         }
00140 
00141         OA_ptr<ExprTree> eTreePtr = mIR->getExprTree(param);
00142 
00143         // associate this ExprTree with this ExprHandle for future reference
00144         retval->mapExprToTree(param,eTreePtr);
00145         
00146         // get formal associated with callsite param
00147         SymHandle formal = mIR->getFormalForActual(callerProc, call, 
00148                                                    calleeProc, param);
00149 
00150         // map the formal SymHandle to the actual ExprHandle
00151         retval->mapFormalToExpr(call, formal, param);
00152      
00153         // associate formal parameter with  the procedure
00154         retval->mapFormalToProc(formal, calleeProc);
00155 
00156         // if the parameter is a memory reference then get the memory reference
00157         EvalToMemRefVisitor evalVisitor;
00158         eTreePtr->acceptVisitor(evalVisitor);
00159         if (debug) { eTreePtr->dump(std::cout,mIR); }
00160         MemRefHandle memref;
00161         if ( evalVisitor.isMemRef() ) {
00162           memref = evalVisitor.getMemRef();
00163         } else {
00164           continue;
00165         }
00166 
00167         // map the actual memref to the formal
00168         retval->mapMemRefToFormal(call, memref, calleeProc, formal);
00169 
00170     } // loop over parameters at callsite
00171     
00172     // map the callHandle to the list of actual ExprHandles
00173     retval->mapCallToExprList(call, exprList);
00174 
00175   }
00176 
00177   return retval;
00178 }
00179 
00180 //----------------------------------------------------------
00181 void FormalFinderVisitor::visitUnnamedRef(UnnamedRef& ref) 
00182 { 
00183 }
00184 
00185 void FormalFinderVisitor::visitUnknownRef(UnknownRef& ref) 
00186 { 
00187 }
00188 
00189 void FormalFinderVisitor::visitAddressOf(AddressOf& ref)
00190 {
00191 }
00192 
00193 void FormalFinderVisitor::visitNamedRef(NamedRef& ref) 
00194 {
00195     if (mIR->isParam(ref.getSymHandle())) { 
00196         // associate formal parameter with  the procedure
00197         mParamBind->mapFormalToProc(ref.getSymHandle(), mProc);
00198     }
00199 }
00200 
00201 void FormalFinderVisitor::visitDeref(Deref& ref) 
00202 { 
00203   // first call recursively on what we are a dereference for
00204   OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
00205   if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); }
00206 }   
00207 
00208 void FormalFinderVisitor::visitSubSetRef(SubSetRef& ref) 
00209 {
00210   // first call recursively on what we are a subset of
00211   OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
00212   if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); }
00213 }
00214 
00215 
00216 
00217   } // end of namespace DataFlow
00218 } // end of namespace OA

Generated on Sat Oct 31 05:21:24 2009 for OpenAnalysis by  doxygen 1.6.1