yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SubCircuit::SolverWorker::DiEdge Struct Reference
+ Collaboration diagram for SubCircuit::SolverWorker::DiEdge:

Public Member Functions

bool operator< (const DiEdge &other) const
 
bool compare (const DiEdge &other, const std::map< std::string, std::string > &mapFromPorts, const std::map< std::string, std::string > &mapToPorts) const
 
bool compareWithFromAndToPermutations (const DiEdge &other, const std::map< std::string, std::string > &mapFromPorts, const std::map< std::string, std::string > &mapToPorts, const std::map< std::string, std::set< std::map< std::string, std::string >>> &swapPermutations) const
 
bool compareWithToPermutations (const DiEdge &other, const std::map< std::string, std::string > &mapFromPorts, const std::map< std::string, std::string > &mapToPorts, const std::map< std::string, std::set< std::map< std::string, std::string >>> &swapPermutations) const
 
bool compare (const DiEdge &other, const std::map< std::string, std::set< std::set< std::string >>> &swapPorts, const std::map< std::string, std::set< std::map< std::string, std::string >>> &swapPermutations) const
 
bool compare (const DiEdge &other, const std::map< std::string, std::string > &mapFromPorts, const std::map< std::string, std::set< std::set< std::string >>> &swapPorts, const std::map< std::string, std::set< std::map< std::string, std::string >>> &swapPermutations) const
 
std::string toString () const
 

Static Public Member Functions

static void findEdgesInGraph (const Graph &graph, std::map< std::pair< int, int >, DiEdge > &edges)
 

Data Fields

DiNode fromNode
 
DiNode toNode
 
std::set< DiBitbits
 
std::string userAnnotation
 

Detailed Description

Definition at line 455 of file subcircuit.cc.

Member Function Documentation

bool SubCircuit::SolverWorker::DiEdge::compare ( const DiEdge other,
const std::map< std::string, std::string > &  mapFromPorts,
const std::map< std::string, std::string > &  mapToPorts 
) const
inline

Definition at line 472 of file subcircuit.cc.

473  {
474  // Rules for matching edges:
475  //
476  // For all bits in the needle edge:
477  // - ignore if needle ports don't exist in haystack edge
478  // - otherwise: matching bit in haystack edge must exist
479  //
480  // There is no need to check in the other direction, as checking
481  // of the isExtern properties is already performed in node matching.
482  //
483  // Note: "this" is needle, "other" is haystack
484 
485  for (auto bit : bits)
486  {
487  if (mapFromPorts.count(bit.fromPort) > 0)
488  bit.fromPort = mapFromPorts.at(bit.fromPort);
489  if (mapToPorts.count(bit.toPort) > 0)
490  bit.toPort = mapToPorts.at(bit.toPort);
491 
492  if (other.fromNode.portSizes.count(bit.fromPort) == 0)
493  continue;
494  if (other.toNode.portSizes.count(bit.toPort) == 0)
495  continue;
496 
497  if (bit.fromBit >= other.fromNode.portSizes.at(bit.fromPort))
498  continue;
499  if (bit.toBit >= other.toNode.portSizes.at(bit.toPort))
500  continue;
501 
502  if (other.bits.count(bit) == 0)
503  return false;
504  }
505 
506  return true;
507  }

+ Here is the caller graph for this function:

bool SubCircuit::SolverWorker::DiEdge::compare ( const DiEdge other,
const std::map< std::string, std::set< std::set< std::string >>> &  swapPorts,
const std::map< std::string, std::set< std::map< std::string, std::string >>> &  swapPermutations 
) const
inline

Definition at line 535 of file subcircuit.cc.

537  {
538  // brute force method for port swapping: try all variations
539 
540  std::vector<std::vector<std::string>> swapFromPorts;
541  std::vector<std::vector<std::string>> swapToPorts;
542 
543  // only use groups that are relevant for this edge
544 
545  if (swapPorts.count(fromNode.typeId) > 0)
546  for (const auto &ports : swapPorts.at(fromNode.typeId)) {
547  for (const auto &bit : bits)
548  if (ports.count(bit.fromPort))
549  goto foundFromPortMatch;
550  if (0) {
551  foundFromPortMatch:
552  std::vector<std::string> portsVector;
553  for (const auto &port : ports)
554  portsVector.push_back(port);
555  swapFromPorts.push_back(portsVector);
556  }
557  }
558 
559  if (swapPorts.count(toNode.typeId) > 0)
560  for (const auto &ports : swapPorts.at(toNode.typeId)) {
561  for (const auto &bit : bits)
562  if (ports.count(bit.toPort))
563  goto foundToPortMatch;
564  if (0) {
565  foundToPortMatch:
566  std::vector<std::string> portsVector;
567  for (const auto &port : ports)
568  portsVector.push_back(port);
569  swapToPorts.push_back(portsVector);
570  }
571  }
572 
573  // try all permutations
574 
575  std::map<std::string, std::string> mapFromPorts, mapToPorts;
576  int fromPortsPermutations = numberOfPermutationsArray(swapFromPorts);
577  int toPortsPermutations = numberOfPermutationsArray(swapToPorts);
578 
579  for (int i = 0; i < fromPortsPermutations; i++)
580  {
581  permutateVectorToMapArray(mapFromPorts, swapFromPorts, i);
582 
583  for (int j = 0; j < toPortsPermutations; j++) {
584  permutateVectorToMapArray(mapToPorts, swapToPorts, j);
585  if (compareWithFromAndToPermutations(other, mapFromPorts, mapToPorts, swapPermutations))
586  return true;
587  }
588  }
589 
590  return false;
591  }
std::map< std::string, std::set< std::map< std::string, std::string > > > swapPermutations
Definition: subcircuit.cc:719
static void permutateVectorToMapArray(std::map< std::string, std::string > &map, const std::vector< std::vector< std::string >> &list, int idx)
Definition: subcircuit.cc:370
static int numberOfPermutationsArray(const std::vector< std::vector< std::string >> &list)
Definition: subcircuit.cc:359
bool compareWithFromAndToPermutations(const DiEdge &other, const std::map< std::string, std::string > &mapFromPorts, const std::map< std::string, std::string > &mapToPorts, const std::map< std::string, std::set< std::map< std::string, std::string >>> &swapPermutations) const
Definition: subcircuit.cc:509
std::map< std::string, std::set< std::set< std::string > > > swapPorts
Definition: subcircuit.cc:718

+ Here is the call graph for this function:

bool SubCircuit::SolverWorker::DiEdge::compare ( const DiEdge other,
const std::map< std::string, std::string > &  mapFromPorts,
const std::map< std::string, std::set< std::set< std::string >>> &  swapPorts,
const std::map< std::string, std::set< std::map< std::string, std::string >>> &  swapPermutations 
) const
inline

Definition at line 593 of file subcircuit.cc.

595  {
596  // strip-down version of the last function: only try permutations for mapToPorts, mapFromPorts is already provided by the caller
597 
598  std::vector<std::vector<std::string>> swapToPorts;
599 
600  if (swapPorts.count(toNode.typeId) > 0)
601  for (const auto &ports : swapPorts.at(toNode.typeId)) {
602  for (const auto &bit : bits)
603  if (ports.count(bit.toPort))
604  goto foundToPortMatch;
605  if (0) {
606  foundToPortMatch:
607  std::vector<std::string> portsVector;
608  for (const auto &port : ports)
609  portsVector.push_back(port);
610  swapToPorts.push_back(portsVector);
611  }
612  }
613 
614  std::map<std::string, std::string> mapToPorts;
615  int toPortsPermutations = numberOfPermutationsArray(swapToPorts);
616 
617  for (int j = 0; j < toPortsPermutations; j++) {
618  permutateVectorToMapArray(mapToPorts, swapToPorts, j);
619  if (compareWithToPermutations(other, mapFromPorts, mapToPorts, swapPermutations))
620  return true;
621  }
622 
623  return false;
624  }
std::map< std::string, std::set< std::map< std::string, std::string > > > swapPermutations
Definition: subcircuit.cc:719
static void permutateVectorToMapArray(std::map< std::string, std::string > &map, const std::vector< std::vector< std::string >> &list, int idx)
Definition: subcircuit.cc:370
static int numberOfPermutationsArray(const std::vector< std::vector< std::string >> &list)
Definition: subcircuit.cc:359
std::map< std::string, std::set< std::set< std::string > > > swapPorts
Definition: subcircuit.cc:718
bool compareWithToPermutations(const DiEdge &other, const std::map< std::string, std::string > &mapFromPorts, const std::map< std::string, std::string > &mapToPorts, const std::map< std::string, std::set< std::map< std::string, std::string >>> &swapPermutations) const
Definition: subcircuit.cc:522

+ Here is the call graph for this function:

bool SubCircuit::SolverWorker::DiEdge::compareWithFromAndToPermutations ( const DiEdge other,
const std::map< std::string, std::string > &  mapFromPorts,
const std::map< std::string, std::string > &  mapToPorts,
const std::map< std::string, std::set< std::map< std::string, std::string >>> &  swapPermutations 
) const
inline

Definition at line 509 of file subcircuit.cc.

511  {
512  if (swapPermutations.count(fromNode.typeId) > 0)
513  for (const auto &permutation : swapPermutations.at(fromNode.typeId)) {
514  std::map<std::string, std::string> thisMapFromPorts = mapFromPorts;
515  applyPermutation(thisMapFromPorts, permutation);
516  if (compareWithToPermutations(other, thisMapFromPorts, mapToPorts, swapPermutations))
517  return true;
518  }
519  return compareWithToPermutations(other, mapFromPorts, mapToPorts, swapPermutations);
520  }
std::map< std::string, std::set< std::map< std::string, std::string > > > swapPermutations
Definition: subcircuit.cc:719
static void applyPermutation(std::map< std::string, std::string > &map, const std::map< std::string, std::string > &permutation)
Definition: subcircuit.cc:380
bool compareWithToPermutations(const DiEdge &other, const std::map< std::string, std::string > &mapFromPorts, const std::map< std::string, std::string > &mapToPorts, const std::map< std::string, std::set< std::map< std::string, std::string >>> &swapPermutations) const
Definition: subcircuit.cc:522

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool SubCircuit::SolverWorker::DiEdge::compareWithToPermutations ( const DiEdge other,
const std::map< std::string, std::string > &  mapFromPorts,
const std::map< std::string, std::string > &  mapToPorts,
const std::map< std::string, std::set< std::map< std::string, std::string >>> &  swapPermutations 
) const
inline

Definition at line 522 of file subcircuit.cc.

524  {
525  if (swapPermutations.count(toNode.typeId) > 0)
526  for (const auto &permutation : swapPermutations.at(toNode.typeId)) {
527  std::map<std::string, std::string> thisMapToPorts = mapToPorts;
528  applyPermutation(thisMapToPorts, permutation);
529  if (compare(other, mapFromPorts, thisMapToPorts))
530  return true;
531  }
532  return compare(other, mapFromPorts, mapToPorts);
533  }
std::map< std::string, std::set< std::map< std::string, std::string > > > swapPermutations
Definition: subcircuit.cc:719
bool compare(const DiEdge &other, const std::map< std::string, std::string > &mapFromPorts, const std::map< std::string, std::string > &mapToPorts) const
Definition: subcircuit.cc:472
static void applyPermutation(std::map< std::string, std::string > &map, const std::map< std::string, std::string > &permutation)
Definition: subcircuit.cc:380

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void SubCircuit::SolverWorker::DiEdge::findEdgesInGraph ( const Graph graph,
std::map< std::pair< int, int >, DiEdge > &  edges 
)
inlinestatic

Definition at line 636 of file subcircuit.cc.

637  {
638  edges.clear();
639  for (const auto &edge : graph.edges) {
640  if (edge.constValue != 0)
641  continue;
642  for (const auto &fromBit : edge.portBits)
643  for (const auto &toBit : edge.portBits)
644  if (&fromBit != &toBit) {
645  DiEdge &de = edges[std::pair<int, int>(fromBit.nodeIdx, toBit.nodeIdx)];
646  de.fromNode = DiNode(graph, fromBit.nodeIdx);
647  de.toNode = DiNode(graph, toBit.nodeIdx);
648  std::string fromPortId = graph.nodes[fromBit.nodeIdx].ports[fromBit.portIdx].portId;
649  std::string toPortId = graph.nodes[toBit.nodeIdx].ports[toBit.portIdx].portId;
650  de.bits.insert(DiBit(fromPortId, fromBit.bitIdx, toPortId, toBit.bitIdx));
651  }
652  }
653  }
std::vector< Node > nodes
Definition: subcircuit.h:72
std::vector< Edge > edges
Definition: subcircuit.h:73

+ Here is the caller graph for this function:

bool SubCircuit::SolverWorker::DiEdge::operator< ( const DiEdge other) const
inline

Definition at line 461 of file subcircuit.cc.

462  {
463  if (fromNode < other.fromNode || other.fromNode < fromNode)
464  return fromNode < other.fromNode;
465  if (toNode < other.toNode || other.toNode < toNode)
466  return toNode < other.toNode;
467  if (bits < other.bits || other.bits < bits)
468  return bits < other.bits;
469  return userAnnotation < other.userAnnotation;
470  }
std::string SubCircuit::SolverWorker::DiEdge::toString ( ) const
inline

Definition at line 626 of file subcircuit.cc.

627  {
628  std::string buffer = fromNode.toString() + " " + toNode.toString();
629  for (const auto &bit : bits)
630  buffer += " " + bit.toString();
631  if (!userAnnotation.empty())
632  buffer += " " + userAnnotation;
633  return buffer;
634  }
std::string toString() const
Definition: subcircuit.cc:443

+ Here is the call graph for this function:

Field Documentation

std::set<DiBit> SubCircuit::SolverWorker::DiEdge::bits

Definition at line 458 of file subcircuit.cc.

DiNode SubCircuit::SolverWorker::DiEdge::fromNode

Definition at line 457 of file subcircuit.cc.

DiNode SubCircuit::SolverWorker::DiEdge::toNode

Definition at line 457 of file subcircuit.cc.

std::string SubCircuit::SolverWorker::DiEdge::userAnnotation

Definition at line 459 of file subcircuit.cc.


The documentation for this struct was generated from the following file: