37 if (dff->
type ==
"$_DFF_N_" || dff->
type ==
"$_DFF_P_") {
44 (dff->
type[6] ==
'N' || dff->
type[6] ==
'P') &&
45 (dff->
type[7] ==
'N' || dff->
type[7] ==
'P') &&
46 (dff->
type[8] ==
'0' || dff->
type[8] ==
'1')) {
55 else if (dff->
type ==
"$dff") {
61 else if (dff->
type ==
"$adff") {
73 assign_map.
apply(sig_d);
74 assign_map.
apply(sig_q);
75 assign_map.
apply(sig_c);
76 assign_map.
apply(sig_r);
78 bool has_init =
false;
80 for (
auto bit :
dff_init_map(sig_q).to_sigbit_vector()) {
86 if (dff->
type ==
"$dff" && mux_drivers.
has(sig_d) && !has_init) {
87 std::set<RTLIL::Cell*> muxes;
88 mux_drivers.
find(sig_d, muxes);
89 for (
auto mux : muxes) {
106 if (val_rv.
bits.size() == 0)
131 if (sig_d == sig_q && !(sig_r.
size() && has_init)) {
157 log(
" opt_rmdff [selection]\n");
159 log(
"This pass identifies flip-flops with constant inputs and replaces them with\n");
160 log(
"a constant driver.\n");
166 log_header(
"Executing OPT_RMDFF pass (remove dff with constant values).\n");
170 for (
auto &mod_it : design->
modules_)
172 if (!design->
selected(mod_it.second))
175 assign_map.
set(mod_it.second);
176 dff_init_map.
set(mod_it.second);
177 for (
auto &it : mod_it.second->wires_)
178 if (it.second->attributes.count(
"\\init") != 0)
179 dff_init_map.
add(it.second, it.second->attributes.at(
"\\init"));
182 std::vector<RTLIL::IdString> dff_list;
183 for (
auto &it : mod_it.second->cells_) {
184 if (it.second->type ==
"$mux" || it.second->type ==
"$pmux") {
185 if (it.second->getPort(
"\\A").size() == it.second->getPort(
"\\B").size())
186 mux_drivers.
insert(assign_map(it.second->getPort(
"\\Y")), it.second);
189 if (!design->
selected(mod_it.second, it.second))
191 if (it.second->type ==
"$_DFF_N_") dff_list.push_back(it.first);
192 if (it.second->type ==
"$_DFF_P_") dff_list.push_back(it.first);
193 if (it.second->type ==
"$_DFF_NN0_") dff_list.push_back(it.first);
194 if (it.second->type ==
"$_DFF_NN1_") dff_list.push_back(it.first);
195 if (it.second->type ==
"$_DFF_NP0_") dff_list.push_back(it.first);
196 if (it.second->type ==
"$_DFF_NP1_") dff_list.push_back(it.first);
197 if (it.second->type ==
"$_DFF_PN0_") dff_list.push_back(it.first);
198 if (it.second->type ==
"$_DFF_PN1_") dff_list.push_back(it.first);
199 if (it.second->type ==
"$_DFF_PP0_") dff_list.push_back(it.first);
200 if (it.second->type ==
"$_DFF_PP1_") dff_list.push_back(it.first);
201 if (it.second->type ==
"$dff") dff_list.push_back(it.first);
202 if (it.second->type ==
"$adff") dff_list.push_back(it.first);
205 for (
auto &
id : dff_list) {
206 if (mod_it.second->cells_.count(
id) > 0 &&
207 handle_dff(mod_it.second, mod_it.second->cells_[
id]))
217 log(
"Replaced %d DFF cells.\n", total_count);
const char * c_str() const
bool selected(T1 *module) const
bool is_fully_undef() const
bool has(RTLIL::SigSpec sig)
void log_header(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Const > parameters
void apply(RTLIL::SigBit &bit) const
void set(RTLIL::Module *module)
void connect(const RTLIL::SigSig &conn)
#define PRIVATE_NAMESPACE_BEGIN
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
bool is_fully_const() const
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN SigMap dff_init_map
#define PRIVATE_NAMESPACE_END
std::string substr(size_t pos=0, size_t len=std::string::npos) const
#define USING_YOSYS_NAMESPACE
std::map< RTLIL::IdString, RTLIL::Module * > modules_
bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
void remove(const std::set< RTLIL::Wire * > &wires)
SigSet< RTLIL::Cell * > mux_drivers
void log(const char *format,...)
void scratchpad_set_bool(std::string varname, bool value)
std::vector< RTLIL::State > bits
void add(RTLIL::SigSpec from, RTLIL::SigSpec to)
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
std::pair< SigSpec, SigSpec > SigSig
void find(RTLIL::SigSpec sig, std::set< T > &result)
void insert(RTLIL::SigSpec sig, T data)
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
OptRmdffPass OptRmdffPass
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN SigMap assign_map