bool printDataflowInfoPass::transfer(const Function& func, const DataflowNode& n, NodeState& state, const vector<Lattice*>& dfInfo) { Dbg::dbg << "-----#############################--------\n"; Dbg::dbg << "Node: ["<<Dbg::escape(n.getNode()->unparseToString())<<" | "<< n.getNode()->class_name()<<"]\n"; // print out all the dataflow facts associated with analysis at this node const /*map <int, NodeFact*>*/vector<NodeFact*> facts = state.getFacts(analysis); int i=0; for(/*map <int, NodeFact*>*/vector<NodeFact*>::const_iterator it = facts.begin(); it!=facts.end(); it++, i++) { //Dbg::dbg << "Fact "<<it->first<<": \n "<<it->second->str(" ")<<endl; Dbg::dbg << "Fact "<<i<<": \n "<<(*it)->str(" ")<<endl; } const vector<Lattice*> dfInfoAbove = state.getLatticeAbove((Analysis*)analysis); const vector<Lattice*> dfInfoBelow = state.getLatticeBelow((Analysis*)analysis); vector<Lattice*>::const_iterator itA, itB; for(itA = dfInfoAbove.begin(), itB = dfInfoBelow.begin(); itA != dfInfoAbove.end() && itB != dfInfoBelow.end(); itA++, itB++) { Dbg::dbg << " Lattice Above "<<*itA<<": \n "<<(*itA)->str(" ")<<endl; Dbg::dbg << " Lattice Below "<<*itB<<": \n "<<(*itB)->str(" ")<<endl; } return dynamic_cast<BoolAndLattice*>(dfInfo[0])->set(true); }
MemLocObjectPtr PointsToAnalysis::Expr2MemLoc(SgNode* sgn, PartEdgePtr pedge) { scope reg(txt()<<"PointsToAnalysis::Expr2MemLoc(sgn=" << SgNode2Str(sgn) << ")", scope::medium, ptaDebugLevel, 1); if(ptaDebugLevel>=1) dbg << "pedge=" << pedge->str() << endl; // NOTE: source and target of edge are not wildcard if(pedge->source() && pedge->target()) { NodeState* state = NodeState::getNodeState(this, pedge->source()); if(ptaDebugLevel>=1) dbg << "state="<<state->str(this)<<endl; AbstractObjectMap* aom = dynamic_cast<AbstractObjectMap*>(state->getLatticeBelow(this, pedge, 0)); assert(aom); boost::shared_ptr<AbstractObjectSet> aos = getPointsToSet(sgn, pedge, aom); return boost::dynamic_pointer_cast<MemLocObject>(Expr2PointsToMLPtr(sgn, pedge, aos)); } // NOTE: merge information across all outgoing edges // target of this edge is wildcard else if(pedge->source()) { NodeState* state = NodeState::getNodeState(this, pedge->source()); //dbg << "state="<<state->str(this)<<endl; // Merge the lattices along all the outgoing edges map<PartEdgePtr, std::vector<Lattice*> >& e2lats = state->getLatticeBelowAllMod(this); assert(e2lats.size()>=1); boost::shared_ptr<AbstractObjectSet> mergedSet = boost::make_shared<AbstractObjectSet>(pedge, getComposer(), this, AbstractObjectSet::may); for(map<PartEdgePtr, std::vector<Lattice*> >::iterator lats=e2lats.begin(); lats!=e2lats.end(); lats++) { PartEdge* edgePtr = lats->first.get(); assert(edgePtr->source() == pedge.get()->source()); AbstractObjectMap* aom = dynamic_cast<AbstractObjectMap*>(state->getLatticeBelow(this, lats->first, 0)); assert(aom); if(ptaDebugLevel>=1) dbg << "aom="<<aom->str()<<endl; boost::shared_ptr<AbstractObjectSet> aos = getPointsToSet(sgn, pedge, aom); // NOTE: It can be empty if no entry was found in AbstractObjectMap // Safe approximation : merge only if it contains pointsTo information along this particular edge // if(aos.get()) mergedSet->meetUpdate(aos.get()); } return boost::dynamic_pointer_cast<MemLocObject>(Expr2PointsToMLPtr(sgn, pedge, mergedSet)); } // source of this edge is a wildcard else if(pedge->target()) { NodeState* state = NodeState::getNodeState(this, pedge->target()); if(ptaDebugLevel>=1) dbg << "state="<<state->str()<<endl; AbstractObjectMap* aom = dynamic_cast<AbstractObjectMap*>(state->getLatticeAbove(this, NULLPartEdge, 0)); assert(aom); boost::shared_ptr<AbstractObjectSet> aos = getPointsToSet(sgn, pedge, aom); return boost::dynamic_pointer_cast<MemLocObject>(Expr2PointsToMLPtr(sgn, pedge, aos)); } else { assert(false); return PointsToMLPtr(); } }
void MergeAllReturnStates::visit(const Function& func, const DataflowNode& n, NodeState& state) { SgNode* sgn = n.getNode(); if(analysisDebugLevel>=1) Dbg::dbg << "MergeAllReturnStates::visit() func="<<func.get_name().getString()<<"() sgn="<<sgn<<"["<<Dbg::escape(sgn->unparseToString())<<" | "<<sgn->class_name()<<"]\n"; //Dbg::dbg << "visit {{{: modified="<<modified<<endl; // If this is an explicit return statement if(isSgReturnStmt(sgn)) { if(analysisDebugLevel>=1) Dbg::dbg << "MergeAllReturnStates::visit() isSgReturnStmt(sgn)->get_expression()="<<isSgReturnStmt(sgn)->get_expression()<<"["<<Dbg::escape(isSgReturnStmt(sgn)->get_expression()->unparseToString())<<" | "<<isSgReturnStmt(sgn)->get_expression()->class_name()<<"]\n"; ROSE_ASSERT(NodeState::getNodeStates(n).size()==1); NodeState* state = *(NodeState::getNodeStates(n).begin()); // Incorporate the entire dataflow state at the return statement if(analysisDebugLevel>=1) Dbg::dbg << " Merging dataflow state at return statement\n"; modified = mergeLats(mergedLatsRetStmt, state->getLatticeAbove(analysis)) || modified; // Incorporate just the portion of the dataflow state that corresponds to the value being returned, // assuming that any information is available vector<Lattice*> exprLats; for(vector<Lattice*>::const_iterator l=state->getLatticeAbove(analysis).begin(); l!=state->getLatticeAbove(analysis).end(); l++) exprLats.push_back((*l)->project(isSgReturnStmt(sgn)->get_expression())); if(analysisDebugLevel>=1) Dbg::dbg << " Merging dataflow state of return value\n"; modified = mergeLats(mergedLatsRetVal, exprLats) || modified; } // If this is the end of a function, which is an implicit return that has no return value else if(isSgFunctionDefinition(sgn)) { if(analysisDebugLevel>=1) Dbg::dbg << "MergeAllReturnStates::visit() isSgFunctionDefinition\n"; ROSE_ASSERT(NodeState::getNodeStates(n).size()==1); NodeState* state = *(NodeState::getNodeStates(n).begin()); // Incorporate the entire dataflow state at the implicit return statement modified = mergeLats(mergedLatsRetStmt, state->getLatticeAbove(analysis)) || modified; } //Dbg::dbg << "visit >>>: modified="<<modified<<endl; }
void evaluateAnalysisStates::visit(const Function& func, const DataflowNode& n, NodeState& state) { SgFunctionCallExp *fnCall = isSgFunctionCallExp(n.getNode()); if (!fnCall) return; if (!fnCall->getAssociatedFunctionSymbol()) return; string funcName = fnCall->getAssociatedFunctionSymbol()->get_name().getString(); if (funcName.find("testFunc") == string::npos) return; FiniteVarsExprsProductLattice *lat = dynamic_cast<FiniteVarsExprsProductLattice *>(state.getLatticeAbove(div)[0]); cout << indent << "Lattice before call to " << funcName << ": " << lat->str() << endl; set<varID> allVars = lat->getAllVars(); for (set<varID>::iterator i = allVars.begin(); i != allVars.end(); ++i) { string name = i->str(); cout << "Variable " << name << " "; if (expectations[funcName].find(name) == expectations[funcName].end()) { cout << "unspecified" << endl; continue; } Lattice *got = lat->getVarLattice(*i); ROSE_ASSERT(got); if (expectations[funcName][name] != got) { cout << "mismatched: " << got->str() << " was not the expected " << expectations[funcName][name].str(); numFails++; } else { cout << "matched"; numPass++; } cout << endl; } }