75 log(
"Running muxtree optimizier on module %s..\n", module->
name.
c_str());
77 log(
" Creating internal representation of mux trees.\n");
87 for (
auto cell : module->
cells())
89 if (cell->type ==
"$mux" || cell->type ==
"$pmux")
99 for (
int i = 0; i < sig_s.
size(); i++) {
110 portinfo.enabled =
false;
111 muxinfo.ports.push_back(portinfo);
119 portinfo.const_activated =
false;
120 portinfo.enabled =
false;
121 muxinfo.ports.push_back(portinfo);
133 for (
auto &it : cell->connections()) {
139 for (
auto wire : module->
wires()) {
140 if (wire->port_output)
146 log(
" No muxes found in this module.\n");
152 for (
size_t i = 0; i <
bit2info.size(); i++)
156 for (
int k :
bit2info[i].mux_drivers)
160 log(
" Evaluating internal representation of mux trees.\n");
162 std::set<int> root_muxes;
164 if (!bi.seen_non_mux)
166 for (
int mux_idx : bi.mux_drivers)
167 root_muxes.insert(mux_idx);
169 for (
int mux_idx : root_muxes)
172 log(
" Analyzing evaluation results.\n");
176 std::vector<int> live_ports;
177 for (
int port_idx = 0; port_idx <
GetSize(mi.ports); port_idx++) {
178 portinfo_t &pi = mi.ports[port_idx];
180 live_ports.push_back(port_idx);
182 log(
" dead port %d/%d on %s %s.\n", port_idx+1,
GetSize(mi.ports),
183 mi.cell->type.c_str(), mi.cell->name.c_str());
188 if (live_ports.size() == mi.ports.size())
191 if (live_ports.size() == 0) {
204 if (live_ports.size() == 1)
214 for (
size_t i = 0; i < live_ports.size(); i++) {
216 if (i == live_ports.size()-1) {
224 mi.cell->setPort(
"\\A", new_sig_a);
225 mi.cell->setPort(
"\\B", new_sig_b);
226 mi.cell->setPort(
"\\S", new_sig_s);
227 if (new_sig_s.
size() == 1) {
228 mi.cell->type =
"$mux";
229 mi.cell->parameters.erase(
"\\S_WIDTH");
const char * c_str() const
std::vector< bitinfo_t > bit2info
static std::string idx(std::string str)
RTLIL::ObjRange< RTLIL::Wire * > wires()
std::vector< muxinfo_t > mux2info
std::vector< int > sig2bits(RTLIL::SigSpec sig)
void add_to_list(std::vector< int > &list, int value)
void connect(const RTLIL::SigSig &conn)
int GetSize(RTLIL::Wire *wire)
bool is_fully_const() const
void eval_root_mux(int mux_idx)
RTLIL::ObjRange< RTLIL::Cell * > cells()
void remove(const std::set< RTLIL::Wire * > &wires)
SigSet< RTLIL::Cell * > mux_drivers
void log(const char *format,...)
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
void append(const RTLIL::SigSpec &signal)
bool is_in_list(const std::vector< int > &list, int value)
std::pair< SigSpec, SigSpec > SigSig