Merge pull request #1309 from whitequark/proc_clean-fix-1268
[yosys.git] / passes / proc / proc_rmdead.cc
index af17e8d38f17bf9dc03edb071ca4e58848d48594..4f40be446827d291805f3f64c4d0482ed63f8794 100644 (file)
@@ -28,7 +28,7 @@
 USING_YOSYS_NAMESPACE
 PRIVATE_NAMESPACE_BEGIN
 
-void proc_rmdead(RTLIL::SwitchRule *sw, int &counter)
+void proc_rmdead(RTLIL::SwitchRule *sw, int &counter, int &full_case_counter)
 {
        BitPatternPool pool(sw->signal);
 
@@ -56,16 +56,21 @@ void proc_rmdead(RTLIL::SwitchRule *sw, int &counter)
                }
 
                for (auto switch_it : sw->cases[i]->switches)
-                       proc_rmdead(switch_it, counter);
+                       proc_rmdead(switch_it, counter, full_case_counter);
 
                if (is_default)
                        pool.take_all();
        }
+
+       if (pool.empty() && !sw->get_bool_attribute("\\full_case")) {
+               sw->set_bool_attribute("\\full_case");
+               full_case_counter++;
+       }
 }
 
 struct ProcRmdeadPass : public Pass {
        ProcRmdeadPass() : Pass("proc_rmdead", "eliminate dead trees in decision trees") { }
-       virtual void help()
+       void help() YS_OVERRIDE
        {
                //   |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
                log("\n");
@@ -74,9 +79,9 @@ struct ProcRmdeadPass : public Pass {
                log("This pass identifies unreachable branches in decision trees and removes them.\n");
                log("\n");
        }
-       virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
+       void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
        {
-               log_header("Executing PROC_RMDEAD pass (remove dead branches from decision trees).\n");
+               log_header(design, "Executing PROC_RMDEAD pass (remove dead branches from decision trees).\n");
 
                extra_args(args, 1, design);
 
@@ -87,12 +92,15 @@ struct ProcRmdeadPass : public Pass {
                        for (auto &proc_it : mod->processes) {
                                if (!design->selected(mod, proc_it.second))
                                        continue;
-                               int counter = 0;
+                               int counter = 0, full_case_counter = 0;
                                for (auto switch_it : proc_it.second->root_case.switches)
-                                       proc_rmdead(switch_it, counter);
+                                       proc_rmdead(switch_it, counter, full_case_counter);
                                if (counter > 0)
                                        log("Removed %d dead cases from process %s in module %s.\n", counter,
-                                                       proc_it.first.c_str(), log_id(mod));
+                                                       log_id(proc_it.first), log_id(mod));
+                               if (full_case_counter > 0)
+                                       log("Marked %d switch rules as full_case in process %s in module %s.\n",
+                                                       full_case_counter, log_id(proc_it.first), log_id(mod));
                                total_counter += counter;
                        }
                }