|
29 | 29 | #include "passes/techmap/simplemap.h" |
30 | 30 | #include <stdio.h> |
31 | 31 | #include <stdlib.h> |
| 32 | +#include <optional> |
32 | 33 |
|
33 | 34 | USING_YOSYS_NAMESPACE |
34 | 35 | PRIVATE_NAMESPACE_BEGIN |
@@ -95,6 +96,18 @@ struct OptDffWorker |
95 | 96 |
|
96 | 97 | } |
97 | 98 |
|
| 99 | + // If this bit sigmaps to a bit driven by a mux ouput bit that only drives this |
| 100 | + // bit, returns that mux otherwise nullopt |
| 101 | + std::optional<cell_int_t> mergeable_mux(SigBit bit) { |
| 102 | + sigmap.apply(bit); |
| 103 | + auto it = bit2mux.find(bit); |
| 104 | + |
| 105 | + if (it == bit2mux.end() || bitusers[bit] != 1) |
| 106 | + return std::nullopt; |
| 107 | + |
| 108 | + return it->second; |
| 109 | + } |
| 110 | + |
98 | 111 | State combine_const(State a, State b) { |
99 | 112 | if (a == State::Sx && !opt.keepdc) |
100 | 113 | return b; |
@@ -591,13 +604,12 @@ struct OptDffWorker |
591 | 604 | State reset_val = State::Sx; |
592 | 605 | if (ff.has_srst) |
593 | 606 | reset_val = ff.val_srst[i]; |
594 | | - while (bit2mux.count(ff.sig_d[i]) && bitusers[ff.sig_d[i]] == 1) { |
595 | | - cell_int_t mbit = bit2mux.at(ff.sig_d[i]); |
596 | | - if (GetSize(mbit.first->getPort(ID::S)) != 1) |
| 607 | + while (const auto mbit = mergeable_mux(ff.sig_d[i])) { |
| 608 | + if (GetSize(mbit->first->getPort(ID::S)) != 1) |
597 | 609 | break; |
598 | | - SigBit s = mbit.first->getPort(ID::S); |
599 | | - SigBit a = mbit.first->getPort(ID::A)[mbit.second]; |
600 | | - SigBit b = mbit.first->getPort(ID::B)[mbit.second]; |
| 610 | + SigBit s = mbit->first->getPort(ID::S); |
| 611 | + SigBit a = mbit->first->getPort(ID::A)[mbit->second]; |
| 612 | + SigBit b = mbit->first->getPort(ID::B)[mbit->second]; |
601 | 613 | // Workaround for funny memory WE pattern. |
602 | 614 | if ((a == State::S0 || a == State::S1) && (b == State::S0 || b == State::S1)) |
603 | 615 | break; |
@@ -668,13 +680,12 @@ struct OptDffWorker |
668 | 680 | for (int i = 0 ; i < ff.width; i++) { |
669 | 681 | // First, eat up as many simple muxes as possible. |
670 | 682 | ctrls_t enables; |
671 | | - while (bit2mux.count(ff.sig_d[i]) && bitusers[ff.sig_d[i]] == 1) { |
672 | | - cell_int_t mbit = bit2mux.at(ff.sig_d[i]); |
673 | | - if (GetSize(mbit.first->getPort(ID::S)) != 1) |
| 683 | + while (const auto mbit = mergeable_mux(ff.sig_d[i])) { |
| 684 | + if (GetSize(mbit->first->getPort(ID::S)) != 1) |
674 | 685 | break; |
675 | | - SigBit s = mbit.first->getPort(ID::S); |
676 | | - SigBit a = mbit.first->getPort(ID::A)[mbit.second]; |
677 | | - SigBit b = mbit.first->getPort(ID::B)[mbit.second]; |
| 686 | + SigBit s = mbit->first->getPort(ID::S); |
| 687 | + SigBit a = mbit->first->getPort(ID::A)[mbit->second]; |
| 688 | + SigBit b = mbit->first->getPort(ID::B)[mbit->second]; |
678 | 689 | if (a == ff.sig_q[i]) { |
679 | 690 | enables.insert(ctrl_t(s, true)); |
680 | 691 | ff.sig_d[i] = b; |
|
0 commit comments