yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
share.cc
Go to the documentation of this file.
1 /*
2  * yosys -- Yosys Open SYnthesis Suite
3  *
4  * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  *
18  */
19 
20 #include "kernel/yosys.h"
21 #include "kernel/satgen.h"
22 #include "kernel/sigtools.h"
23 #include "kernel/modtools.h"
24 #include "kernel/utils.h"
25 #include "kernel/macc.h"
26 
29 
31 
33 {
34  int limit;
35  bool opt_force;
37  bool opt_fast;
39 };
40 
42 {
44  std::set<RTLIL::IdString> generic_ops;
45 
48 
52 
53  std::set<RTLIL::Cell*> cells_to_remove;
54  std::set<RTLIL::Cell*> recursion_state;
55 
57  std::map<RTLIL::Cell*, std::set<RTLIL::Cell*, cell_ptr_cmp>, cell_ptr_cmp> topo_cell_drivers;
58  std::map<RTLIL::SigBit, std::set<RTLIL::Cell*, cell_ptr_cmp>> topo_bit_drivers;
59 
60  std::vector<std::pair<RTLIL::SigBit, RTLIL::SigBit>> exclusive_ctrls;
61 
62 
63  // ------------------------------------------------------------------------------
64  // Find terminal bits -- i.e. bits that do not (exclusively) feed into a mux tree
65  // ------------------------------------------------------------------------------
66 
67  std::set<RTLIL::SigBit> terminal_bits;
68 
70  {
71  std::set<RTLIL::SigBit> queue_bits;
72  std::set<RTLIL::Cell*> visited_cells;
73 
74  queue_bits.insert(modwalker.signal_outputs.begin(), modwalker.signal_outputs.end());
75 
76  for (auto &it : module->cells_)
77  if (!fwd_ct.cell_known(it.second->type)) {
78  std::set<RTLIL::SigBit> &bits = modwalker.cell_inputs[it.second];
79  queue_bits.insert(bits.begin(), bits.end());
80  }
81 
82  terminal_bits.insert(queue_bits.begin(), queue_bits.end());
83 
84  while (!queue_bits.empty())
85  {
86  std::set<ModWalker::PortBit> portbits;
87  modwalker.get_drivers(portbits, queue_bits);
88  queue_bits.clear();
89 
90  for (auto &pbit : portbits) {
91  if (pbit.cell->type == "$mux" || pbit.cell->type == "$pmux") {
92  std::set<RTLIL::SigBit> bits = modwalker.sigmap(pbit.cell->getPort("\\S")).to_sigbit_set();
93  terminal_bits.insert(bits.begin(), bits.end());
94  queue_bits.insert(bits.begin(), bits.end());
95  visited_cells.insert(pbit.cell);
96  }
97  if (fwd_ct.cell_known(pbit.cell->type) && visited_cells.count(pbit.cell) == 0) {
98  std::set<RTLIL::SigBit> &bits = modwalker.cell_inputs[pbit.cell];
99  terminal_bits.insert(bits.begin(), bits.end());
100  queue_bits.insert(bits.begin(), bits.end());
101  visited_cells.insert(pbit.cell);
102  }
103  }
104  }
105  }
106 
107 
108  // ---------------------------------------------------
109  // Code for sharing and comparing MACC cells
110  // ---------------------------------------------------
111 
112  static int bits_macc_port(const Macc::port_t &p, int width)
113  {
114  if (GetSize(p.in_a) == 0 || GetSize(p.in_b) == 0)
115  return std::min(std::max(GetSize(p.in_a), GetSize(p.in_b)), width);
116  return std::min(GetSize(p.in_a), width) * std::min(GetSize(p.in_b), width) / 2;
117  }
118 
119  static int bits_macc(const Macc &m, int width)
120  {
121  int bits = GetSize(m.bit_ports);
122  for (auto &p : m.ports)
123  bits += bits_macc_port(p, width);
124  return bits;
125  }
126 
127  static int bits_macc(RTLIL::Cell *c)
128  {
129  Macc m(c);
130  int width = GetSize(c->getPort("\\Y"));
131  return bits_macc(m, width);
132  }
133 
134  static bool cmp_macc_ports(const Macc::port_t &p1, const Macc::port_t &p2)
135  {
136  bool mul1 = GetSize(p1.in_a) && GetSize(p1.in_b);
137  bool mul2 = GetSize(p2.in_a) && GetSize(p2.in_b);
138 
139  int w1 = mul1 ? GetSize(p1.in_a) * GetSize(p1.in_b) : GetSize(p1.in_a) + GetSize(p1.in_b);
140  int w2 = mul2 ? GetSize(p2.in_a) * GetSize(p2.in_b) : GetSize(p2.in_a) + GetSize(p2.in_b);
141 
142  if (mul1 != mul2)
143  return mul1;
144 
145  if (w1 != w2)
146  return w1 > w2;
147 
148  if (p1.is_signed != p2.is_signed)
149  return p1.is_signed < p2.is_signed;
150 
151  if (p1.do_subtract != p2.do_subtract)
152  return p1.do_subtract < p2.do_subtract;
153 
154  if (p1.in_a != p2.in_a)
155  return p1.in_a < p2.in_a;
156 
157  if (p1.in_b != p2.in_b)
158  return p1.in_b < p2.in_b;
159 
160  return false;
161  }
162 
163  int share_macc_ports(Macc::port_t &p1, Macc::port_t &p2, int w1, int w2,
164  RTLIL::SigSpec act = RTLIL::SigSpec(), Macc *supermacc = nullptr, std::set<RTLIL::Cell*> *supercell_aux = nullptr)
165  {
166  if (p1.do_subtract != p2.do_subtract)
167  return -1;
168 
169  bool mul1 = GetSize(p1.in_a) && GetSize(p1.in_b);
170  bool mul2 = GetSize(p2.in_a) && GetSize(p2.in_b);
171 
172  if (mul1 != mul2)
173  return -1;
174 
175  bool force_signed = false, force_not_signed = false;
176 
177  if ((GetSize(p1.in_a) && GetSize(p1.in_a) < w1) || (GetSize(p1.in_b) && GetSize(p1.in_b) < w1)) {
178  if (p1.is_signed)
179  force_signed = true;
180  else
181  force_not_signed = true;
182  }
183 
184  if ((GetSize(p2.in_a) && GetSize(p2.in_a) < w2) || (GetSize(p2.in_b) && GetSize(p2.in_b) < w2)) {
185  if (p2.is_signed)
186  force_signed = true;
187  else
188  force_not_signed = true;
189  }
190 
191  if (force_signed && force_not_signed)
192  return -1;
193 
194  if (supermacc)
195  {
196  RTLIL::SigSpec sig_a1 = p1.in_a, sig_b1 = p1.in_b;
197  RTLIL::SigSpec sig_a2 = p2.in_a, sig_b2 = p2.in_b;
198 
199  RTLIL::SigSpec sig_a = GetSize(sig_a1) > GetSize(sig_a2) ? sig_a1 : sig_a2;
200  RTLIL::SigSpec sig_b = GetSize(sig_b1) > GetSize(sig_b2) ? sig_b1 : sig_b2;
201 
202  sig_a1.extend_u0(GetSize(sig_a), p1.is_signed);
203  sig_b1.extend_u0(GetSize(sig_b), p1.is_signed);
204 
205  sig_a2.extend_u0(GetSize(sig_a), p2.is_signed);
206  sig_b2.extend_u0(GetSize(sig_b), p2.is_signed);
207 
208  if (supercell_aux && GetSize(sig_a)) {
209  sig_a = module->addWire(NEW_ID, GetSize(sig_a));
210  supercell_aux->insert(module->addMux(NEW_ID, sig_a2, sig_a1, act, sig_a));
211  }
212 
213  if (supercell_aux && GetSize(sig_b)) {
214  sig_b = module->addWire(NEW_ID, GetSize(sig_b));
215  supercell_aux->insert(module->addMux(NEW_ID, sig_b2, sig_b1, act, sig_b));
216  }
217 
218  Macc::port_t p;
219  p.in_a = sig_a;
220  p.in_b = sig_b;
221  p.is_signed = force_signed;
222  p.do_subtract = p1.do_subtract;
223  supermacc->ports.push_back(p);
224  }
225 
226  int score = 1000 + abs(GetSize(p1.in_a) - GetSize(p2.in_a)) * std::max(abs(GetSize(p1.in_b) - GetSize(p2.in_b)), 1);
227 
228  for (int i = 0; i < std::min(GetSize(p1.in_a), GetSize(p2.in_a)); i++)
229  if (p1.in_a[i] == p2.in_a[i] && score > 0)
230  score--;
231 
232  for (int i = 0; i < std::min(GetSize(p1.in_b), GetSize(p2.in_b)); i++)
233  if (p1.in_b[i] == p2.in_b[i] && score > 0)
234  score--;
235 
236  return score;
237  }
238 
240  RTLIL::SigSpec act = RTLIL::SigSpec(), RTLIL::Cell *supercell = nullptr, std::set<RTLIL::Cell*> *supercell_aux = nullptr)
241  {
242  Macc m1(c1), m2(c2), supermacc;
243 
244  int w1 = GetSize(c1->getPort("\\Y")), w2 = GetSize(c2->getPort("\\Y"));
245  int width = std::max(w1, w2);
246 
247  m1.optimize(w1);
248  m2.optimize(w2);
249 
250  std::sort(m1.ports.begin(), m1.ports.end(), cmp_macc_ports);
251  std::sort(m2.ports.begin(), m2.ports.end(), cmp_macc_ports);
252 
253  std::set<int> m1_unmapped, m2_unmapped;
254 
255  for (int i = 0; i < GetSize(m1.ports); i++)
256  m1_unmapped.insert(i);
257 
258  for (int i = 0; i < GetSize(m2.ports); i++)
259  m2_unmapped.insert(i);
260 
261  while (1)
262  {
263  int best_i = -1, best_j = -1, best_score = 0;
264 
265  for (int i : m1_unmapped)
266  for (int j : m2_unmapped) {
267  int score = share_macc_ports(m1.ports[i], m2.ports[j], w1, w2);
268  if (score >= 0 && (best_i < 0 || best_score > score))
269  best_i = i, best_j = j, best_score = score;
270  }
271 
272  if (best_i >= 0) {
273  m1_unmapped.erase(best_i);
274  m2_unmapped.erase(best_j);
275  share_macc_ports(m1.ports[best_i], m2.ports[best_j], w1, w2, act, &supermacc, supercell_aux);
276  } else
277  break;
278  }
279 
280  for (int i : m1_unmapped)
281  {
282  RTLIL::SigSpec sig_a = m1.ports[i].in_a;
283  RTLIL::SigSpec sig_b = m1.ports[i].in_b;
284 
285  if (supercell_aux && GetSize(sig_a)) {
286  sig_a = module->addWire(NEW_ID, GetSize(sig_a));
287  supercell_aux->insert(module->addMux(NEW_ID, RTLIL::SigSpec(0, GetSize(sig_a)), m1.ports[i].in_a, act, sig_a));
288  }
289 
290  if (supercell_aux && GetSize(sig_b)) {
291  sig_b = module->addWire(NEW_ID, GetSize(sig_b));
292  supercell_aux->insert(module->addMux(NEW_ID, RTLIL::SigSpec(0, GetSize(sig_b)), m1.ports[i].in_b, act, sig_b));
293  }
294 
295  Macc::port_t p;
296  p.in_a = sig_a;
297  p.in_b = sig_b;
298  p.is_signed = m1.ports[i].is_signed;
299  p.do_subtract = m1.ports[i].do_subtract;
300  supermacc.ports.push_back(p);
301  }
302 
303  for (int i : m2_unmapped)
304  {
305  RTLIL::SigSpec sig_a = m2.ports[i].in_a;
306  RTLIL::SigSpec sig_b = m2.ports[i].in_b;
307 
308  if (supercell_aux && GetSize(sig_a)) {
309  sig_a = module->addWire(NEW_ID, GetSize(sig_a));
310  supercell_aux->insert(module->addMux(NEW_ID, m2.ports[i].in_a, RTLIL::SigSpec(0, GetSize(sig_a)), act, sig_a));
311  }
312 
313  if (supercell_aux && GetSize(sig_b)) {
314  sig_b = module->addWire(NEW_ID, GetSize(sig_b));
315  supercell_aux->insert(module->addMux(NEW_ID, m2.ports[i].in_b, RTLIL::SigSpec(0, GetSize(sig_b)), act, sig_b));
316  }
317 
318  Macc::port_t p;
319  p.in_a = sig_a;
320  p.in_b = sig_b;
321  p.is_signed = m2.ports[i].is_signed;
322  p.do_subtract = m2.ports[i].do_subtract;
323  supermacc.ports.push_back(p);
324  }
325 
326  if (supercell)
327  {
328  RTLIL::SigSpec sig_y = module->addWire(NEW_ID, width);
329 
330  supercell_aux->insert(module->addPos(NEW_ID, sig_y, c1->getPort("\\Y")));
331  supercell_aux->insert(module->addPos(NEW_ID, sig_y, c2->getPort("\\Y")));
332 
333  supercell->setParam("\\Y_WIDTH", width);
334  supercell->setPort("\\Y", sig_y);
335 
336  supermacc.optimize(width);
337  supermacc.to_cell(supercell);
338  }
339 
340  return bits_macc(supermacc, width);
341  }
342 
343 
344  // ---------------------------------------------------
345  // Find shareable cells and compatible groups of cells
346  // ---------------------------------------------------
347 
348  std::set<RTLIL::Cell*, RTLIL::sort_by_name_str<RTLIL::Cell>> shareable_cells;
349 
351  {
352  for (auto cell : module->cells())
353  {
354  if (!design->selected(module, cell) || !modwalker.ct.cell_known(cell->type))
355  continue;
356 
357  for (auto &bit : modwalker.cell_outputs[cell])
358  if (terminal_bits.count(bit))
359  goto not_a_muxed_cell;
360 
361  if (0)
362  not_a_muxed_cell:
363  continue;
364 
365  if (config.opt_force) {
366  shareable_cells.insert(cell);
367  continue;
368  }
369 
370  if (cell->type == "$memrd") {
371  if (!cell->parameters.at("\\CLK_ENABLE").as_bool())
372  shareable_cells.insert(cell);
373  continue;
374  }
375 
376  if (cell->type == "$mul" || cell->type == "$div" || cell->type == "$mod") {
377  if (config.opt_aggressive || cell->parameters.at("\\Y_WIDTH").as_int() >= 4)
378  shareable_cells.insert(cell);
379  continue;
380  }
381 
382  if (cell->type == "$shl" || cell->type == "$shr" || cell->type == "$sshl" || cell->type == "$sshr") {
383  if (config.opt_aggressive || cell->parameters.at("\\Y_WIDTH").as_int() >= 8)
384  shareable_cells.insert(cell);
385  continue;
386  }
387 
388  if (generic_ops.count(cell->type)) {
389  if (config.opt_aggressive || cell->parameters.at("\\Y_WIDTH").as_int() >= 10)
390  shareable_cells.insert(cell);
391  continue;
392  }
393  }
394  }
395 
397  {
398  if (c1->type != c2->type)
399  return false;
400 
401  if (c1->type == "$memrd")
402  {
403  if (c1->parameters.at("\\MEMID").decode_string() != c2->parameters.at("\\MEMID").decode_string())
404  return false;
405 
406  return true;
407  }
408 
409  if (config.generic_uni_ops.count(c1->type))
410  {
411  if (!config.opt_aggressive)
412  {
413  int a1_width = c1->parameters.at("\\A_WIDTH").as_int();
414  int y1_width = c1->parameters.at("\\Y_WIDTH").as_int();
415 
416  int a2_width = c2->parameters.at("\\A_WIDTH").as_int();
417  int y2_width = c2->parameters.at("\\Y_WIDTH").as_int();
418 
419  if (std::max(a1_width, a2_width) > 2 * std::min(a1_width, a2_width)) return false;
420  if (std::max(y1_width, y2_width) > 2 * std::min(y1_width, y2_width)) return false;
421  }
422 
423  return true;
424  }
425 
426  if (config.generic_bin_ops.count(c1->type) || c1->type == "$alu")
427  {
428  if (!config.opt_aggressive)
429  {
430  int a1_width = c1->parameters.at("\\A_WIDTH").as_int();
431  int b1_width = c1->parameters.at("\\B_WIDTH").as_int();
432  int y1_width = c1->parameters.at("\\Y_WIDTH").as_int();
433 
434  int a2_width = c2->parameters.at("\\A_WIDTH").as_int();
435  int b2_width = c2->parameters.at("\\B_WIDTH").as_int();
436  int y2_width = c2->parameters.at("\\Y_WIDTH").as_int();
437 
438  if (std::max(a1_width, a2_width) > 2 * std::min(a1_width, a2_width)) return false;
439  if (std::max(b1_width, b2_width) > 2 * std::min(b1_width, b2_width)) return false;
440  if (std::max(y1_width, y2_width) > 2 * std::min(y1_width, y2_width)) return false;
441  }
442 
443  return true;
444  }
445 
446  if (config.generic_cbin_ops.count(c1->type))
447  {
448  if (!config.opt_aggressive)
449  {
450  int a1_width = c1->parameters.at("\\A_WIDTH").as_int();
451  int b1_width = c1->parameters.at("\\B_WIDTH").as_int();
452  int y1_width = c1->parameters.at("\\Y_WIDTH").as_int();
453 
454  int a2_width = c2->parameters.at("\\A_WIDTH").as_int();
455  int b2_width = c2->parameters.at("\\B_WIDTH").as_int();
456  int y2_width = c2->parameters.at("\\Y_WIDTH").as_int();
457 
458  int min1_width = std::min(a1_width, b1_width);
459  int max1_width = std::max(a1_width, b1_width);
460 
461  int min2_width = std::min(a2_width, b2_width);
462  int max2_width = std::max(a2_width, b2_width);
463 
464  if (std::max(min1_width, min2_width) > 2 * std::min(min1_width, min2_width)) return false;
465  if (std::max(max1_width, max2_width) > 2 * std::min(max1_width, max2_width)) return false;
466  if (std::max(y1_width, y2_width) > 2 * std::min(y1_width, y2_width)) return false;
467  }
468 
469  return true;
470  }
471 
472  if (c1->type == "$macc")
473  {
474  if (!config.opt_aggressive)
475  if (share_macc(c1, c2) > 2 * std::min(bits_macc(c1), bits_macc(c2))) return false;
476 
477  return true;
478  }
479 
480  for (auto &it : c1->parameters)
481  if (c2->parameters.count(it.first) == 0 || c2->parameters.at(it.first) != it.second)
482  return false;
483 
484  for (auto &it : c2->parameters)
485  if (c1->parameters.count(it.first) == 0 || c1->parameters.at(it.first) != it.second)
486  return false;
487 
488  return true;
489  }
490 
491  void find_shareable_partners(std::vector<RTLIL::Cell*> &results, RTLIL::Cell *cell)
492  {
493  results.clear();
494  for (auto c : shareable_cells)
495  if (c != cell && is_shareable_pair(c, cell))
496  results.push_back(c);
497  }
498 
499 
500  // -----------------------
501  // Create replacement cell
502  // -----------------------
503 
504  RTLIL::Cell *make_supercell(RTLIL::Cell *c1, RTLIL::Cell *c2, RTLIL::SigSpec act, std::set<RTLIL::Cell*> &supercell_aux)
505  {
506  log_assert(c1->type == c2->type);
507 
508  if (config.generic_uni_ops.count(c1->type))
509  {
510  if (c1->parameters.at("\\A_SIGNED").as_bool() != c2->parameters.at("\\A_SIGNED").as_bool())
511  {
512  RTLIL::Cell *unsigned_cell = c1->parameters.at("\\A_SIGNED").as_bool() ? c2 : c1;
513  if (unsigned_cell->getPort("\\A").to_sigbit_vector().back() != RTLIL::State::S0) {
514  unsigned_cell->parameters.at("\\A_WIDTH") = unsigned_cell->parameters.at("\\A_WIDTH").as_int() + 1;
515  RTLIL::SigSpec new_a = unsigned_cell->getPort("\\A");
517  unsigned_cell->setPort("\\A", new_a);
518  }
519  unsigned_cell->parameters.at("\\A_SIGNED") = true;
520  unsigned_cell->check();
521  }
522 
523  bool a_signed = c1->parameters.at("\\A_SIGNED").as_bool();
524  log_assert(a_signed == c2->parameters.at("\\A_SIGNED").as_bool());
525 
526  RTLIL::SigSpec a1 = c1->getPort("\\A");
527  RTLIL::SigSpec y1 = c1->getPort("\\Y");
528 
529  RTLIL::SigSpec a2 = c2->getPort("\\A");
530  RTLIL::SigSpec y2 = c2->getPort("\\Y");
531 
532  int a_width = std::max(a1.size(), a2.size());
533  int y_width = std::max(y1.size(), y2.size());
534 
535  a1.extend_u0(a_width, a_signed);
536  a2.extend_u0(a_width, a_signed);
537 
538  RTLIL::SigSpec a = module->addWire(NEW_ID, a_width);
539  supercell_aux.insert(module->addMux(NEW_ID, a2, a1, act, a));
540 
541  RTLIL::Wire *y = module->addWire(NEW_ID, y_width);
542 
543  RTLIL::Cell *supercell = module->addCell(NEW_ID, c1->type);
544  supercell->parameters["\\A_SIGNED"] = a_signed;
545  supercell->parameters["\\A_WIDTH"] = a_width;
546  supercell->parameters["\\Y_WIDTH"] = y_width;
547  supercell->setPort("\\A", a);
548  supercell->setPort("\\Y", y);
549 
550  supercell_aux.insert(module->addPos(NEW_ID, y, y1));
551  supercell_aux.insert(module->addPos(NEW_ID, y, y2));
552 
553  supercell_aux.insert(supercell);
554  return supercell;
555  }
556 
557  if (config.generic_bin_ops.count(c1->type) || config.generic_cbin_ops.count(c1->type) || c1->type == "$alu")
558  {
559  bool modified_src_cells = false;
560 
561  if (config.generic_cbin_ops.count(c1->type))
562  {
563  int score_unflipped = std::max(c1->parameters.at("\\A_WIDTH").as_int(), c2->parameters.at("\\A_WIDTH").as_int()) +
564  std::max(c1->parameters.at("\\B_WIDTH").as_int(), c2->parameters.at("\\B_WIDTH").as_int());
565 
566  int score_flipped = std::max(c1->parameters.at("\\A_WIDTH").as_int(), c2->parameters.at("\\B_WIDTH").as_int()) +
567  std::max(c1->parameters.at("\\B_WIDTH").as_int(), c2->parameters.at("\\A_WIDTH").as_int());
568 
569  if (score_flipped < score_unflipped)
570  {
571  RTLIL::SigSpec tmp = c2->getPort("\\A");
572  c2->setPort("\\A", c2->getPort("\\B"));
573  c2->setPort("\\B", tmp);
574 
575  std::swap(c2->parameters.at("\\A_WIDTH"), c2->parameters.at("\\B_WIDTH"));
576  std::swap(c2->parameters.at("\\A_SIGNED"), c2->parameters.at("\\B_SIGNED"));
577  modified_src_cells = true;
578  }
579  }
580 
581  if (c1->parameters.at("\\A_SIGNED").as_bool() != c2->parameters.at("\\A_SIGNED").as_bool())
582 
583  {
584  RTLIL::Cell *unsigned_cell = c1->parameters.at("\\A_SIGNED").as_bool() ? c2 : c1;
585  if (unsigned_cell->getPort("\\A").to_sigbit_vector().back() != RTLIL::State::S0) {
586  unsigned_cell->parameters.at("\\A_WIDTH") = unsigned_cell->parameters.at("\\A_WIDTH").as_int() + 1;
587  RTLIL::SigSpec new_a = unsigned_cell->getPort("\\A");
589  unsigned_cell->setPort("\\A", new_a);
590  }
591  unsigned_cell->parameters.at("\\A_SIGNED") = true;
592  modified_src_cells = true;
593  }
594 
595  if (c1->parameters.at("\\B_SIGNED").as_bool() != c2->parameters.at("\\B_SIGNED").as_bool())
596  {
597  RTLIL::Cell *unsigned_cell = c1->parameters.at("\\B_SIGNED").as_bool() ? c2 : c1;
598  if (unsigned_cell->getPort("\\B").to_sigbit_vector().back() != RTLIL::State::S0) {
599  unsigned_cell->parameters.at("\\B_WIDTH") = unsigned_cell->parameters.at("\\B_WIDTH").as_int() + 1;
600  RTLIL::SigSpec new_b = unsigned_cell->getPort("\\B");
602  unsigned_cell->setPort("\\B", new_b);
603  }
604  unsigned_cell->parameters.at("\\B_SIGNED") = true;
605  modified_src_cells = true;
606  }
607 
608  if (modified_src_cells) {
609  c1->check();
610  c2->check();
611  }
612 
613  bool a_signed = c1->parameters.at("\\A_SIGNED").as_bool();
614  bool b_signed = c1->parameters.at("\\B_SIGNED").as_bool();
615 
616  log_assert(a_signed == c2->parameters.at("\\A_SIGNED").as_bool());
617  log_assert(b_signed == c2->parameters.at("\\B_SIGNED").as_bool());
618 
619  if (c1->type == "$shl" || c1->type == "$shr" || c1->type == "$sshl" || c1->type == "$sshr")
620  b_signed = false;
621 
622  RTLIL::SigSpec a1 = c1->getPort("\\A");
623  RTLIL::SigSpec b1 = c1->getPort("\\B");
624  RTLIL::SigSpec y1 = c1->getPort("\\Y");
625 
626  RTLIL::SigSpec a2 = c2->getPort("\\A");
627  RTLIL::SigSpec b2 = c2->getPort("\\B");
628  RTLIL::SigSpec y2 = c2->getPort("\\Y");
629 
630  int a_width = std::max(a1.size(), a2.size());
631  int b_width = std::max(b1.size(), b2.size());
632  int y_width = std::max(y1.size(), y2.size());
633 
634  if (c1->type == "$shr" && a_signed)
635  {
636  a_width = std::max(y_width, a_width);
637 
638  if (a1.size() < y1.size()) a1.extend_u0(y1.size(), true);
639  if (a2.size() < y2.size()) a2.extend_u0(y2.size(), true);
640 
641  a1.extend_u0(a_width, false);
642  a2.extend_u0(a_width, false);
643  }
644  else
645  {
646  a1.extend_u0(a_width, a_signed);
647  a2.extend_u0(a_width, a_signed);
648  }
649 
650  b1.extend_u0(b_width, b_signed);
651  b2.extend_u0(b_width, b_signed);
652 
653  RTLIL::SigSpec a = module->addWire(NEW_ID, a_width);
654  RTLIL::SigSpec b = module->addWire(NEW_ID, b_width);
655 
656  supercell_aux.insert(module->addMux(NEW_ID, a2, a1, act, a));
657  supercell_aux.insert(module->addMux(NEW_ID, b2, b1, act, b));
658 
659  RTLIL::Wire *y = module->addWire(NEW_ID, y_width);
660  RTLIL::Wire *x = c1->type == "$alu" ? module->addWire(NEW_ID, y_width) : nullptr;
661  RTLIL::Wire *co = c1->type == "$alu" ? module->addWire(NEW_ID, y_width) : nullptr;
662 
663  RTLIL::Cell *supercell = module->addCell(NEW_ID, c1->type);
664  supercell->parameters["\\A_SIGNED"] = a_signed;
665  supercell->parameters["\\B_SIGNED"] = b_signed;
666  supercell->parameters["\\A_WIDTH"] = a_width;
667  supercell->parameters["\\B_WIDTH"] = b_width;
668  supercell->parameters["\\Y_WIDTH"] = y_width;
669  supercell->setPort("\\A", a);
670  supercell->setPort("\\B", b);
671  supercell->setPort("\\Y", y);
672  if (c1->type == "$alu") {
674  supercell_aux.insert(module->addMux(NEW_ID, c2->getPort("\\CI"), c1->getPort("\\CI"), act, ci));
675  supercell_aux.insert(module->addMux(NEW_ID, c2->getPort("\\BI"), c1->getPort("\\BI"), act, bi));
676  supercell->setPort("\\CI", ci);
677  supercell->setPort("\\BI", bi);
678  supercell->setPort("\\CO", co);
679  supercell->setPort("\\X", x);
680  }
681  supercell->check();
682 
683  supercell_aux.insert(module->addPos(NEW_ID, y, y1));
684  supercell_aux.insert(module->addPos(NEW_ID, y, y2));
685  if (c1->type == "$alu") {
686  supercell_aux.insert(module->addPos(NEW_ID, co, c1->getPort("\\CO")));
687  supercell_aux.insert(module->addPos(NEW_ID, co, c2->getPort("\\CO")));
688  supercell_aux.insert(module->addPos(NEW_ID, x, c1->getPort("\\X")));
689  supercell_aux.insert(module->addPos(NEW_ID, x, c2->getPort("\\X")));
690  }
691 
692  supercell_aux.insert(supercell);
693  return supercell;
694  }
695 
696  if (c1->type == "$macc")
697  {
698  RTLIL::Cell *supercell = module->addCell(NEW_ID, c1->type);
699  supercell_aux.insert(supercell);
700  share_macc(c1, c2, act, supercell, &supercell_aux);
701  supercell->check();
702  return supercell;
703  }
704 
705  if (c1->type == "$memrd")
706  {
707  RTLIL::Cell *supercell = module->addCell(NEW_ID, c1);
708  supercell_aux.insert(module->addPos(NEW_ID, supercell->getPort("\\DATA"), c2->getPort("\\DATA")));
709  supercell_aux.insert(supercell);
710  return supercell;
711  }
712 
713  log_abort();
714  }
715 
716 
717  // -------------------------------------------
718  // Finding forbidden control inputs for a cell
719  // -------------------------------------------
720 
721  std::map<RTLIL::Cell*, std::set<RTLIL::SigBit>> forbidden_controls_cache;
722 
723  const std::set<RTLIL::SigBit> &find_forbidden_controls(RTLIL::Cell *cell)
724  {
725  if (recursion_state.count(cell)) {
726  static std::set<RTLIL::SigBit> empty_controls_set;
727  return empty_controls_set;
728  }
729 
730  if (forbidden_controls_cache.count(cell))
731  return forbidden_controls_cache.at(cell);
732 
733  std::set<ModWalker::PortBit> pbits;
734  std::set<RTLIL::Cell*> consumer_cells;
735 
737 
738  for (auto &bit : pbits) {
739  if ((bit.cell->type == "$mux" || bit.cell->type == "$pmux") && bit.port == "\\S")
740  forbidden_controls_cache[cell].insert(bit.cell->getPort("\\S").extract(bit.offset, 1));
741  consumer_cells.insert(bit.cell);
742  }
743 
744  recursion_state.insert(cell);
745 
746  for (auto c : consumer_cells)
747  if (fwd_ct.cell_known(c->type)) {
748  const std::set<RTLIL::SigBit> &bits = find_forbidden_controls(c);
749  forbidden_controls_cache[cell].insert(bits.begin(), bits.end());
750  }
751 
752  log_assert(recursion_state.count(cell) != 0);
753  recursion_state.erase(cell);
754 
755  return forbidden_controls_cache[cell];
756  }
757 
758 
759  // --------------------------------------------------------
760  // Finding control inputs and activation pattern for a cell
761  // --------------------------------------------------------
762 
763  std::map<RTLIL::Cell*, std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>>> activation_patterns_cache;
764 
765  bool sort_check_activation_pattern(std::pair<RTLIL::SigSpec, RTLIL::Const> &p)
766  {
767  std::map<RTLIL::SigBit, RTLIL::State> p_bits;
768 
769  std::vector<RTLIL::SigBit> p_first_bits = p.first;
770  for (int i = 0; i < GetSize(p_first_bits); i++) {
771  RTLIL::SigBit b = p_first_bits[i];
772  RTLIL::State v = p.second.bits[i];
773  if (p_bits.count(b) && p_bits.at(b) != v)
774  return false;
775  p_bits[b] = v;
776  }
777 
778  p.first = RTLIL::SigSpec();
779  p.second.bits.clear();
780 
781  for (auto &it : p_bits) {
782  p.first.append_bit(it.first);
783  p.second.bits.push_back(it.second);
784  }
785 
786  return true;
787  }
788 
789  void optimize_activation_patterns(std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> & /* patterns */)
790  {
791  // TODO: Remove patterns that are contained in other patterns
792  // TODO: Consolidate pairs of patterns that only differ in the value for one signal bit
793  }
794 
795  const std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> &find_cell_activation_patterns(RTLIL::Cell *cell, const char *indent)
796  {
797  if (recursion_state.count(cell)) {
798  static std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> empty_patterns_set;
799  return empty_patterns_set;
800  }
801 
802  if (activation_patterns_cache.count(cell))
803  return activation_patterns_cache.at(cell);
804 
805  const std::set<RTLIL::SigBit> &cell_out_bits = modwalker.cell_outputs[cell];
806  std::set<RTLIL::Cell*> driven_cells, driven_data_muxes;
807 
808  for (auto &bit : cell_out_bits)
809  {
810  if (terminal_bits.count(bit)) {
811  // Terminal cells are always active: unconditional activation pattern
812  activation_patterns_cache[cell].insert(std::pair<RTLIL::SigSpec, RTLIL::Const>());
813  return activation_patterns_cache.at(cell);
814  }
815  for (auto &pbit : modwalker.signal_consumers[bit]) {
816  log_assert(fwd_ct.cell_known(pbit.cell->type));
817  if ((pbit.cell->type == "$mux" || pbit.cell->type == "$pmux") && (pbit.port == "\\A" || pbit.port == "\\B"))
818  driven_data_muxes.insert(pbit.cell);
819  else
820  driven_cells.insert(pbit.cell);
821  }
822  }
823 
824  recursion_state.insert(cell);
825 
826  for (auto c : driven_data_muxes)
827  {
828  const std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> &c_patterns = find_cell_activation_patterns(c, indent);
829 
830  bool used_in_a = false;
831  std::set<int> used_in_b_parts;
832 
833  int width = c->parameters.at("\\WIDTH").as_int();
834  std::vector<RTLIL::SigBit> sig_a = modwalker.sigmap(c->getPort("\\A"));
835  std::vector<RTLIL::SigBit> sig_b = modwalker.sigmap(c->getPort("\\B"));
836  std::vector<RTLIL::SigBit> sig_s = modwalker.sigmap(c->getPort("\\S"));
837 
838  for (auto &bit : sig_a)
839  if (cell_out_bits.count(bit))
840  used_in_a = true;
841 
842  for (int i = 0; i < GetSize(sig_b); i++)
843  if (cell_out_bits.count(sig_b[i]))
844  used_in_b_parts.insert(i / width);
845 
846  if (used_in_a)
847  for (auto p : c_patterns) {
848  for (int i = 0; i < GetSize(sig_s); i++)
849  p.first.append_bit(sig_s[i]), p.second.bits.push_back(RTLIL::State::S0);
851  activation_patterns_cache[cell].insert(p);
852  }
853 
854  for (int idx : used_in_b_parts)
855  for (auto p : c_patterns) {
856  p.first.append_bit(sig_s[idx]), p.second.bits.push_back(RTLIL::State::S1);
858  activation_patterns_cache[cell].insert(p);
859  }
860  }
861 
862  for (auto c : driven_cells) {
863  const std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> &c_patterns = find_cell_activation_patterns(c, indent);
864  activation_patterns_cache[cell].insert(c_patterns.begin(), c_patterns.end());
865  }
866 
867  log_assert(recursion_state.count(cell) != 0);
868  recursion_state.erase(cell);
869 
871  if (activation_patterns_cache[cell].empty()) {
872  log("%sFound cell that is never activated: %s\n", indent, log_id(cell));
873  RTLIL::SigSpec cell_outputs = modwalker.cell_outputs[cell];
874  module->connect(RTLIL::SigSig(cell_outputs, RTLIL::SigSpec(RTLIL::State::Sx, cell_outputs.size())));
875  cells_to_remove.insert(cell);
876  }
877 
878  return activation_patterns_cache[cell];
879  }
880 
881  RTLIL::SigSpec bits_from_activation_patterns(const std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> &activation_patterns)
882  {
883  std::set<RTLIL::SigBit> all_bits;
884  for (auto &it : activation_patterns) {
885  std::vector<RTLIL::SigBit> bits = it.first;
886  all_bits.insert(bits.begin(), bits.end());
887  }
888 
889  RTLIL::SigSpec signal;
890  for (auto &bit : all_bits)
891  signal.append_bit(bit);
892 
893  return signal;
894  }
895 
896  void filter_activation_patterns(std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> &out,
897  const std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> &in, const std::set<RTLIL::SigBit> &filter_bits)
898  {
899  for (auto &p : in)
900  {
901  std::vector<RTLIL::SigBit> p_first = p.first;
902  std::pair<RTLIL::SigSpec, RTLIL::Const> new_p;
903 
904  for (int i = 0; i < GetSize(p_first); i++)
905  if (filter_bits.count(p_first[i]) == 0) {
906  new_p.first.append_bit(p_first[i]);
907  new_p.second.bits.push_back(p.second.bits.at(i));
908  }
909 
910  out.insert(new_p);
911  }
912  }
913 
914  RTLIL::SigSpec make_cell_activation_logic(const std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> &activation_patterns, std::set<RTLIL::Cell*> &supercell_aux)
915  {
916  RTLIL::Wire *all_cases_wire = module->addWire(NEW_ID, 0);
917 
918  for (auto &p : activation_patterns) {
919  all_cases_wire->width++;
920  supercell_aux.insert(module->addEq(NEW_ID, p.first, p.second, RTLIL::SigSpec(all_cases_wire, all_cases_wire->width - 1)));
921  }
922 
923  if (all_cases_wire->width == 1)
924  return all_cases_wire;
925 
926  RTLIL::Wire *result_wire = module->addWire(NEW_ID);
927  supercell_aux.insert(module->addReduceOr(NEW_ID, all_cases_wire, result_wire));
928  return result_wire;
929  }
930 
931 
932  // -------------------------------------------------------------------------------------
933  // Helper functions used to make sure that this pass does not introduce new logic loops.
934  // -------------------------------------------------------------------------------------
935 
937  {
938  CellTypes ct;
939  ct.setup_internals();
940  ct.setup_stdcells();
941 
943  toposort.analyze_loops = false;
944 
946  topo_bit_drivers.clear();
947 
948  std::map<RTLIL::Cell*, std::set<RTLIL::SigBit>> cell_to_bits;
949  std::map<RTLIL::SigBit, std::set<RTLIL::Cell*>> bit_to_cells;
950 
951  for (auto cell : module->cells())
952  if (ct.cell_known(cell->type))
953  for (auto &conn : cell->connections()) {
954  if (ct.cell_output(cell->type, conn.first))
955  for (auto bit : topo_sigmap(conn.second)) {
956  cell_to_bits[cell].insert(bit);
957  topo_bit_drivers[bit].insert(cell);
958  }
959  else
960  for (auto bit : topo_sigmap(conn.second))
961  bit_to_cells[bit].insert(cell);
962  }
963 
964  for (auto &it : cell_to_bits)
965  {
966  RTLIL::Cell *c1 = it.first;
967 
968  for (auto bit : it.second)
969  for (auto c2 : bit_to_cells[bit])
970  toposort.edge(c1, c2);
971  }
972 
973  bool found_scc = !toposort.sort();
974  topo_cell_drivers = std::move(toposort.database);
975 
976  if (found_scc && toposort.analyze_loops)
977  for (auto &loop : toposort.loops) {
978  log("### loop ###\n");
979  for (auto &c : loop)
980  log("%s (%s)\n", log_id(c), log_id(c->type));
981  }
982 
983  return found_scc;
984  }
985 
986  bool find_in_input_cone_worker(RTLIL::Cell *root, RTLIL::Cell *needle, std::set<RTLIL::Cell*> &stop)
987  {
988  if (root == needle)
989  return true;
990 
991  if (stop.count(root))
992  return false;
993 
994  stop.insert(root);
995 
996  for (auto c : topo_cell_drivers[root])
997  if (find_in_input_cone_worker(c, needle, stop))
998  return true;
999  return false;
1000  }
1001 
1003  {
1004  std::set<RTLIL::Cell*> stop;
1005  return find_in_input_cone_worker(root, needle, stop);
1006  }
1007 
1009  {
1010  CellTypes ct;
1011  ct.setup_internals();
1012  ct.setup_stdcells();
1013 
1014  std::set<RTLIL::Cell*> queue, covered;
1015  queue.insert(cell);
1016 
1017  while (!queue.empty())
1018  {
1019  std::set<RTLIL::Cell*> new_queue;
1020 
1021  for (auto c : queue) {
1022  if (!ct.cell_known(c->type))
1023  continue;
1024  for (auto &conn : c->connections())
1025  if (ct.cell_input(c->type, conn.first))
1026  for (auto bit : conn.second)
1027  for (auto &pi : mi.query_ports(bit))
1028  if (ct.cell_known(pi.cell->type) && ct.cell_output(pi.cell->type, pi.port))
1029  new_queue.insert(pi.cell);
1030  covered.insert(c);
1031  }
1032 
1033  queue.clear();
1034  for (auto c : new_queue) {
1035  if (cells_to_remove.count(c))
1036  continue;
1037  if (c == cell)
1038  return true;
1039  if (!covered.count(c))
1040  queue.insert(c);
1041  }
1042  }
1043 
1044  return false;
1045  }
1046 
1047 
1048  // -------------
1049  // Setup and run
1050  // -------------
1051 
1053  config(config), design(design), module(module), mi(module)
1054  {
1055  bool before_scc = module_has_scc();
1056 
1057  generic_ops.insert(config.generic_uni_ops.begin(), config.generic_uni_ops.end());
1058  generic_ops.insert(config.generic_bin_ops.begin(), config.generic_bin_ops.end());
1059  generic_ops.insert(config.generic_cbin_ops.begin(), config.generic_cbin_ops.end());
1060  generic_ops.insert(config.generic_other_ops.begin(), config.generic_other_ops.end());
1061 
1063 
1065  cone_ct.cell_types.erase("$mul");
1066  cone_ct.cell_types.erase("$mod");
1067  cone_ct.cell_types.erase("$div");
1068  cone_ct.cell_types.erase("$pow");
1069  cone_ct.cell_types.erase("$shl");
1070  cone_ct.cell_types.erase("$shr");
1071  cone_ct.cell_types.erase("$sshl");
1072  cone_ct.cell_types.erase("$sshr");
1073 
1074  modwalker.setup(design, module);
1075 
1078 
1079  if (shareable_cells.size() < 2)
1080  return;
1081 
1082  log("Found %d cells in module %s that may be considered for resource sharing.\n",
1083  GetSize(shareable_cells), log_id(module));
1084 
1085  for (auto cell : module->cells())
1086  if (cell->type == "$pmux")
1087  for (auto bit : cell->getPort("\\S"))
1088  for (auto other_bit : cell->getPort("\\S"))
1089  if (bit < other_bit)
1090  exclusive_ctrls.push_back(std::pair<RTLIL::SigBit, RTLIL::SigBit>(bit, other_bit));
1091 
1092  while (!shareable_cells.empty() && config.limit != 0)
1093  {
1094  RTLIL::Cell *cell = *shareable_cells.begin();
1095  shareable_cells.erase(cell);
1096 
1097  log(" Analyzing resource sharing options for %s:\n", log_id(cell));
1098 
1099  const std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> &cell_activation_patterns = find_cell_activation_patterns(cell, " ");
1100  RTLIL::SigSpec cell_activation_signals = bits_from_activation_patterns(cell_activation_patterns);
1101 
1102  if (cell_activation_patterns.empty()) {
1103  log(" Cell is never active. Sharing is pointless, we simply remove it.\n");
1104  cells_to_remove.insert(cell);
1105  continue;
1106  }
1107 
1108  if (cell_activation_patterns.count(std::pair<RTLIL::SigSpec, RTLIL::Const>())) {
1109  log(" Cell is always active. Therefore no sharing is possible.\n");
1110  continue;
1111  }
1112 
1113  log(" Found %d activation_patterns using ctrl signal %s.\n", GetSize(cell_activation_patterns), log_signal(cell_activation_signals));
1114 
1115  std::vector<RTLIL::Cell*> candidates;
1116  find_shareable_partners(candidates, cell);
1117 
1118  if (candidates.empty()) {
1119  log(" No candidates found.\n");
1120  continue;
1121  }
1122 
1123  log(" Found %d candidates:", GetSize(candidates));
1124  for (auto c : candidates)
1125  log(" %s", log_id(c));
1126  log("\n");
1127 
1128  for (auto other_cell : candidates)
1129  {
1130  log(" Analyzing resource sharing with %s:\n", log_id(other_cell));
1131 
1132  const std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> &other_cell_activation_patterns = find_cell_activation_patterns(other_cell, " ");
1133  RTLIL::SigSpec other_cell_activation_signals = bits_from_activation_patterns(other_cell_activation_patterns);
1134 
1135  if (other_cell_activation_patterns.empty()) {
1136  log(" Cell is never active. Sharing is pointless, we simply remove it.\n");
1137  shareable_cells.erase(other_cell);
1138  cells_to_remove.insert(other_cell);
1139  continue;
1140  }
1141 
1142  if (other_cell_activation_patterns.count(std::pair<RTLIL::SigSpec, RTLIL::Const>())) {
1143  log(" Cell is always active. Therefore no sharing is possible.\n");
1144  shareable_cells.erase(other_cell);
1145  continue;
1146  }
1147 
1148  log(" Found %d activation_patterns using ctrl signal %s.\n",
1149  GetSize(other_cell_activation_patterns), log_signal(other_cell_activation_signals));
1150 
1151  const std::set<RTLIL::SigBit> &cell_forbidden_controls = find_forbidden_controls(cell);
1152  const std::set<RTLIL::SigBit> &other_cell_forbidden_controls = find_forbidden_controls(other_cell);
1153 
1154  std::set<RTLIL::SigBit> union_forbidden_controls;
1155  union_forbidden_controls.insert(cell_forbidden_controls.begin(), cell_forbidden_controls.end());
1156  union_forbidden_controls.insert(other_cell_forbidden_controls.begin(), other_cell_forbidden_controls.end());
1157 
1158  if (!union_forbidden_controls.empty())
1159  log(" Forbidden control signals for this pair of cells: %s\n", log_signal(union_forbidden_controls));
1160 
1161  std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> filtered_cell_activation_patterns;
1162  std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> filtered_other_cell_activation_patterns;
1163 
1164  filter_activation_patterns(filtered_cell_activation_patterns, cell_activation_patterns, union_forbidden_controls);
1165  filter_activation_patterns(filtered_other_cell_activation_patterns, other_cell_activation_patterns, union_forbidden_controls);
1166 
1167  optimize_activation_patterns(filtered_cell_activation_patterns);
1168  optimize_activation_patterns(filtered_other_cell_activation_patterns);
1169 
1170  ezDefaultSAT ez;
1171  SatGen satgen(&ez, &modwalker.sigmap);
1172 
1173  std::set<RTLIL::Cell*> sat_cells;
1174  std::set<RTLIL::SigBit> bits_queue;
1175 
1176  std::vector<int> cell_active, other_cell_active;
1177  RTLIL::SigSpec all_ctrl_signals;
1178 
1179  for (auto &p : filtered_cell_activation_patterns) {
1180  log(" Activation pattern for cell %s: %s = %s\n", log_id(cell), log_signal(p.first), log_signal(p.second));
1181  cell_active.push_back(ez.vec_eq(satgen.importSigSpec(p.first), satgen.importSigSpec(p.second)));
1182  all_ctrl_signals.append(p.first);
1183  }
1184 
1185  for (auto &p : filtered_other_cell_activation_patterns) {
1186  log(" Activation pattern for cell %s: %s = %s\n", log_id(other_cell), log_signal(p.first), log_signal(p.second));
1187  other_cell_active.push_back(ez.vec_eq(satgen.importSigSpec(p.first), satgen.importSigSpec(p.second)));
1188  all_ctrl_signals.append(p.first);
1189  }
1190 
1191  for (auto &bit : cell_activation_signals.to_sigbit_vector())
1192  bits_queue.insert(bit);
1193 
1194  for (auto &bit : other_cell_activation_signals.to_sigbit_vector())
1195  bits_queue.insert(bit);
1196 
1197  while (!bits_queue.empty())
1198  {
1199  std::set<ModWalker::PortBit> portbits;
1200  modwalker.get_drivers(portbits, bits_queue);
1201  bits_queue.clear();
1202 
1203  for (auto &pbit : portbits)
1204  if (sat_cells.count(pbit.cell) == 0 && cone_ct.cell_known(pbit.cell->type)) {
1205  if (config.opt_fast && modwalker.cell_outputs[pbit.cell].size() >= 4)
1206  continue;
1207  // log(" Adding cell %s (%s) to SAT problem.\n", log_id(pbit.cell), log_id(pbit.cell->type));
1208  bits_queue.insert(modwalker.cell_inputs[pbit.cell].begin(), modwalker.cell_inputs[pbit.cell].end());
1209  satgen.importCell(pbit.cell);
1210  sat_cells.insert(pbit.cell);
1211  }
1212 
1213  if (config.opt_fast && sat_cells.size() > 100)
1214  break;
1215  }
1216 
1217  for (auto it : exclusive_ctrls)
1218  if (satgen.importedSigBit(it.first) && satgen.importedSigBit(it.second)) {
1219  log(" Adding exclusive control bits: %s vs. %s\n", log_signal(it.first), log_signal(it.second));
1220  ez.assume(ez.NOT(ez.AND(satgen.importSigBit(it.first), satgen.importSigBit(it.second))));
1221  }
1222 
1223  if (!ez.solve(ez.expression(ez.OpOr, cell_active))) {
1224  log(" According to the SAT solver the cell %s is never active. Sharing is pointless, we simply remove it.\n", log_id(cell));
1225  cells_to_remove.insert(cell);
1226  break;
1227  }
1228 
1229  if (!ez.solve(ez.expression(ez.OpOr, other_cell_active))) {
1230  log(" According to the SAT solver the cell %s is never active. Sharing is pointless, we simply remove it.\n", log_id(other_cell));
1231  cells_to_remove.insert(other_cell);
1232  shareable_cells.erase(other_cell);
1233  continue;
1234  }
1235 
1236  ez.non_incremental();
1237 
1238  all_ctrl_signals.sort_and_unify();
1239  std::vector<int> sat_model = satgen.importSigSpec(all_ctrl_signals);
1240  std::vector<bool> sat_model_values;
1241 
1242  ez.assume(ez.AND(ez.expression(ez.OpOr, cell_active), ez.expression(ez.OpOr, other_cell_active)));
1243 
1244  log(" Size of SAT problem: %d cells, %d variables, %d clauses\n",
1245  GetSize(sat_cells), ez.numCnfVariables(), ez.numCnfClauses());
1246 
1247  if (ez.solve(sat_model, sat_model_values)) {
1248  log(" According to the SAT solver this pair of cells can not be shared.\n");
1249  log(" Model from SAT solver: %s = %d'", log_signal(all_ctrl_signals), GetSize(sat_model_values));
1250  for (int i = GetSize(sat_model_values)-1; i >= 0; i--)
1251  log("%c", sat_model_values[i] ? '1' : '0');
1252  log("\n");
1253  continue;
1254  }
1255 
1256  log(" According to the SAT solver this pair of cells can be shared.\n");
1257 
1258  if (find_in_input_cone(cell, other_cell)) {
1259  log(" Sharing not possible: %s is in input cone of %s.\n", log_id(other_cell), log_id(cell));
1260  continue;
1261  }
1262 
1263  if (find_in_input_cone(other_cell, cell)) {
1264  log(" Sharing not possible: %s is in input cone of %s.\n", log_id(cell), log_id(other_cell));
1265  continue;
1266  }
1267 
1268  shareable_cells.erase(other_cell);
1269 
1270  int cell_select_score = 0;
1271  int other_cell_select_score = 0;
1272 
1273  for (auto &p : filtered_cell_activation_patterns)
1274  cell_select_score += p.first.size();
1275 
1276  for (auto &p : filtered_other_cell_activation_patterns)
1277  other_cell_select_score += p.first.size();
1278 
1279  RTLIL::Cell *supercell;
1280  std::set<RTLIL::Cell*> supercell_aux;
1281  if (cell_select_score <= other_cell_select_score) {
1282  RTLIL::SigSpec act = make_cell_activation_logic(filtered_cell_activation_patterns, supercell_aux);
1283  supercell = make_supercell(cell, other_cell, act, supercell_aux);
1284  log(" Activation signal for %s: %s\n", log_id(cell), log_signal(act));
1285  } else {
1286  RTLIL::SigSpec act = make_cell_activation_logic(filtered_other_cell_activation_patterns, supercell_aux);
1287  supercell = make_supercell(other_cell, cell, act, supercell_aux);
1288  log(" Activation signal for %s: %s\n", log_id(other_cell), log_signal(act));
1289  }
1290 
1291  log(" New cell: %s (%s)\n", log_id(supercell), log_id(supercell->type));
1292 
1293  cells_to_remove.insert(cell);
1294  cells_to_remove.insert(other_cell);
1295 
1296  for (auto c : supercell_aux)
1297  if (is_part_of_scc(c))
1298  goto do_rollback;
1299 
1300  if (0) {
1301  do_rollback:
1302  log(" New topology contains loops! Rolling back..\n");
1303  cells_to_remove.erase(cell);
1304  cells_to_remove.erase(other_cell);
1305  shareable_cells.insert(other_cell);
1306  for (auto cc : supercell_aux)
1307  module->remove(cc);
1308  continue;
1309  }
1310 
1311  std::set<std::pair<RTLIL::SigSpec, RTLIL::Const>> supercell_activation_patterns;
1312  supercell_activation_patterns.insert(filtered_cell_activation_patterns.begin(), filtered_cell_activation_patterns.end());
1313  supercell_activation_patterns.insert(filtered_other_cell_activation_patterns.begin(), filtered_other_cell_activation_patterns.end());
1314  optimize_activation_patterns(supercell_activation_patterns);
1315  activation_patterns_cache[supercell] = supercell_activation_patterns;
1316  shareable_cells.insert(supercell);
1317 
1318  for (auto bit : topo_sigmap(all_ctrl_signals))
1319  for (auto c : topo_bit_drivers[bit])
1320  topo_cell_drivers[supercell].insert(c);
1321 
1322  topo_cell_drivers[supercell].insert(topo_cell_drivers[cell].begin(), topo_cell_drivers[cell].end());
1323  topo_cell_drivers[supercell].insert(topo_cell_drivers[other_cell].begin(), topo_cell_drivers[other_cell].end());
1324 
1325  topo_cell_drivers[cell] = { supercell };
1326  topo_cell_drivers[other_cell] = { supercell };
1327 
1328  if (config.limit > 0)
1329  config.limit--;
1330 
1331  break;
1332  }
1333  }
1334 
1335  if (!cells_to_remove.empty()) {
1336  log("Removing %d cells in module %s:\n", GetSize(cells_to_remove), log_id(module));
1337  for (auto c : cells_to_remove) {
1338  log(" Removing cell %s (%s).\n", log_id(c), log_id(c->type));
1339  module->remove(c);
1340  }
1341  }
1342 
1343  log_assert(recursion_state.empty());
1344 
1345  bool after_scc = before_scc || module_has_scc();
1346  log_assert(before_scc == after_scc);
1347  }
1348 };
1349 
1350 struct SharePass : public Pass {
1351  SharePass() : Pass("share", "perform sat-based resource sharing") { }
1352  virtual void help()
1353  {
1354  // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
1355  log("\n");
1356  log(" share [options] [selection]\n");
1357  log("\n");
1358  log("This pass merges shareable resources into a single resource. A SAT solver\n");
1359  log("is used to determine if two resources are share-able.\n");
1360  log("\n");
1361  log(" -force\n");
1362  log(" Per default the selection of cells that is considered for sharing is\n");
1363  log(" narrowed using a list of cell types. With this option all selected\n");
1364  log(" cells are considered for resource sharing.\n");
1365  log("\n");
1366  log(" IMPORTANT NOTE: If the -all option is used then no cells with internal\n");
1367  log(" state must be selected!\n");
1368  log("\n");
1369  log(" -aggressive\n");
1370  log(" Per default some heuristics are used to reduce the number of cells\n");
1371  log(" considered for resource sharing to only large resources. This options\n");
1372  log(" turns this heuristics off, resulting in much more cells being considered\n");
1373  log(" for resource sharing.\n");
1374  log("\n");
1375  log(" -fast\n");
1376  log(" Only consider the simple part of the control logic in SAT solving, resulting\n");
1377  log(" in much easier SAT problems at the cost of maybe missing some oportunities\n");
1378  log(" for resource sharing.\n");
1379  log("\n");
1380  log(" -limit N\n");
1381  log(" Only perform the first N merges, then stop. This is useful for debugging.\n");
1382  log("\n");
1383  }
1384  virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
1385  {
1386  ShareWorkerConfig config;
1387 
1388  config.limit = -1;
1389  config.opt_force = false;
1390  config.opt_aggressive = false;
1391  config.opt_fast = false;
1392 
1393  config.generic_uni_ops.insert("$not");
1394  // config.generic_uni_ops.insert("$pos");
1395  config.generic_uni_ops.insert("$neg");
1396 
1397  config.generic_cbin_ops.insert("$and");
1398  config.generic_cbin_ops.insert("$or");
1399  config.generic_cbin_ops.insert("$xor");
1400  config.generic_cbin_ops.insert("$xnor");
1401 
1402  config.generic_bin_ops.insert("$shl");
1403  config.generic_bin_ops.insert("$shr");
1404  config.generic_bin_ops.insert("$sshl");
1405  config.generic_bin_ops.insert("$sshr");
1406 
1407  config.generic_bin_ops.insert("$lt");
1408  config.generic_bin_ops.insert("$le");
1409  config.generic_bin_ops.insert("$eq");
1410  config.generic_bin_ops.insert("$ne");
1411  config.generic_bin_ops.insert("$eqx");
1412  config.generic_bin_ops.insert("$nex");
1413  config.generic_bin_ops.insert("$ge");
1414  config.generic_bin_ops.insert("$gt");
1415 
1416  config.generic_cbin_ops.insert("$add");
1417  config.generic_cbin_ops.insert("$mul");
1418 
1419  config.generic_bin_ops.insert("$sub");
1420  config.generic_bin_ops.insert("$div");
1421  config.generic_bin_ops.insert("$mod");
1422  // config.generic_bin_ops.insert("$pow");
1423 
1424  config.generic_uni_ops.insert("$logic_not");
1425  config.generic_cbin_ops.insert("$logic_and");
1426  config.generic_cbin_ops.insert("$logic_or");
1427 
1428  config.generic_other_ops.insert("$alu");
1429  config.generic_other_ops.insert("$macc");
1430 
1431  log_header("Executing SHARE pass (SAT-based resource sharing).\n");
1432 
1433  size_t argidx;
1434  for (argidx = 1; argidx < args.size(); argidx++) {
1435  if (args[argidx] == "-force") {
1436  config.opt_force = true;
1437  continue;
1438  }
1439  if (args[argidx] == "-aggressive") {
1440  config.opt_aggressive = true;
1441  continue;
1442  }
1443  if (args[argidx] == "-fast") {
1444  config.opt_fast = true;
1445  continue;
1446  }
1447  if (args[argidx] == "-limit" && argidx+1 < args.size()) {
1448  config.limit = atoi(args[++argidx].c_str());
1449  continue;
1450  }
1451  break;
1452  }
1453  extra_args(args, argidx, design);
1454 
1455  for (auto &mod_it : design->modules_)
1456  if (design->selected(mod_it.second))
1457  ShareWorker(config, design, mod_it.second);
1458  }
1459 } SharePass;
1460 
void to_cell(RTLIL::Cell *cell) const
Definition: macc.h:152
std::map< RTLIL::SigBit, std::set< PortBit > > signal_consumers
Definition: modtools.h:205
bool selected(T1 *module) const
Definition: rtlil.h:551
bool find_in_input_cone(RTLIL::Cell *root, RTLIL::Cell *needle)
Definition: share.cc:1002
void find_terminal_bits()
Definition: share.cc:69
bool is_shareable_pair(RTLIL::Cell *c1, RTLIL::Cell *c2)
Definition: share.cc:396
std::map< RTLIL::Cell *, std::set< RTLIL::SigBit > > cell_outputs
Definition: modtools.h:208
void find_shareable_cells()
Definition: share.cc:350
std::map< bitDef_t, shared_bit_data_t * > bits
Definition: sigtools.h:224
std::set< RTLIL::SigBit > signal_outputs
Definition: modtools.h:206
RTLIL::SigSpec bit_ports
Definition: macc.h:35
void setup_stdcells()
Definition: celltypes.h:132
void sort(T *array, int size, LessThan lt)
Definition: Sort.h:57
Definition: macc.h:27
std::set< std::set< T, C > > loops
Definition: utils.h:136
bool sort()
Definition: utils.h:194
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
RTLIL::Design * design
Definition: share.cc:46
ShareWorkerConfig config
Definition: share.cc:43
void log_header(const char *format,...)
Definition: log.cc:188
CellTypes ct
Definition: opt_clean.cc:33
std::set< RTLIL::SigBit > terminal_bits
Definition: share.cc:67
static int bits_macc(const Macc &m, int width)
Definition: share.cc:119
SigMap sigmap
Definition: modtools.h:202
std::map< RTLIL::Cell *, std::set< RTLIL::Cell *, cell_ptr_cmp >, cell_ptr_cmp > topo_cell_drivers
Definition: share.cc:57
std::set< RTLIL::IdString > generic_other_ops
Definition: share.cc:38
int importSigBit(RTLIL::SigBit bit, int timestep=-1)
Definition: satgen.h:99
bool is_part_of_scc(RTLIL::Cell *cell)
Definition: share.cc:1008
const char * log_signal(const RTLIL::SigSpec &sig, bool autoint)
Definition: log.cc:269
ezMiniSAT ez
Definition: puzzle3d.cc:31
static std::string idx(std::string str)
Definition: test_autotb.cc:57
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
int width
Definition: rtlil.h:826
RTLIL::Cell * addEq(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed=false)
std::vector< int > importSigSpec(RTLIL::SigSpec sig, int timestep=-1)
Definition: satgen.h:78
std::vector< port_t > ports
Definition: macc.h:34
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN typedef RTLIL::IdString::compare_ptr_by_name< RTLIL::Cell > cell_ptr_cmp
Definition: share.cc:30
RTLIL::IdString type
Definition: rtlil.h:854
std::map< RTLIL::IdString, RTLIL::Const > parameters
Definition: rtlil.h:856
void extend_u0(int width, bool is_signed=false)
Definition: rtlil.cc:2612
std::set< RTLIL::IdString > generic_uni_ops
Definition: share.cc:38
void optimize(int width)
Definition: macc.h:37
int size() const
Definition: rtlil.h:1019
#define log_abort()
Definition: log.h:84
std::set< RTLIL::Cell * > recursion_state
Definition: share.cc:54
bool get_drivers(std::set< PortBit > &result, RTLIL::SigBit bit) const
Definition: modtools.h:289
SharePass()
Definition: share.cc:1351
RTLIL::Cell * addReduceOr(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed=false)
static int bits_macc_port(const Macc::port_t &p, int width)
Definition: share.cc:112
ShareWorker(ShareWorkerConfig config, RTLIL::Design *design, RTLIL::Module *module)
Definition: share.cc:1052
const std::set< std::pair< RTLIL::SigSpec, RTLIL::Const > > & find_cell_activation_patterns(RTLIL::Cell *cell, const char *indent)
Definition: share.cc:795
RTLIL::SigSpec in_b
Definition: macc.h:30
void filter_activation_patterns(std::set< std::pair< RTLIL::SigSpec, RTLIL::Const >> &out, const std::set< std::pair< RTLIL::SigSpec, RTLIL::Const >> &in, const std::set< RTLIL::SigBit > &filter_bits)
Definition: share.cc:896
YOSYS_NAMESPACE_BEGIN typedef ezMiniSAT ezDefaultSAT
Definition: satgen.h:32
bool get_consumers(std::set< PortBit > &result, RTLIL::SigBit bit) const
Definition: modtools.h:301
std::map< RTLIL::IdString, CellType > cell_types
Definition: celltypes.h:36
RTLIL::Module * module
Definition: share.cc:47
void set(RTLIL::Module *module)
Definition: sigtools.h:273
bool cell_known(RTLIL::IdString type)
Definition: celltypes.h:188
void connect(const RTLIL::SigSig &conn)
Definition: rtlil.cc:1278
void append_bit(const RTLIL::SigBit &bit)
Definition: rtlil.cc:2562
bool importedSigBit(RTLIL::SigBit bit, int timestep=-1)
Definition: satgen.h:106
static bool cmp_macc_ports(const Macc::port_t &p1, const Macc::port_t &p2)
Definition: share.cc:134
#define PRIVATE_NAMESPACE_BEGIN
Definition: yosys.h:97
bool opt_aggressive
Definition: share.cc:36
ModIndex mi
Definition: share.cc:51
bool cell_output(RTLIL::IdString type, RTLIL::IdString port)
Definition: celltypes.h:193
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
void edge(T left, T right)
Definition: utils.h:151
std::map< RTLIL::SigBit, std::set< RTLIL::Cell *, cell_ptr_cmp > > topo_bit_drivers
Definition: share.cc:58
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
#define log_assert(_assert_expr_)
Definition: log.h:85
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
Definition: rtlil.cc:1331
SigMap topo_sigmap
Definition: share.cc:56
#define NEW_ID
Definition: yosys.h:166
std::map< T, std::set< T, C >, C > database
Definition: utils.h:135
std::map< RTLIL::Cell *, std::set< RTLIL::SigBit > > cell_inputs
Definition: modtools.h:208
bool is_signed
Definition: macc.h:31
CellTypes fwd_ct
Definition: share.cc:49
#define PRIVATE_NAMESPACE_END
Definition: yosys.h:98
std::map< RTLIL::Cell *, std::set< std::pair< RTLIL::SigSpec, RTLIL::Const > > > activation_patterns_cache
Definition: share.cc:763
Definition: satgen.h:34
Definition: register.h:27
ModWalker modwalker
Definition: share.cc:50
static int bits_macc(RTLIL::Cell *c)
Definition: share.cc:127
std::map< RTLIL::Cell *, std::set< RTLIL::SigBit > > forbidden_controls_cache
Definition: share.cc:721
void optimize_activation_patterns(std::set< std::pair< RTLIL::SigSpec, RTLIL::Const >> &)
Definition: share.cc:789
std::set< RTLIL::IdString > generic_cbin_ops
Definition: share.cc:38
void check()
Definition: rtlil.cc:1839
#define USING_YOSYS_NAMESPACE
Definition: yosys.h:102
RTLIL::ObjRange< RTLIL::Cell * > cells()
Definition: rtlil.h:641
std::set< RTLIL::Cell *, RTLIL::sort_by_name_str< RTLIL::Cell > > shareable_cells
Definition: share.cc:348
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507
void sort_and_unify()
Definition: rtlil.cc:2291
RTLIL::SigSpec in_a
Definition: macc.h:30
void setup(RTLIL::Design *design, RTLIL::Module *module, CellTypes *filter_ct=NULL)
Definition: modtools.h:265
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
Definition: rtlil.h:596
void remove(const std::set< RTLIL::Wire * > &wires)
Definition: rtlil.cc:1158
bool analyze_loops
Definition: utils.h:134
std::set< RTLIL::Cell * > cells_to_remove
Definition: share.cc:53
int share_macc(RTLIL::Cell *c1, RTLIL::Cell *c2, RTLIL::SigSpec act=RTLIL::SigSpec(), RTLIL::Cell *supercell=nullptr, std::set< RTLIL::Cell * > *supercell_aux=nullptr)
Definition: share.cc:239
int share_macc_ports(Macc::port_t &p1, Macc::port_t &p2, int w1, int w2, RTLIL::SigSpec act=RTLIL::SigSpec(), Macc *supermacc=nullptr, std::set< RTLIL::Cell * > *supercell_aux=nullptr)
Definition: share.cc:163
RTLIL::Cell * addMux(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s, RTLIL::SigSpec sig_y)
void log(const char *format,...)
Definition: log.cc:180
RTLIL::SigSpec bits_from_activation_patterns(const std::set< std::pair< RTLIL::SigSpec, RTLIL::Const >> &activation_patterns)
Definition: share.cc:881
void setup_internals()
Definition: celltypes.h:83
bool importCell(RTLIL::Cell *cell, int timestep=-1)
Definition: satgen.h:203
RTLIL::SigSpec make_cell_activation_logic(const std::set< std::pair< RTLIL::SigSpec, RTLIL::Const >> &activation_patterns, std::set< RTLIL::Cell * > &supercell_aux)
Definition: share.cc:914
bool module_has_scc()
Definition: share.cc:936
CellTypes ct
Definition: modtools.h:201
void append(const RTLIL::SigSpec &signal)
Definition: rtlil.cc:2523
RTLIL::Cell * make_supercell(RTLIL::Cell *c1, RTLIL::Cell *c2, RTLIL::SigSpec act, std::set< RTLIL::Cell * > &supercell_aux)
Definition: share.cc:504
State
Definition: rtlil.h:29
CellTypes cone_ct
Definition: share.cc:49
bool cell_input(RTLIL::IdString type, RTLIL::IdString port)
Definition: celltypes.h:199
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
Definition: share.cc:1384
RTLIL::Cell * addPos(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed=false)
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
Definition: register.cc:128
bool opt_force
Definition: share.cc:35
void find_shareable_partners(std::vector< RTLIL::Cell * > &results, RTLIL::Cell *cell)
Definition: share.cc:491
std::pair< SigSpec, SigSpec > SigSig
Definition: rtlil.h:71
bool do_subtract
Definition: macc.h:31
const char * log_id(RTLIL::IdString str)
Definition: log.cc:283
SharePass SharePass
std::vector< std::pair< RTLIL::SigBit, RTLIL::SigBit > > exclusive_ctrls
Definition: share.cc:60
std::vector< RTLIL::SigBit > to_sigbit_vector() const
Definition: rtlil.cc:2921
std::set< RTLIL::IdString > generic_ops
Definition: share.cc:44
virtual void help()
Definition: share.cc:1352
std::set< PortInfo > & query_ports(RTLIL::SigBit bit)
Definition: modtools.h:171
const std::set< RTLIL::SigBit > & find_forbidden_controls(RTLIL::Cell *cell)
Definition: share.cc:723
bool sort_check_activation_pattern(std::pair< RTLIL::SigSpec, RTLIL::Const > &p)
Definition: share.cc:765
std::set< RTLIL::IdString > generic_bin_ops
Definition: share.cc:38
bool find_in_input_cone_worker(RTLIL::Cell *root, RTLIL::Cell *needle, std::set< RTLIL::Cell * > &stop)
Definition: share.cc:986