Added opt_rmdff support for $ff cells
authorClifford Wolf <clifford@clifford.at>
Fri, 14 Oct 2016 11:02:36 +0000 (13:02 +0200)
committerClifford Wolf <clifford@clifford.at>
Fri, 14 Oct 2016 11:02:36 +0000 (13:02 +0200)
passes/opt/opt_rmdff.cc

index 7e87d1adcffbb72225cecad68278a949e122fa3c..922f086f10ccd60351d51c5ec84f41948e75374f 100644 (file)
@@ -72,7 +72,11 @@ bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
        RTLIL::SigSpec sig_d, sig_q, sig_c, sig_r;
        RTLIL::Const val_cp, val_rp, val_rv;
 
-       if (dff->type == "$_DFF_N_" || dff->type == "$_DFF_P_") {
+       if (dff->type == "$_FF_") {
+               sig_d = dff->getPort("\\D");
+               sig_q = dff->getPort("\\Q");
+       }
+       else if (dff->type == "$_DFF_N_" || dff->type == "$_DFF_P_") {
                sig_d = dff->getPort("\\D");
                sig_q = dff->getPort("\\Q");
                sig_c = dff->getPort("\\C");
@@ -90,6 +94,10 @@ bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
                val_rp = RTLIL::Const(dff->type[7] == 'P', 1);
                val_rv = RTLIL::Const(dff->type[8] == '1', 1);
        }
+       else if (dff->type == "$ff") {
+               sig_d = dff->getPort("\\D");
+               sig_q = dff->getPort("\\Q");
+       }
        else if (dff->type == "$dff") {
                sig_d = dff->getPort("\\D");
                sig_q = dff->getPort("\\Q");
@@ -121,7 +129,7 @@ bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
                val_init.bits.push_back(bit.wire == NULL ? bit.data : RTLIL::State::Sx);
        }
 
-       if (dff->type == "$dff" && mux_drivers.has(sig_d)) {
+       if (dff->type.in("$ff", "$dff") && mux_drivers.has(sig_d)) {
                std::set<RTLIL::Cell*> muxes;
                mux_drivers.find(sig_d, muxes);
                for (auto mux : muxes) {
@@ -138,7 +146,7 @@ bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
                }
        }
 
-       if (sig_c.is_fully_const() && (!sig_r.size() || !has_init || val_init == val_rv)) {
+       if (!sig_c.empty() && sig_c.is_fully_const() && (!sig_r.size() || !has_init || val_init == val_rv)) {
                if (val_rv.bits.size() == 0)
                        val_rv = val_init;
                mod->connect(sig_q, val_rv);
@@ -254,10 +262,10 @@ struct OptRmdffPass : public Pass {
                                if (!design->selected(module, cell))
                                        continue;
 
-                               if (cell->type.in("$_DFF_N_", "$_DFF_P_",
+                               if (cell->type.in("$_FF_", "$_DFF_N_", "$_DFF_P_",
                                                "$_DFF_NN0_", "$_DFF_NN1_", "$_DFF_NP0_", "$_DFF_NP1_",
                                                "$_DFF_PN0_", "$_DFF_PN1_", "$_DFF_PP0_", "$_DFF_PP1_",
-                                               "$dff", "$adff"))
+                                               "$ff", "$dff", "$adff"))
                                        dff_list.push_back(cell->name);
 
                                if (cell->type == "$dlatch")