Пример #1
0
void simplifyPFBlock(const Edges& toUnlink, const PFBlock& block, Blocks& simplifiedBlocks, Nodes& history) {
  // take a block, unlink some of the edges and
  // create smaller blocks or a simplified blocks
  // or if nothing has changed take a copy of the original block
  if (toUnlink.size() == 0) {
    // no change needed, just make a copy of block
    PFBlock newblock(block.elementIds(), block.edges(), simplifiedBlocks.size(), 's');  // will copy edges and ids
    PDebug::write("Made {}", newblock);
    auto id = newblock.id();
    simplifiedBlocks.emplace(id, std::move(newblock));
    // update history
    makeHistoryLinks(block.elementIds(), {id}, history);
  } else {
    Edges modifiedEdges;
    for (auto edge : block.edges()) {  // copying edges
      Edge e = edge.second;
      if (toUnlink.find(edge.first) != toUnlink.end()) {
        e.setLinked(false);
      }
      modifiedEdges.emplace(e.key(), e);
    }
    // create new blocks and add into simplifiedBlocks
    buildPFBlocks(block.elementIds(), modifiedEdges, 's', simplifiedBlocks, history);
  }
}
Пример #2
0
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));
   }
}
Пример #3
0
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";
}
Пример #4
0
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;
}
Пример #5
0
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());
}
Пример #6
0
BlockSplitter::BlockSplitter(const Edges& unlinkEdges, PFBlock& block, Nodes& historynodes) : m_blocks() {
  Edges modifiedEdges;
  for (auto edge : block.edges()) {  // copy edges
    Edge e = edge.second;
    if (unlinkEdges.find(edge.first) != unlinkEdges.end()) {
      e.setLinked(false);
    }
    modifiedEdges.emplace(e.key(), std::move(e));
  }

  BlockBuilder bbuilder{block.elementIds(), std::move(modifiedEdges), historynodes};
  m_blocks = bbuilder.moveBlocks();
  block.setActive(false);
}
Пример #7
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";
    }
Пример #8
0
PFBlock::PFBlock(const Ids& element_ids, Edges& edges)
    : m_uniqueId(Id::makeBlockId()), m_isActive(true), m_elementIds(element_ids) {
  PFBlock::tempBlockCount += 1;

  // extract the relevant parts of the complete set of edges and store this within the block
  // note the edges will be removed from the edges unordered_map
  for (auto id1 : m_elementIds) {
    for (auto id2 : m_elementIds) {
      if (id1 >= id2) continue;
      // move the edge from one unordered map to the other
      auto e = edges.find(Edge::makeKey(id1, id2));
      if (e == edges.end()) throw std::range_error("Required Edge is missing from edges collection");
      m_edges.emplace(e->second.key(), std::move(e->second));
      edges.erase(e);
    }
  }
}
Пример #9
0
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;
}
Пример #10
0
 SbkObjectType* identifyType(void** cptr, SbkObjectType* type, SbkObjectType* baseType) const
 {
     Edges::const_iterator edgesIt = m_edges.find(type);
     if (edgesIt != m_edges.end()) {
         const NodeList& adjNodes = m_edges.find(type)->second;
         NodeList::const_iterator i = adjNodes.begin();
         for (; i != adjNodes.end(); ++i) {
             SbkObjectType* newType = identifyType(cptr, *i, baseType);
             if (newType)
                 return newType;
         }
     }
     void* typeFound = ((type->d && type->d->type_discovery) ? type->d->type_discovery(*cptr, baseType) : 0);
     if (typeFound) {
         // This "typeFound != type" is needed for backwards compatibility with old modules using a newer version of
         // libshiboken because old versions of type_discovery function used to return a SbkObjectType* instead of
         // a possible variation of the C++ instance pointer (*cptr).
         if (typeFound != type)
             *cptr = typeFound;
         return type;
     } else {
         return 0;
     }
 }
Пример #11
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());
}
Пример #12
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();
}
Пример #13
0
void Graph::sort_edges() {
	std::sort(edges.begin(), edges.end());
}