diff options
author | Marcelina KoĆcielnicka <mwk@0x04.net> | 2021-03-06 11:05:57 +0100 |
---|---|---|
committer | Marcelina KoĆcielnicka <mwk@0x04.net> | 2021-03-06 17:39:50 +0100 |
commit | d245e2bae59d18eb641aa6b324eef1bbbfa13c38 (patch) | |
tree | 8634caf2113f127d9c966dfd537307dd67210d60 | |
parent | 3d2aef0bde5ee35d283da4b230430ffcb73ec176 (diff) | |
download | yosys-d245e2bae59d18eb641aa6b324eef1bbbfa13c38.tar.gz yosys-d245e2bae59d18eb641aa6b324eef1bbbfa13c38.tar.bz2 yosys-d245e2bae59d18eb641aa6b324eef1bbbfa13c38.zip |
proc_clean: Fix empty case removal conditions.
Fixes #2639.
-rw-r--r-- | passes/proc/proc_clean.cc | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/passes/proc/proc_clean.cc b/passes/proc/proc_clean.cc index 5e78b7316..54d5a81ff 100644 --- a/passes/proc/proc_clean.cc +++ b/passes/proc/proc_clean.cc @@ -76,22 +76,33 @@ void proc_clean_switch(RTLIL::SwitchRule *sw, RTLIL::CaseRule *parent, bool &did } else { - bool all_fully_def = true; for (auto cs : sw->cases) - { if (max_depth != 0) proc_clean_case(cs, did_something, count, max_depth-1); - int size = 0; - for (auto cmp : cs->compare) + + bool is_parallel_case = sw->get_bool_attribute(ID::parallel_case); + bool is_full_case = sw->get_bool_attribute(ID::full_case); + + // Empty case removal. The rules are: + // + // - for full_case: only remove cases if *all* cases are empty + // - for parallel_case but not full_case: remove any empty case + // - for non-parallel and non-full case: remove the final case if it's empty + + if (is_full_case) + { + bool all_empty = true; + for (auto cs : sw->cases) + if (!cs->empty()) + all_empty = false; + if (all_empty) { - size += cmp.size(); - if (!cmp.is_fully_def()) - all_fully_def = false; + for (auto cs : sw->cases) + delete cs; + sw->cases.clear(); } - if (sw->signal.size() != size) - all_fully_def = false; } - if (all_fully_def) + else if (is_parallel_case) { for (auto cs = sw->cases.begin(); cs != sw->cases.end();) { |