Added "opt_rmdff -keepdc"
authorClifford Wolf <clifford@clifford.at>
Fri, 30 Sep 2016 15:02:38 +0000 (17:02 +0200)
committerClifford Wolf <clifford@clifford.at>
Fri, 30 Sep 2016 15:02:38 +0000 (17:02 +0200)
passes/opt/opt.cc
passes/opt/opt_rmdff.cc

index 13ea5469bba700c36634ebbbb4d82db2cb5dacc6..021c1a03f0292cf7f9b64aad0bd655b701c2bac7 100644 (file)
@@ -44,7 +44,7 @@ struct OptPass : public Pass {
                log("        opt_muxtree\n");
                log("        opt_reduce [-fine] [-full]\n");
                log("        opt_merge [-share_all]\n");
-               log("        opt_rmdff\n");
+               log("        opt_rmdff [-keepdc]\n");
                log("        opt_clean [-purge]\n");
                log("        opt_expr [-mux_undef] [-mux_bool] [-undriven] [-clkinv] [-fine] [-full] [-keepdc]\n");
                log("    while <changed design>\n");
@@ -54,7 +54,7 @@ struct OptPass : public Pass {
                log("    do\n");
                log("        opt_expr [-mux_undef] [-mux_bool] [-undriven] [-clkinv] [-fine] [-full] [-keepdc]\n");
                log("        opt_merge [-share_all]\n");
-               log("        opt_rmdff\n");
+               log("        opt_rmdff [-keepdc]\n");
                log("        opt_clean [-purge]\n");
                log("    while <changed design in opt_rmdff>\n");
                log("\n");
@@ -69,6 +69,7 @@ struct OptPass : public Pass {
                std::string opt_expr_args;
                std::string opt_reduce_args;
                std::string opt_merge_args;
+               std::string opt_rmdff_args;
                bool fast_mode = false;
 
                log_header(design, "Executing OPT pass (performing simple optimizations).\n");
@@ -108,6 +109,7 @@ struct OptPass : public Pass {
                        }
                        if (args[argidx] == "-keepdc") {
                                opt_expr_args += " -keepdc";
+                               opt_rmdff_args += " -keepdc";
                                continue;
                        }
                        if (args[argidx] == "-share_all") {
@@ -128,7 +130,7 @@ struct OptPass : public Pass {
                                Pass::call(design, "opt_expr" + opt_expr_args);
                                Pass::call(design, "opt_merge" + opt_merge_args);
                                design->scratchpad_unset("opt.did_something");
-                               Pass::call(design, "opt_rmdff");
+                               Pass::call(design, "opt_rmdff" + opt_rmdff_args);
                                if (design->scratchpad_get_bool("opt.did_something") == false)
                                        break;
                                Pass::call(design, "opt_clean" + opt_clean_args);
@@ -145,7 +147,7 @@ struct OptPass : public Pass {
                                Pass::call(design, "opt_muxtree");
                                Pass::call(design, "opt_reduce" + opt_reduce_args);
                                Pass::call(design, "opt_merge" + opt_merge_args);
-                               Pass::call(design, "opt_rmdff");
+                               Pass::call(design, "opt_rmdff" + opt_rmdff_args);
                                Pass::call(design, "opt_clean" + opt_clean_args);
                                Pass::call(design, "opt_expr" + opt_expr_args);
                                if (design->scratchpad_get_bool("opt.did_something") == false)
index fa954afaca62ca82d79592b229cc30597f7c2fe0..7e87d1adcffbb72225cecad68278a949e122fa3c 100644 (file)
@@ -29,6 +29,7 @@ PRIVATE_NAMESPACE_BEGIN
 SigMap assign_map, dff_init_map;
 SigSet<RTLIL::Cell*> mux_drivers;
 dict<SigBit, pool<SigBit>> init_attributes;
+bool keepdc;
 
 void remove_init_attr(SigSpec sig)
 {
@@ -115,7 +116,7 @@ bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
        bool has_init = false;
        RTLIL::Const val_init;
        for (auto bit : dff_init_map(sig_q).to_sigbit_vector()) {
-               if (bit.wire == NULL)
+               if (bit.wire == NULL || keepdc)
                        has_init = true;
                val_init.bits.push_back(bit.wire == NULL ? bit.data : RTLIL::State::Sx);
        }
@@ -182,7 +183,7 @@ struct OptRmdffPass : public Pass {
        {
                //   |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
                log("\n");
-               log("    opt_rmdff [selection]\n");
+               log("    opt_rmdff [-keepdc] [selection]\n");
                log("\n");
                log("This pass identifies flip-flops with constant inputs and replaces them with\n");
                log("a constant driver.\n");
@@ -193,7 +194,17 @@ struct OptRmdffPass : public Pass {
                int total_count = 0, total_initdrv = 0;
                log_header(design, "Executing OPT_RMDFF pass (remove dff with constant values).\n");
 
-               extra_args(args, 1, design);
+               keepdc = false;
+
+               size_t argidx;
+               for (argidx = 1; argidx < args.size(); argidx++) {
+                       if (args[argidx] == "-keepdc") {
+                               keepdc = true;
+                               continue;
+                       }
+                       break;
+               }
+               extra_args(args, argidx, design);
 
                for (auto module : design->selected_modules())
                {