コード例 #1
0
ファイル: PatchMgr.C プロジェクト: Zirkon/dyninst
void PatchMgr::getEdgeCandidates(Scope &scope, Point::Type, Candidates &ret) {
   Edges edges;
   getEdges(scope, edges);
   for (Edges::iterator iter = edges.begin(); iter != edges.end(); ++iter) {
      ret.push_back(Candidate(Location::Edge(*iter), Point::EdgeDuring));
   }
}
コード例 #2
0
ファイル: Mutation.cpp プロジェクト: kzahedi/NMODE
void Mutation::__cleanup(Module *m)
{
  VLOG(50) << ">>>>> clean up";
  LOG_MODULE;
  for(Edges::iterator e = m->e_begin(); e != m->e_end(); e++)
  {
    if((*e)->sourceNode() == NULL || (*e)->destinationNode() == NULL) m->removeEdge(*e);
  }
  Edges toBeRemoved;
  for(Edges::iterator e = m->e_begin(); e != m->e_end(); e++)
  {
    for(Edges::iterator f = m->e_begin(); f != m->e_end(); f++)
    {
      if((*e)->sourceNode()->label() == (*f)->sourceNode()->label() &&
         (*e)->sourceNode()          != (*f)->sourceNode()          &&
         (*e)                        != (*f))
      {
        toBeRemoved.push_back(*e);
      }
    }
  }
  for(Edges::iterator e = toBeRemoved.begin(); e != toBeRemoved.end(); e++)
  {
    m->removeEdge(*e);
  }
  LOG_MODULE;
  VLOG(50) << "<<<<< clean up";
}
コード例 #3
0
ファイル: math.hpp プロジェクト: go4and/lib
inline bool onEdge(const Point & point, const Poly & poly, const Edges & edges, const S & eps)
{
    for(auto j = edges.begin(), jend = edges.end(); j != jend; ++j)
    {
        auto & p1 = poly[*j];
        auto & p2 = *j == 0 ? poly.back() : poly[*j - 1];
        if(onEdge(point, p1, p2, eps))
            return true;
    }
    return false;
}
コード例 #4
0
ファイル: split.cpp プロジェクト: AidanDelaney/adaptagrams
void split() {
    Nodes nodes;
    Edges es;

    printf("test: bend2()\n");

    addNode(nodes,100,100,40,20);
    addNode(nodes,100,130,40,20);
    addNode(nodes,70,160,40,20);
    addNode(nodes,180,190,40,20);
    EdgePoints p1;
    addToPath(p1,nodes[0],EdgePoint::CENTRE);
    addToPath(p1,nodes[1],EdgePoint::BL);
    addToPath(p1,nodes[1],EdgePoint::TL);
    addToPath(p1,nodes[3],EdgePoint::CENTRE);
    es.push_back(new Edge(100,p1));

    EdgePoints p2;
    addToPath(p2,nodes[2],EdgePoint::CENTRE);
    addToPath(p2,nodes[3],EdgePoint::CENTRE);
    es.push_back(new Edge(50,p2));

    const size_t V = nodes.size();

    vpsc::Constraints cs;
    vpsc::Variables vs;
    getVariables(nodes,vs);
    { // scope for t, so that t gets destroyed before es

        TopologyConstraints t(vpsc::HORIZONTAL,nodes,es,vs,cs);
        writeFile(nodes,es,"split-0.svg");

        // test computeStress
        double stress=t.computeStress();
        printf("Stress=%f\n",stress);
        //assert(fabs(expectedStress-stress)<1e-4);

        valarray<double> g(V);
        cola::SparseMap h(V);
        for(unsigned i=1;i<5;i++) {
            g=0;
            h.clear();
            t.gradientProjection(g,h);
            stringstream ss;
            ss << "split-" << i << ".svg";
            writeFile(nodes,es,ss.str().c_str());
        }
    }

    for_each(nodes.begin(),nodes.end(),delete_node());
    for_each(es.begin(),es.end(),delete_object());
    for_each(cs.begin(),cs.end(),delete_object());
    for_each(vs.begin(),vs.end(),delete_object());
}
コード例 #5
0
    void dumpDotGraph()
    {
        std::ofstream file("/tmp/shiboken_graph.dot");

        file << "digraph D {\n";

        Edges::const_iterator i = m_edges.begin();
        for (; i != m_edges.end(); ++i) {
            SbkObjectType* node1 = i->first;
            const NodeList& nodeList = i->second;
            NodeList::const_iterator j = nodeList.begin();
            for (; j != nodeList.end(); ++j)
                file << '"' << (*j)->super.ht_type.tp_name << "\" -> \"" << node1->super.ht_type.tp_name << "\"\n";
        }
        file << "}\n";
    }
コード例 #6
0
ファイル: pair_example.cpp プロジェクト: chaitanyav/UVA
int main(int argc, char *argv[]) {
  typedef std::pair<int, int> Edge;
  typedef std::vector<Edge> Edges;
  Edges edges;
  Edge edge;
  edge = std::make_pair(0, 1);
  edges.push_back(edge);

  std::cout << edge.first << " ---- " << edge.second << std::endl;
  edge = std::make_pair(1, 0);
  edges.push_back(edge);

  std::cout << edge.first << " ---- " << edge.second << std::endl;
  for(Edges::iterator it = edges.begin(); it != edges.end(); it++) {
    std::cout << (*it).first << " --- " << (*it).second << std::endl;
  }

  return 0;
}
コード例 #7
0
/*
 * compute the stress:
 * \f[
 *   \sigma = \sum_{e \in E} \left( d_e - \sum_{s \in S(e)} |s| \right)^2
 * \f]
 */
double computeStress(const Edges& es) {
    return sum_over(es.begin(),es.end(),0.0,ComputeStress());
}
コード例 #8
0
//_________________________________________________________________________________________________
void DCE::runImpl()
{
    bool early = false;
    getArg("early", early);
    if (early && !irManager->getCGFlags()->earlyDCEOn) {
        return;
    }

    irManager->updateLivenessInfo();
    irManager->calculateOpndStatistics();
    BitSet ls(irManager->getMemoryManager(), irManager->getOpndCount());
    const Nodes& nodes = irManager->getFlowGraph()->getNodesPostOrder();

#ifdef ORDER

    MemoryManager mm("dce_parents");

    U_32 opndCount = irManager->getOpndCount();
    bool * isParentOpnd = new(mm) bool [opndCount];
    memset(isParentOpnd, 0, sizeof(bool) * opndCount);
    for (Nodes::const_iterator it = nodes.begin(),end = nodes.end(); it!=end; ++it) {
        Node* node = *it;
        for (Inst * inst=(Inst*)node->getLastInst(); inst!=NULL; inst=inst->getPrevInst()) {
            Opnd* load_obj = inst->getParentObjectLoad();
            if (load_obj)
            {
                isParentOpnd[load_obj->getId()] = true;
            }

            Opnd* store_obj = inst->getParentObjectStore();
            if (store_obj)
            {
                isParentOpnd[store_obj->getId()] = true;
            }

        }
    }
#endif



    for (Nodes::const_iterator it = nodes.begin(),end = nodes.end(); it!=end; ++it) {
        Node* node = *it;
        if (node->isBlockNode()) {
            //Here we'll try to remove redundant branches that could appear after
            //branch translations. All such branches are supposed to be conditional.
            Inst * inst = (Inst *)node->getLastInst();
            if(inst && node->getOutEdges().size() > 1) {
                Edges edges = node->getOutEdges();
                for (Edges::const_iterator ite1 = ++edges.begin(), end = edges.end(); ite1 != end; ++ite1) {
                    for (Edges::const_iterator ite2 = edges.begin(); ite1 != ite2; ++ite2) {
                        Edge *edge1 = *ite1;
                        Edge *edge2 = *ite2;
                        assert(edge1 != edge2);

                        //If this condition is satisfied then there are at least two branches with
                        //the same destination
                        if (edge1->getTargetNode() == edge2->getTargetNode()) {
                            //Check that edges are conditional and the last instruction is branch,
                            //the other situations are not permitted at the moment
                            assert(inst->hasKind(Inst::Kind_BranchInst));
                            assert(edge1->getKind() == Edge::Kind_True ||
                                   edge1->getKind() == Edge::Kind_False);
                            assert(edge2->getKind() == Edge::Kind_True ||
                                   edge2->getKind() == Edge::Kind_False);

                            //Remove last instruction if it is a branch
                            inst->unlink();
                            irManager->getFlowGraph()->removeEdge(edge2);
                        }

                    }
                }
            }

            irManager->getLiveAtExit(node, ls);
            for (Inst * inst=(Inst*)node->getLastInst(), * prevInst=NULL; inst!=NULL; inst=prevInst) {
                prevInst=inst->getPrevInst();
                // Prevent debug traps or instructions with side effects
                // like (MOVS) from being removed.
                bool deadInst=!inst->hasSideEffect() && (inst->getMnemonic() != Mnemonic_INT3);

#ifdef ORDER //yzm
                for (unsigned int i = 0 ; i < inst->getOpndCount() ; i ++)
                {
                    Opnd* opnd = inst->getOpnd(i);
                    if (isParentOpnd[opnd->getId()])
                        deadInst = false;
                }
#endif

                if (deadInst) {
                    if (inst->hasKind(Inst::Kind_CopyPseudoInst)) {
                        Opnd * opnd=inst->getOpnd(1);
                        if (opnd->getType()->isFP() && opnd->getDefiningInst()!=NULL && opnd->getDefiningInst()->getMnemonic()==Mnemonic_CALL) {
                            deadInst=false;
                        }
                    }
                    if (deadInst) {
                        Inst::Opnds opnds(inst, Inst::OpndRole_All);
                        for (Inst::Opnds::iterator ito = opnds.begin(); ito != opnds.end(); ito = opnds.next(ito)) {
                            Opnd * opnd = inst->getOpnd(ito);
                            if ((ls.getBit(opnd->getId()) && (inst->getOpndRoles(ito) & Inst::OpndRole_Def)) ||
                                    (((opnd->getMemOpndKind()&(MemOpndKind_Heap|MemOpndKind_StackManualLayout))!=0) && (inst->getMnemonic() != Mnemonic_LEA))) {
                                deadInst=false;
                                break;
                            }
                        }
                    }
                }
                if (deadInst) {
                    inst->unlink();
                } else {
                    irManager->updateLiveness(inst, ls);
                }
            }
            irManager->getLiveAtEntry(node)->copyFrom(ls);
        }
    }

    irManager->eliminateSameOpndMoves();

    irManager->getFlowGraph()->purgeEmptyNodes();
    irManager->getFlowGraph()->mergeAdjacentNodes(true, false);
    irManager->getFlowGraph()->purgeUnreachableNodes();

    irManager->packOpnds();
    irManager->invalidateLivenessInfo();
}
コード例 #9
0
void Graph::sort_edges() {
	std::sort(edges.begin(), edges.end());
}