yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SubCircuitSolver Class Reference
+ Inheritance diagram for SubCircuitSolver:
+ Collaboration diagram for SubCircuitSolver:

Public Member Functions

 SubCircuitSolver ()
 
bool compareAttributes (const std::set< RTLIL::IdString > &attr, const std::map< RTLIL::IdString, RTLIL::Const > &needleAttr, const std::map< RTLIL::IdString, RTLIL::Const > &haystackAttr)
 
RTLIL::Const unified_param (RTLIL::IdString cell_type, RTLIL::IdString param, RTLIL::Const value)
 
virtual bool userCompareNodes (const std::string &, const std::string &, void *needleUserData, const std::string &, const std::string &, void *haystackUserData, const std::map< std::string, std::string > &portMapping)
 
void setVerbose ()
 
void addGraph (std::string graphId, const Graph &graph)
 
void addCompatibleTypes (std::string needleTypeId, std::string haystackTypeId)
 
void addCompatibleConstants (int needleConstant, int haystackConstant)
 
void addSwappablePorts (std::string needleTypeId, std::string portId1, std::string portId2, std::string portId3=std::string(), std::string portId4=std::string())
 
void addSwappablePorts (std::string needleTypeId, std::set< std::string > ports)
 
void addSwappablePortsPermutation (std::string needleTypeId, std::map< std::string, std::string > portMapping)
 
void solve (std::vector< Result > &results, std::string needleGraphId, std::string haystackGraphId, bool allowOverlap=true, int maxSolutions=-1)
 
void solve (std::vector< Result > &results, std::string needleGraphId, std::string haystackGraphId, const std::map< std::string, std::set< std::string >> &initialMapping, bool allowOverlap=true, int maxSolutions=-1)
 
void mine (std::vector< MineResult > &results, int minNodes, int maxNodes, int minMatches, int limitMatchesPerGraph=-1)
 
void clearOverlapHistory ()
 
void clearConfig ()
 

Data Fields

bool ignore_parameters
 
std::set< std::pair
< RTLIL::IdString,
RTLIL::IdString > > 
ignored_parameters
 
std::set< RTLIL::IdStringcell_attr
 
std::set< RTLIL::IdStringwire_attr
 

Protected Member Functions

virtual std::string userAnnotateEdge (const std::string &graphId, const std::string &fromNodeId, void *fromUserData, const std::string &toNodeId, void *toUserData)
 
virtual bool userCompareEdge (const std::string &needleGraphId, const std::string &needleFromNodeId, void *needleFromUserData, const std::string &needleToNodeId, void *needleToUserData, const std::string &haystackGraphId, const std::string &haystackFromNodeId, void *haystackFromUserData, const std::string &haystackToNodeId, void *haystackToUserData)
 
virtual bool userCheckSolution (const Result &result)
 

Detailed Description

Definition at line 34 of file extract.cc.

Constructor & Destructor Documentation

SubCircuitSolver::SubCircuitSolver ( )
inline

Definition at line 41 of file extract.cc.

41  : ignore_parameters(false)
42  {
43  }
bool ignore_parameters
Definition: extract.cc:37

Member Function Documentation

void SubCircuit::Solver::addCompatibleConstants ( int  needleConstant,
int  haystackConstant 
)
inherited

Definition at line 1642 of file subcircuit.cc.

1643 {
1644  worker->addCompatibleConstants(needleConstant, haystackConstant);
1645 }
SolverWorker * worker
Definition: subcircuit.h:117
void addCompatibleConstants(int needleConstant, int haystackConstant)
Definition: subcircuit.cc:1498

+ Here is the caller graph for this function:

void SubCircuit::Solver::addCompatibleTypes ( std::string  needleTypeId,
std::string  haystackTypeId 
)
inherited

Definition at line 1637 of file subcircuit.cc.

1638 {
1639  worker->addCompatibleTypes(needleTypeId, haystackTypeId);
1640 }
void addCompatibleTypes(std::string needleTypeId, std::string haystackTypeId)
Definition: subcircuit.cc:1493
SolverWorker * worker
Definition: subcircuit.h:117

+ Here is the caller graph for this function:

void SubCircuit::Solver::addGraph ( std::string  graphId,
const Graph graph 
)
inherited

Definition at line 1632 of file subcircuit.cc.

1633 {
1634  worker->addGraph(graphId, graph);
1635 }
void addGraph(std::string graphId, const Graph &graph)
Definition: subcircuit.cc:1483
SolverWorker * worker
Definition: subcircuit.h:117

+ Here is the caller graph for this function:

void SubCircuit::Solver::addSwappablePorts ( std::string  needleTypeId,
std::string  portId1,
std::string  portId2,
std::string  portId3 = std::string(),
std::string  portId4 = std::string() 
)
inherited

Definition at line 1647 of file subcircuit.cc.

1648 {
1649  std::set<std::string> ports;
1650  ports.insert(portId1);
1651  ports.insert(portId2);
1652  ports.insert(portId3);
1653  ports.insert(portId4);
1654  ports.erase(std::string());
1655  addSwappablePorts(needleTypeId, ports);
1656 }
void addSwappablePorts(std::string needleTypeId, std::string portId1, std::string portId2, std::string portId3=std::string(), std::string portId4=std::string())
Definition: subcircuit.cc:1647

+ Here is the caller graph for this function:

void SubCircuit::Solver::addSwappablePorts ( std::string  needleTypeId,
std::set< std::string >  ports 
)
inherited

Definition at line 1658 of file subcircuit.cc.

1659 {
1660  worker->addSwappablePorts(needleTypeId, ports);
1661 }
SolverWorker * worker
Definition: subcircuit.h:117
void addSwappablePorts(std::string needleTypeId, const std::set< std::string > &ports)
Definition: subcircuit.cc:1503
void SubCircuit::Solver::addSwappablePortsPermutation ( std::string  needleTypeId,
std::map< std::string, std::string >  portMapping 
)
inherited

Definition at line 1663 of file subcircuit.cc.

1664 {
1665  worker->addSwappablePortsPermutation(needleTypeId, portMapping);
1666 }
SolverWorker * worker
Definition: subcircuit.h:117
void addSwappablePortsPermutation(std::string needleTypeId, const std::map< std::string, std::string > &portMapping)
Definition: subcircuit.cc:1509

+ Here is the caller graph for this function:

void SubCircuit::Solver::clearConfig ( )
inherited

Definition at line 1690 of file subcircuit.cc.

1691 {
1692  worker->clearConfig();
1693 }
SolverWorker * worker
Definition: subcircuit.h:117

+ Here is the caller graph for this function:

void SubCircuit::Solver::clearOverlapHistory ( )
inherited

Definition at line 1685 of file subcircuit.cc.

1686 {
1688 }
SolverWorker * worker
Definition: subcircuit.h:117

+ Here is the caller graph for this function:

bool SubCircuitSolver::compareAttributes ( const std::set< RTLIL::IdString > &  attr,
const std::map< RTLIL::IdString, RTLIL::Const > &  needleAttr,
const std::map< RTLIL::IdString, RTLIL::Const > &  haystackAttr 
)
inline

Definition at line 45 of file extract.cc.

46  {
47  for (auto &it : attr) {
48  size_t nc = needleAttr.count(it), hc = haystackAttr.count(it);
49  if (nc != hc || (nc > 0 && needleAttr.at(it) != haystackAttr.at(it)))
50  return false;
51  }
52  return true;
53  }

+ Here is the caller graph for this function:

void SubCircuit::Solver::mine ( std::vector< MineResult > &  results,
int  minNodes,
int  maxNodes,
int  minMatches,
int  limitMatchesPerGraph = -1 
)
inherited

Definition at line 1680 of file subcircuit.cc.

1681 {
1682  worker->mine(results, minNodes, maxNodes, minMatches, limitMatchesPerGraph);
1683 }
void mine(std::vector< Solver::MineResult > &results, int minNodes, int maxNodes, int minMatches, int limitMatchesPerGraph)
Definition: subcircuit.cc:1560
SolverWorker * worker
Definition: subcircuit.h:117

+ Here is the caller graph for this function:

void SubCircuit::Solver::setVerbose ( )
inherited

Definition at line 1627 of file subcircuit.cc.

1628 {
1629  worker->setVerbose();
1630 }
SolverWorker * worker
Definition: subcircuit.h:117

+ Here is the caller graph for this function:

void SubCircuit::Solver::solve ( std::vector< Result > &  results,
std::string  needleGraphId,
std::string  haystackGraphId,
bool  allowOverlap = true,
int  maxSolutions = -1 
)
inherited

Definition at line 1668 of file subcircuit.cc.

1669 {
1670  std::map<std::string, std::set<std::string>> emptyInitialMapping;
1671  worker->solve(results, needleGraphId, haystackGraphId, emptyInitialMapping, allowOverlap, maxSolutions);
1672 }
void solve(std::vector< Solver::Result > &results, std::string needleGraphId, std::string haystackGraphId, const std::map< std::string, std::set< std::string >> &initialMappings, bool allowOverlap, int maxSolutions)
Definition: subcircuit.cc:1515
SolverWorker * worker
Definition: subcircuit.h:117

+ Here is the caller graph for this function:

void SubCircuit::Solver::solve ( std::vector< Result > &  results,
std::string  needleGraphId,
std::string  haystackGraphId,
const std::map< std::string, std::set< std::string >> &  initialMapping,
bool  allowOverlap = true,
int  maxSolutions = -1 
)
inherited

Definition at line 1674 of file subcircuit.cc.

1676 {
1677  worker->solve(results, needleGraphId, haystackGraphId, initialMappings, allowOverlap, maxSolutions);
1678 }
void solve(std::vector< Solver::Result > &results, std::string needleGraphId, std::string haystackGraphId, const std::map< std::string, std::set< std::string >> &initialMappings, bool allowOverlap, int maxSolutions)
Definition: subcircuit.cc:1515
SolverWorker * worker
Definition: subcircuit.h:117
RTLIL::Const SubCircuitSolver::unified_param ( RTLIL::IdString  cell_type,
RTLIL::IdString  param,
RTLIL::Const  value 
)
inline

Definition at line 55 of file extract.cc.

56  {
57  if (cell_type.substr(0, 1) != "$" || cell_type.substr(0, 2) == "$_")
58  return value;
59 
60  #define param_bool(_n) if (param == _n) return value.as_bool();
61  param_bool("\\ARST_POLARITY");
62  param_bool("\\A_SIGNED");
63  param_bool("\\B_SIGNED");
64  param_bool("\\CLK_ENABLE");
65  param_bool("\\CLK_POLARITY");
66  param_bool("\\CLR_POLARITY");
67  param_bool("\\EN_POLARITY");
68  param_bool("\\SET_POLARITY");
69  param_bool("\\TRANSPARENT");
70  #undef param_bool
71 
72  #define param_int(_n) if (param == _n) return value.as_int();
73  param_int("\\ABITS")
74  param_int("\\A_WIDTH")
75  param_int("\\B_WIDTH")
76  param_int("\\CTRL_IN_WIDTH")
77  param_int("\\CTRL_OUT_WIDTH")
78  param_int("\\OFFSET")
79  param_int("\\PRIORITY")
80  param_int("\\RD_PORTS")
81  param_int("\\SIZE")
82  param_int("\\STATE_BITS")
83  param_int("\\STATE_NUM")
84  param_int("\\STATE_NUM_LOG2")
85  param_int("\\STATE_RST")
86  param_int("\\S_WIDTH")
87  param_int("\\TRANS_NUM")
88  param_int("\\WIDTH")
89  param_int("\\WR_PORTS")
90  param_int("\\Y_WIDTH")
91  #undef param_int
92 
93  return value;
94  }
#define param_int(_n)
#define param_bool(_n)
std::string substr(size_t pos=0, size_t len=std::string::npos) const
Definition: rtlil.h:208

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string Solver::userAnnotateEdge ( const std::string &  graphId,
const std::string &  fromNodeId,
void *  fromUserData,
const std::string &  toNodeId,
void *  toUserData 
)
protectedvirtualinherited

Definition at line 1602 of file subcircuit.cc.

1603 {
1604  return std::string();
1605 }

+ Here is the caller graph for this function:

bool Solver::userCheckSolution ( const Result result)
protectedvirtualinherited

Definition at line 1612 of file subcircuit.cc.

1613 {
1614  return true;
1615 }

+ Here is the caller graph for this function:

bool Solver::userCompareEdge ( const std::string &  needleGraphId,
const std::string &  needleFromNodeId,
void *  needleFromUserData,
const std::string &  needleToNodeId,
void *  needleToUserData,
const std::string &  haystackGraphId,
const std::string &  haystackFromNodeId,
void *  haystackFromUserData,
const std::string &  haystackToNodeId,
void *  haystackToUserData 
)
protectedvirtualinherited

Definition at line 1607 of file subcircuit.cc.

1608 {
1609  return true;
1610 }

+ Here is the caller graph for this function:

virtual bool SubCircuitSolver::userCompareNodes ( const std::string &  ,
const std::string &  ,
void *  needleUserData,
const std::string &  ,
const std::string &  ,
void *  haystackUserData,
const std::map< std::string, std::string > &  portMapping 
)
inlinevirtual

Reimplemented from SubCircuit::Solver.

Definition at line 96 of file extract.cc.

98  {
99  RTLIL::Cell *needleCell = (RTLIL::Cell*) needleUserData;
100  RTLIL::Cell *haystackCell = (RTLIL::Cell*) haystackUserData;
101 
102  if (!needleCell || !haystackCell) {
103  log_assert(!needleCell && !haystackCell);
104  return true;
105  }
106 
107  if (!ignore_parameters) {
108  std::map<RTLIL::IdString, RTLIL::Const> needle_param, haystack_param;
109  for (auto &it : needleCell->parameters)
110  if (!ignored_parameters.count(std::pair<RTLIL::IdString, RTLIL::IdString>(needleCell->type, it.first)))
111  needle_param[it.first] = unified_param(needleCell->type, it.first, it.second);
112  for (auto &it : haystackCell->parameters)
113  if (!ignored_parameters.count(std::pair<RTLIL::IdString, RTLIL::IdString>(haystackCell->type, it.first)))
114  haystack_param[it.first] = unified_param(haystackCell->type, it.first, it.second);
115  if (needle_param != haystack_param)
116  return false;
117  }
118 
119  if (cell_attr.size() > 0 && !compareAttributes(cell_attr, needleCell->attributes, haystackCell->attributes))
120  return false;
121 
122  if (wire_attr.size() > 0)
123  {
124  RTLIL::Wire *lastNeedleWire = NULL;
125  RTLIL::Wire *lastHaystackWire = NULL;
126  std::map<RTLIL::IdString, RTLIL::Const> emptyAttr;
127 
128  for (auto &conn : needleCell->connections())
129  {
130  RTLIL::SigSpec needleSig = conn.second;
131  RTLIL::SigSpec haystackSig = haystackCell->getPort(portMapping.at(conn.first.str()));
132 
133  for (int i = 0; i < std::min(needleSig.size(), haystackSig.size()); i++) {
134  RTLIL::Wire *needleWire = needleSig[i].wire, *haystackWire = haystackSig[i].wire;
135  if (needleWire != lastNeedleWire || haystackWire != lastHaystackWire)
136  if (!compareAttributes(wire_attr, needleWire ? needleWire->attributes : emptyAttr, haystackWire ? haystackWire->attributes : emptyAttr))
137  return false;
138  lastNeedleWire = needleWire, lastHaystackWire = haystackWire;
139  }
140  }
141  }
142 
143  return true;
144  }
std::set< RTLIL::IdString > wire_attr
Definition: extract.cc:39
std::set< RTLIL::IdString > cell_attr
Definition: extract.cc:39
RTLIL::IdString type
Definition: rtlil.h:854
std::map< RTLIL::IdString, RTLIL::Const > parameters
Definition: rtlil.h:856
int size() const
Definition: rtlil.h:1019
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
RTLIL::Const unified_param(RTLIL::IdString cell_type, RTLIL::IdString param, RTLIL::Const value)
Definition: extract.cc:55
#define log_assert(_assert_expr_)
Definition: log.h:85
bool compareAttributes(const std::set< RTLIL::IdString > &attr, const std::map< RTLIL::IdString, RTLIL::Const > &needleAttr, const std::map< RTLIL::IdString, RTLIL::Const > &haystackAttr)
Definition: extract.cc:45
std::set< std::pair< RTLIL::IdString, RTLIL::IdString > > ignored_parameters
Definition: extract.cc:38
#define NULL
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const
Definition: rtlil.cc:1814
bool ignore_parameters
Definition: extract.cc:37

+ Here is the call graph for this function:

Field Documentation

std::set<RTLIL::IdString> SubCircuitSolver::cell_attr

Definition at line 39 of file extract.cc.

bool SubCircuitSolver::ignore_parameters

Definition at line 37 of file extract.cc.

std::set<std::pair<RTLIL::IdString, RTLIL::IdString> > SubCircuitSolver::ignored_parameters

Definition at line 38 of file extract.cc.

std::set<RTLIL::IdString> SubCircuitSolver::wire_attr

Definition at line 39 of file extract.cc.


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