153 for (
auto &it : module->
cells_) {
158 register_signals.
add(it2.second);
160 connected_signals.
add(it2.second);
164 std::set<RTLIL::SigSpec> direct_sigs;
165 std::set<RTLIL::Wire*> direct_wires;
166 for (
auto &it : module->
cells_) {
173 for (
auto &it : module->
wires_) {
174 if (direct_sigs.count(
assign_map(it.second)) || it.second->port_input)
175 direct_wires.insert(it.second);
178 for (
auto &it : module->
wires_) {
180 for (
int i = 0; i < wire->
width; i++) {
182 if (!
compare_signals(s1, s2, register_signals, connected_signals, direct_wires))
190 SigPool used_signals_nodrivers;
191 for (
auto &it : module->
cells_) {
195 used_signals.
add(it2.second);
197 used_signals_nodrivers.
add(it2.second);
200 for (
auto &it : module->
wires_) {
205 used_signals.
add(sig);
207 used_signals_nodrivers.
add(sig);
209 if (wire->get_bool_attribute(
"\\keep")) {
212 used_signals.
add(sig);
216 std::vector<RTLIL::Wire*> maybe_del_wires;
217 for (
auto wire : module->
wires())
222 if (!used_signals.
check_any(s2) && wire->
port_id == 0 && !wire->get_bool_attribute(
"\\keep")) {
223 maybe_del_wires.push_back(wire);
227 for (
int i = 0; i <
GetSize(s1); i++)
228 if (s1[i] != s2[i]) {
229 new_conn.first.append_bit(s1[i]);
230 new_conn.second.append_bit(s2[i]);
232 if (new_conn.first.size() > 0) {
233 used_signals.
add(new_conn.first);
234 used_signals.
add(new_conn.second);
240 maybe_del_wires.push_back(wire);
244 if (!used_signals_nodrivers.
check_any(sig)) {
245 std::string unused_bits;
246 for (
int i = 0; i <
GetSize(sig); i++) {
247 if (sig[i].wire ==
NULL)
249 if (!used_signals_nodrivers.
check(sig[i])) {
250 if (!unused_bits.empty())
252 unused_bits +=
stringf(
"%d", i);
255 if (unused_bits.empty() || wire->
port_id != 0)
256 wire->attributes.erase(
"\\unused_bits");
258 wire->attributes[
"\\unused_bits"] =
RTLIL::Const(unused_bits);
260 wire->attributes.erase(
"\\unused_bits");
265 std::set<RTLIL::Wire*> del_wires;
267 int del_wires_count = 0;
268 for (
auto wire : maybe_del_wires)
271 log(
" removing unused non-port wire %s.\n", wire->
name.
c_str());
274 del_wires.insert(wire);
277 module->
remove(del_wires);
280 if (del_wires_count > 0)
281 log(
" removed %d unused temporary wires.\n", del_wires_count);
const char * c_str() const
std::string stringf(const char *fmt,...)
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
bool compare_signals(RTLIL::SigBit &s1, RTLIL::SigBit &s2, SigPool ®s, SigPool &conns, std::set< RTLIL::Wire * > &direct_wires)
RTLIL::ObjRange< RTLIL::Wire * > wires()
std::vector< RTLIL::SigSig > connections_
void apply(RTLIL::SigBit &bit) const
bool check_public_name(RTLIL::IdString id)
bool cell_known(RTLIL::IdString type)
bool check_any(RTLIL::SigSpec sig)
void connect(const RTLIL::SigSig &conn)
bool cell_output(RTLIL::IdString type, RTLIL::IdString port)
int GetSize(RTLIL::Wire *wire)
#define log_assert(_assert_expr_)
void add(RTLIL::SigSpec sig)
bool check(RTLIL::SigBit bit)
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
void remove(const std::set< RTLIL::Wire * > &wires)
void log(const char *format,...)
void add(RTLIL::SigSpec from, RTLIL::SigSpec to)
std::map< RTLIL::IdString, RTLIL::SigSpec > connections_
std::pair< SigSpec, SigSpec > SigSig
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const