DepCompAstRefDAG(const DepCompAstRefAnal& stmtorder, const DepCompAstRefGraphCreate* g) { DoublyLinkedListWrap <DepCompAstRefGraphNode*> nodelist; DepCompAstRefGraphCreate::NodeIterator nodes = g->GetNodeIterator(); for ( ; !nodes.ReachEnd(); nodes.Advance()) { DepCompAstRefGraphNode* n = nodes.Current(); AddNode(n); nodelist.AppendLast(n); } if (nodelist.size() <= 1) return; for (nodes.Reset(); !nodes.ReachEnd(); nodes.Advance()) { DepCompAstRefGraphNode* n = *nodes; DepCompAstRef& info = n->GetInfo(); for (DepInfoEdgeIterator edges = g->GetNodeEdgeIterator(n, GraphAccess::EdgeOut); !edges.ReachEnd(); ++edges) { DepInfoEdge* e = *edges; DepCompAstRefGraphNode* n1 = g->GetEdgeEndPoint(e, GraphAccess::EdgeIn); DepCompAstRef& info1 = n1->GetInfo(); int c = stmtorder.CompareAstRef(info,info1); if (c < 0) { AddEdge(n, n1, e); } else if (c > 0) { AddEdge(n1,n,e); } } } if (DebugRefFuse()) { std::cerr << GraphToString(*this) << std::endl; } }
void ValuePropagate:: build(AstInterface& fa, const AstNodePtr& head, AliasAnalysisInterface& alias, FunctionSideEffectInterface* f) { ReachingDefinitionAnalysis r; if (DebugValuePropogate()) std::cerr << "constructing reaching definitions\n"; r(fa, head, f); if (DebugValuePropogate()) std::cerr << "finished reaching definition\n" << GraphToString(*this) << std::endl; build(fa, head, r, alias, f); }
void DefUseChain<Node>:: build( AstInterface& fa, ReachingDefinitionAnalysis& r, AliasAnalysisInterface& alias, FunctionSideEffectInterface* f) { std::vector <Node*> defvec; const ReachingDefinitionGenerator* g = r.get_generator(); StmtSideEffectCollect collect(f); std::map<AstNodePtr, Node*> defmap; const ReachingDefinitionBase& base = g->get_base(); for (ReachingDefinitionBase::iterator p = base.begin(); p != base.end(); ++p) { std::pair<AstNodePtr,AstNodePtr> cur = base.get_ref(p); if (DebugDefUseChain()) std::cerr << "creating def node : " << AstToString(cur.first) << " : " << AstToString(cur.second) << std::endl; Node* n = CreateNode( fa, cur.first, cur.second, true); assert(n != 0); defvec.push_back(n); defmap[cur.first] = n; } for (ReachingDefinitionAnalysis::NodeIterator p = r.GetNodeIterator(); !p.ReachEnd(); ++p) { ReachingDefNode* cur = *p; if (DebugDefUseChain()) { std::cerr << "processing CFG node : "; cur->write(std::cerr); } ReachingDefinitions in = cur->get_entry_defs(); if (DebugDefUseChain()) { std::cerr << "Reaching definitions: \n"; DumpDefSet(defvec,in); std::cerr << std::endl; } ProcessUseInfo<Node> opread( this, defvec, g, alias,fa, in); ProcessGenInfo<Node> opgen( this, defvec, g, alias, fa, defmap, in); ProcessKillInfo<Node> opkill( this, defvec, g, alias, fa, defmap, in); std::list <AstNodePtr>& stmts = cur->GetStmts(); for (std::list<AstNodePtr>::iterator p = stmts.begin(); p != stmts.end(); ++p) { AstNodePtr cur = *p; if (DebugDefUseChain()) std::cerr << "processing stmt : " << AstToString(cur) << std::endl; collect(fa, cur, &opgen, &opread, &opkill); } } if (DebugDefUseChain()) { std::cerr << "\nfinished building def-use chain:\n"; std::cerr << GraphToString(*this); } }
void ValuePropagate:: build(AstInterface& fa, const AstNodePtr& h, ReachingDefinitionAnalysis& r, AliasAnalysisInterface& alias, FunctionSideEffectInterface* f) { if (DebugValuePropogate()) std::cerr << "building def-use chain\n"; DefUseChain<ValuePropagateNode>::build(fa, r, alias, f); if (DebugValuePropogate()) write_graph(*this, std::cout, "def-use"); if (DebugValuePropogate()) { std::cerr << "finshed building def-use chain\n"; std::cerr << "propagating values on def-use chain\n"; } UpdateValuePropagateNode update(fa, h, valmap, astmap, nodemap); PropagateDefUseChainUpdate( this, update); if (DebugValuePropogate()) std::cerr << "\nfinished propagating values on def-use chain\n" << GraphToString(*this) << std::endl; }
void ReachingDefinitionAnalysis:: operator()( AstInterface& fa, const AstNodePtr& h, FunctionSideEffectInterface* anal) { assert( g == 0 && pars.size() == 0); AstNodePtr body = h; if (!fa.IsFunctionDefinition( h, 0, &pars, 0, &body)) ;//assert(false); ReachingDefinitionBase base; base.collect_refs( fa, body, anal, &pars); base.finalize(); g = new ReachingDefinitionGenerator( base); a = anal; if (DebugReachingDef()) std::cerr << "start building reaching definitions \n"; DataFlowAnalysis<ReachingDefNode, ReachingDefinitions>::operator()( fa, h); if (DebugReachingDef()) std::cerr << "finished building reaching definitions \n" << GraphToString(*this); }
bool graph_test_create(){ logInfo("graph_test_create..."); Graph *graph = NULL; CreateTestGraph1(&graph); if(GraphIsDestroyed(graph)){ logError("fail - CreateTestGraph1() returned null."); return false; } logDebug(GraphToString(graph)); GraphDestroy(&graph); if(!GraphIsDestroyed(graph)){ logError("fail - GraphIsDestroyed() was not successful."); return false; } logInfo("success."); return true; }